Skip to content

Commit

Permalink
MB-43772: [BP] Only collect exposer_ metrics for the low cardinality
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
veselink1 committed Jan 22, 2024
1 parent 3071fdc commit c8d9921
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
9 changes: 9 additions & 0 deletions include/statistics/prometheus.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ enum class IncludeTimestamps {
Yes,
};

/**
* Flag whether to include meta metrics generated by prometheus-cpp for every
* endpoint.
*
* Those metrics start with "exposer_" and contain information about metrics
* scape latencies, among others.
*/
enum class IncludeMetaMetrics { No, Yes };

using AuthCallback =
std::function<bool(const std::string&, const std::string&)>;

Expand Down
24 changes: 19 additions & 5 deletions statistics/prometheus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,19 @@ MetricServer::MetricServer(in_port_t port,

// used to store the newly created KVCollectable into the array
auto arrayItr = endpoints.begin();
for (auto [cardinality, timestamps] : {
std::make_pair(Cardinality::Low, IncludeTimestamps::No),
std::make_pair(Cardinality::Low, IncludeTimestamps::Yes),
std::make_pair(Cardinality::High, IncludeTimestamps::No),
std::make_pair(Cardinality::High, IncludeTimestamps::Yes),
for (auto [cardinality, timestamps, metaMetrics] : {
std::make_tuple(Cardinality::Low,
IncludeTimestamps::No,
IncludeMetaMetrics::Yes),
std::make_tuple(Cardinality::Low,
IncludeTimestamps::Yes,
IncludeMetaMetrics::Yes),
std::make_tuple(Cardinality::High,
IncludeTimestamps::No,
IncludeMetaMetrics::No),
std::make_tuple(Cardinality::High,
IncludeTimestamps::Yes,
IncludeMetaMetrics::No),
}) {
auto ptr = std::make_shared<KVCollectable>(
cardinality, timestamps, getStatsCB);
Expand All @@ -195,6 +203,12 @@ MetricServer::MetricServer(in_port_t port,

exposer->RegisterAuth(authCB, authRealm, path);
exposer->RegisterCollectable(ptr, path);

if (metaMetrics == IncludeMetaMetrics::No) {
exposer->RemoveCollectable(exposer->GetMetaCollectable(path),
path);
}

*arrayItr = std::move(ptr);
++arrayItr;
}
Expand Down

0 comments on commit c8d9921

Please sign in to comment.