Skip to content

Commit c8d9921

Browse files
committed
MB-43772: [BP] Only collect exposer_ metrics for the low cardinality
Backport to 7.2.5. This is because ns_server will concat the outputs from both the low cardinality and high cardinality endpoints. Collecting exposer_ metrics for both results in duplicate metrics after the concat, which is not allowed by the Prometheus exposition format. Change-Id: Ifcf0e51e8dbf08bf7a8f4189b8a5e6c0c9ec7d2e Reviewed-on: https://review.couchbase.org/c/kv_engine/+/203920 Reviewed-by: Trond Norbye <[email protected]> Well-Formed: Restriction Checker Tested-by: Vesko Karaganev <[email protected]>
1 parent 3071fdc commit c8d9921

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

include/statistics/prometheus.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ enum class IncludeTimestamps {
4444
Yes,
4545
};
4646

47+
/**
48+
* Flag whether to include meta metrics generated by prometheus-cpp for every
49+
* endpoint.
50+
*
51+
* Those metrics start with "exposer_" and contain information about metrics
52+
* scape latencies, among others.
53+
*/
54+
enum class IncludeMetaMetrics { No, Yes };
55+
4756
using AuthCallback =
4857
std::function<bool(const std::string&, const std::string&)>;
4958

statistics/prometheus.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,19 @@ MetricServer::MetricServer(in_port_t port,
176176

177177
// used to store the newly created KVCollectable into the array
178178
auto arrayItr = endpoints.begin();
179-
for (auto [cardinality, timestamps] : {
180-
std::make_pair(Cardinality::Low, IncludeTimestamps::No),
181-
std::make_pair(Cardinality::Low, IncludeTimestamps::Yes),
182-
std::make_pair(Cardinality::High, IncludeTimestamps::No),
183-
std::make_pair(Cardinality::High, IncludeTimestamps::Yes),
179+
for (auto [cardinality, timestamps, metaMetrics] : {
180+
std::make_tuple(Cardinality::Low,
181+
IncludeTimestamps::No,
182+
IncludeMetaMetrics::Yes),
183+
std::make_tuple(Cardinality::Low,
184+
IncludeTimestamps::Yes,
185+
IncludeMetaMetrics::Yes),
186+
std::make_tuple(Cardinality::High,
187+
IncludeTimestamps::No,
188+
IncludeMetaMetrics::No),
189+
std::make_tuple(Cardinality::High,
190+
IncludeTimestamps::Yes,
191+
IncludeMetaMetrics::No),
184192
}) {
185193
auto ptr = std::make_shared<KVCollectable>(
186194
cardinality, timestamps, getStatsCB);
@@ -195,6 +203,12 @@ MetricServer::MetricServer(in_port_t port,
195203

196204
exposer->RegisterAuth(authCB, authRealm, path);
197205
exposer->RegisterCollectable(ptr, path);
206+
207+
if (metaMetrics == IncludeMetaMetrics::No) {
208+
exposer->RemoveCollectable(exposer->GetMetaCollectable(path),
209+
path);
210+
}
211+
198212
*arrayItr = std::move(ptr);
199213
++arrayItr;
200214
}

0 commit comments

Comments
 (0)