diff options
author | Tor Brede Vekterli <vekterli@vespa.ai> | 2024-03-21 11:46:14 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@vespa.ai> | 2024-03-21 12:21:26 +0000 |
commit | 1562ae1726453a0789aabb4baad2754020579b8d (patch) | |
tree | d702db3a02c9b035d4a14ee94b295f27859d6743 /storage | |
parent | 723d6cacbdce4c45e01c92cb3e2eeb71f7b513f2 (diff) |
Wire Prometheus metric export to state V1 APIs
Extends metric producer classes with the requested exposition format.
As a consequence, the State API server has been changed to allow
emitting other content types than just `application/json`.
Add custom Prometheus rendering for Slobrok, as it does its own
domain-specific metric tracking. However, since it has non-destructive
sampling properties, we can actually use proper `counter` types.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/src/vespa/storage/storageserver/statereporter.cpp | 31 | ||||
-rw-r--r-- | storage/src/vespa/storage/storageserver/statereporter.h | 4 |
2 files changed, 24 insertions, 11 deletions
diff --git a/storage/src/vespa/storage/storageserver/statereporter.cpp b/storage/src/vespa/storage/storageserver/statereporter.cpp index c0d2d4dcc59..93b60cad71d 100644 --- a/storage/src/vespa/storage/storageserver/statereporter.cpp +++ b/storage/src/vespa/storage/storageserver/statereporter.cpp @@ -4,6 +4,7 @@ #include <vespa/storageframework/generic/clock/clock.h> #include <vespa/metrics/jsonwriter.h> #include <vespa/metrics/metricmanager.h> +#include <vespa/metrics/prometheus_writer.h> #include <vespa/storage/common/nodestateupdater.h> #include <vespa/vdslib/state/nodestate.h> #include <vespa/vespalib/net/connection_auth_context.h> @@ -74,7 +75,7 @@ StateReporter::reportStatus(std::ostream& out, } vespalib::string -StateReporter::getMetrics(const vespalib::string &consumer) +StateReporter::getMetrics(const vespalib::string &consumer, ExpositionFormat format) { metrics::MetricLockGuard guard(_manager.getMetricLock()); auto periods = _manager.getSnapshotPeriods(guard); @@ -92,18 +93,30 @@ StateReporter::getMetrics(const vespalib::string &consumer) snapshot.reset(); _manager.getMetricSnapshot(guard, interval).addToSnapshot(snapshot, _component.getClock().getSystemTime()); - vespalib::asciistream json; - vespalib::JsonStream stream(json); - metrics::JsonWriter metricJsonWriter(stream); - _manager.visit(guard, snapshot, metricJsonWriter, consumer); - stream.finalize(); - return json.str(); + vespalib::asciistream out; + switch (format) { + case ExpositionFormat::JSON: + { + vespalib::JsonStream stream(out); + metrics::JsonWriter metricJsonWriter(stream); + _manager.visit(guard, snapshot, metricJsonWriter, consumer); + stream.finalize(); + break; + } + case ExpositionFormat::Prometheus: + { + metrics::PrometheusWriter writer(out); + _manager.visit(guard, snapshot, writer, consumer); + break; + } + } + return out.str(); } vespalib::string -StateReporter::getTotalMetrics(const vespalib::string &consumer) +StateReporter::getTotalMetrics(const vespalib::string &consumer, ExpositionFormat format) { - return _metricsAdapter.getTotalMetrics(consumer); + return _metricsAdapter.getTotalMetrics(consumer, format); } vespalib::HealthProducer::Health diff --git a/storage/src/vespa/storage/storageserver/statereporter.h b/storage/src/vespa/storage/storageserver/statereporter.h index 9601d0fc34f..c6fb570ae04 100644 --- a/storage/src/vespa/storage/storageserver/statereporter.h +++ b/storage/src/vespa/storage/storageserver/statereporter.h @@ -57,8 +57,8 @@ private: ApplicationGenerationFetcher& _generationFetcher; std::string _name; - vespalib::string getMetrics(const vespalib::string &consumer) override; - vespalib::string getTotalMetrics(const vespalib::string &consumer) override; + vespalib::string getMetrics(const vespalib::string &consumer, ExpositionFormat format) override; + vespalib::string getTotalMetrics(const vespalib::string &consumer, ExpositionFormat format) override; Health getHealth() const override; void getComponentConfig(Consumer &consumer) override; }; |