X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fmetrics.cpp;h=91b03e83483e1335d85d747dca730d607ff10438;hb=5a95cccfdacb0da1091ad71a1777a3045d7497e4;hp=248da38a277992289e9ae703bd1442f16ce077e5;hpb=7074d937649879a6f7ae1a812a207643ca63945c;p=nageru diff --git a/shared/metrics.cpp b/shared/metrics.cpp index 248da38..91b03e8 100644 --- a/shared/metrics.cpp +++ b/shared/metrics.cpp @@ -106,6 +106,23 @@ void Metrics::remove(const string &name, const vector> &lab metrics.erase(it); } +void Metrics::remove_if_exists(const string &name, const vector> &labels) +{ + lock_guard lock(mu); + auto it = metrics.find(MetricKey(name, labels)); + if (it == metrics.end()) { + return; + } + + // If this is the last metric with this name, remove the type as well. + if (!((it != metrics.begin() && prev(it)->first.name == name) || + (it != metrics.end() && next(it) != metrics.end() && next(it)->first.name == name))) { + types.erase(name); + } + + metrics.erase(it); +} + string Metrics::serialize() const { stringstream ss;