Skip to content

Commit

Permalink
Make field separator and value separator configurable. (#112)
Browse files Browse the repository at this point in the history
* Make field and value separator configurable.

Signed-off-by: Mandar U Jog <[email protected]>
  • Loading branch information
mandarjog authored and jplevyak committed Aug 6, 2019
1 parent 3504b4e commit 01b4016
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions api/wasm/cpp/proxy_wasm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -998,14 +998,19 @@ struct MetricTag {
struct MetricBase {
MetricBase(MetricType t, const std::string& n) : type(t), name(n) {}
MetricBase(MetricType t, const std::string& n, std::vector<MetricTag> ts)
: type(t), name(n), tags(ts.begin(), ts.end()) {}
: type(t), name(n), tags(ts.begin(), ts.end()){}
MetricBase(MetricType t, const std::string& n, std::vector<MetricTag> ts, std::string fs, std::string vs)
: type(t), name(n), tags(ts.begin(), ts.end()), field_separator(fs), value_separator(vs) {}

MetricType type;
std::string name;
std::string prefix;
std::vector<MetricTag> tags;
std::unordered_map<std::string, uint32_t> metric_ids;

std::string field_separator = "."; // used to separate two fields.
std::string value_separator = "."; // used to separate a field from its value.

std::string prefixWithFields(const std::vector<std::string>& fields);
uint32_t resolveFullName(const std::string& n);
uint32_t resolveWithFields(const std::vector<std::string>& fields);
Expand All @@ -1016,6 +1021,7 @@ struct MetricBase {
struct Metric : public MetricBase {
Metric(MetricType t, const std::string& n) : MetricBase(t, n) {}
Metric(MetricType t, const std::string& n, std::vector<MetricTag> ts) : MetricBase(t, n, ts) {}
Metric(MetricType t, const std::string& n, std::vector<MetricTag> ts, std::string field_separator, std::string value_separator) : MetricBase(t, n, ts, field_separator, value_separator) {}

template <typename... Fields> void increment(int64_t offset, Fields... tags);
template <typename... Fields> void record(uint64_t value, Fields... tags);
Expand All @@ -1037,9 +1043,9 @@ inline std::string MetricBase::prefixWithFields(const std::vector<std::string>&
n.append(prefix);
for (size_t i = 0; i < fields.size(); i++) {
n.append(tags[i].name);
n.append(".");
n.append(value_separator);
n.append(fields[i]);
n.append(".");
n.append(field_separator);
}
return n;
}
Expand Down

0 comments on commit 01b4016

Please sign in to comment.