]> git.sesse.net Git - nageru/blobdiff - shared/metrics.cpp
Fix a Clang 19 warning.
[nageru] / shared / metrics.cpp
index b2d0bbce5ca0671a3d810bf19c74cd7dda29f1ce..91b03e83483e1335d85d747dca730d607ff10438 100644 (file)
@@ -99,7 +99,24 @@ void Metrics::remove(const string &name, const vector<pair<string, string>> &lab
 
        // 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)->first.name == name))) {
+             (it != metrics.end() && next(it) != metrics.end() && next(it)->first.name == name))) {
+               types.erase(name);
+       }
+
+       metrics.erase(it);
+}
+
+void Metrics::remove_if_exists(const string &name, const vector<pair<string, string>> &labels)
+{
+       lock_guard<mutex> 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);
        }