aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-10-02 13:11:42 +0200
committerAlex Auvolat <alex@adnab.me>2023-10-02 13:11:42 +0200
commit4818e8cccc68c88ae64a7a6f65032906f6d818c3 (patch)
treea7491cf8b77d6556f5e128a2697ea4286256b1ed /src
parent46d517b2f75bfff84b49fe3abc57152dcbc55133 (diff)
downloadtricot-4818e8cccc68c88ae64a7a6f65032906f6d818c3.tar.gz
tricot-4818e8cccc68c88ae64a7a6f65032906f6d818c3.zip
cargo upgrades: update opentelemetry dependency to 0.20/prometheus to 0.13
Diffstat (limited to 'src')
-rw-r--r--src/https.rs4
-rw-r--r--src/metrics.rs42
-rw-r--r--src/proxy_config.rs5
3 files changed, 36 insertions, 15 deletions
diff --git a/src/https.rs b/src/https.rs
index f31caef..ed98ae1 100644
--- a/src/https.rs
+++ b/src/https.rs
@@ -41,7 +41,7 @@ pub struct HttpsConfig {
struct HttpsMetrics {
requests_received: metrics::Counter<u64>,
requests_served: metrics::Counter<u64>,
- request_proxy_duration: metrics::ValueRecorder<f64>,
+ request_proxy_duration: metrics::Histogram<f64>,
}
pub async fn serve_https(
@@ -63,7 +63,7 @@ pub async fn serve_https(
.with_description("Total number of requests served over HTTPS")
.init(),
request_proxy_duration: meter
- .f64_value_recorder("https_request_proxy_duration")
+ .f64_histogram("https_request_proxy_duration")
.with_description("Duration between time when request was received, and time when backend returned status code and headers")
.init(),
});
diff --git a/src/metrics.rs b/src/metrics.rs
index ee5c60a..d2e29c7 100644
--- a/src/metrics.rs
+++ b/src/metrics.rs
@@ -11,27 +11,29 @@ use hyper::{
service::{make_service_fn, service_fn},
Body, Method, Request, Response, Server,
};
-use opentelemetry_prometheus::PrometheusExporter;
+use opentelemetry::sdk::metrics;
use prometheus::{Encoder, TextEncoder};
pub struct MetricsServer {
bind_addr: Option<SocketAddr>,
- exporter: PrometheusExporter,
+ registry: prometheus::Registry,
}
impl MetricsServer {
pub fn init(bind_addr: Option<SocketAddr>) -> MetricsServer {
+ let registry = prometheus::Registry::new();
let exporter = opentelemetry_prometheus::exporter()
- .with_default_summary_quantiles(vec![0.25, 0.5, 0.75, 0.9, 0.95, 0.99])
- .with_default_histogram_boundaries(vec![
- 0.001, 0.0015, 0.002, 0.003, 0.005, 0.007, 0.01, 0.015, 0.02, 0.03, 0.05, 0.07,
- 0.1, 0.15, 0.2, 0.3, 0.5, 0.7, 1., 1.5, 2., 3., 5., 7., 10., 15., 20., 30., 40.,
- 50., 60., 70., 100.,
- ])
- .init();
+ .with_registry(registry.clone())
+ .with_aggregation_selector(AggregationSelector)
+ .build()
+ .expect("build prometheus registry");
+ let mp = metrics::MeterProvider::builder()
+ .with_reader(exporter)
+ .build();
+ opentelemetry::global::set_meter_provider(mp);
Self {
bind_addr,
- exporter,
+ registry,
}
}
@@ -70,7 +72,7 @@ impl MetricsServer {
(&Method::GET, "/metrics") => {
let mut buffer = vec![];
let encoder = TextEncoder::new();
- let metric_families = self.exporter.registry().gather();
+ let metric_families = self.registry.gather();
encoder.encode(&metric_families, &mut buffer).unwrap();
Response::builder()
@@ -88,3 +90,21 @@ impl MetricsServer {
Ok(response)
}
}
+
+struct AggregationSelector;
+
+impl metrics::reader::AggregationSelector for AggregationSelector {
+ fn aggregation(&self, kind: metrics::InstrumentKind) -> metrics::Aggregation {
+ match kind {
+ metrics::InstrumentKind::Histogram => metrics::Aggregation::ExplicitBucketHistogram {
+ boundaries: vec![
+ 0.001, 0.0015, 0.002, 0.003, 0.005, 0.007, 0.01, 0.015, 0.02, 0.03, 0.05, 0.07,
+ 0.1, 0.15, 0.2, 0.3, 0.5, 0.7, 1., 1.5, 2., 3., 5., 7., 10., 15., 20., 30.,
+ 40., 50., 60., 70., 100.,
+ ],
+ record_min_max: true,
+ },
+ _ => metrics::reader::DefaultAggregationSelector::new().aggregation(kind),
+ }
+ }
+}
diff --git a/src/proxy_config.rs b/src/proxy_config.rs
index 43d3929..dab4d98 100644
--- a/src/proxy_config.rs
+++ b/src/proxy_config.rs
@@ -334,7 +334,7 @@ pub fn spawn_proxy_config_task(
// ----
struct ProxyConfigMetrics {
- _proxy_config_entries: metrics::ValueObserver<u64>,
+ _proxy_config_entries: metrics::ObservableGauge<u64>,
}
impl ProxyConfigMetrics {
@@ -342,7 +342,8 @@ impl ProxyConfigMetrics {
let meter = opentelemetry::global::meter("tricot");
Self {
_proxy_config_entries: meter
- .u64_value_observer("proxy_config_entries", move |observer| {
+ .u64_observable_gauge("proxy_config_entries")
+ .with_callback(move |observer| {
let mut patterns = HashMap::new();
for ent in rx.borrow().entries.iter() {
let attrs = (