-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathutility.h
More file actions
78 lines (64 loc) · 2.67 KB
/
utility.h
File metadata and controls
78 lines (64 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include <string>
#include "envoy/stats/store.h"
#include "nighthawk/common/exception.h"
#include "external/envoy/envoy/network/dns.h"
#include "api/client/options.pb.h"
#include "absl/strings/string_view.h"
#include "re2/re2.h"
#include "tclap/CmdLine.h"
namespace Nighthawk {
using StoreCounterFilter = std::function<bool(absl::string_view, const uint64_t)>;
class Utility {
public:
/**
* Gets a map of tracked counter values, keyed by name.
* @param filter function that returns true iff a counter should be included in the map,
* based on the named and value it gets passed. The default filter returns all counters.
* @return std::map<std::string, uint64_t> containing zero or more entries.
*/
std::map<std::string, uint64_t> mapCountersFromStore(
const Envoy::Stats::Store& store,
const StoreCounterFilter& filter = [](absl::string_view, const uint64_t) {
return true;
}) const;
/**
* Finds the position of the port separator in the host:port fragment.
*
* @param hostname valid "host[:port]" string.
* @return size_t the position of the port separator, or absl::string_view::npos if none was
* found.
*/
static size_t findPortSeparator(absl::string_view hostname);
/**
* @param family Address family as a string. Allowed values are "v6", "v4", and "auto" (case
* insensitive). Any other values will throw a NighthawkException.
* @return Envoy::Network::DnsLookupFamily the equivalent DnsLookupFamily value
*/
static Envoy::Network::DnsLookupFamily
translateFamilyOptionString(nighthawk::client::AddressFamily::AddressFamilyOptions value);
/**
* Executes TCLAP command line parsing
* @param cmd TCLAP command line specification.
* @param argc forwarded argc argument of the main entry point.
* @param argv forwarded argv argument of the main entry point.
*/
static void parseCommand(TCLAP::CmdLine& cmd, const int argc, const char* const* argv);
/**
* @param host_port host:port as a string, where host can be IPv4, [IPv6], or a DNS
* name.
* @param host string* to receive the host if the parse succeeds
* @param port int* to receive the port if the parse succeeds
* @return bool true if the input could be parsed as host:port
*/
static bool parseHostPort(const std::string& host_port, std::string* host, int* port);
// Obtains an available TCP or UDP port. Throws an exception if one cannot be
// allocated.
/**
* @param udp boolean true if a UDP port is requested, otherwise get a TCP port
* @return port number
*/
static uint16_t
GetAvailablePort(bool udp, nighthawk::client::AddressFamily::AddressFamilyOptions address_family);
};
} // namespace Nighthawk