diff --git a/server/src/lib.rs b/server/src/lib.rs index 5e18df8738..14bdbfa716 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -419,15 +419,15 @@ impl ServerMetrics { #[derive(Debug)] pub struct Server { connection_manager: Arc, - pub store: Arc, + store: Arc, exec: Arc, jobs: Arc, - pub metrics: Arc, + metrics: Arc, /// The metrics registry associated with the server. This is needed not for /// recording telemetry, but because the server hosts the /metric endpoint /// and populates the endpoint with this data. - pub registry: Arc, + registry: Arc, /// The state machine for server startup stage: Arc>, @@ -551,6 +551,16 @@ where } } + /// Returns the metrics registry associated with this server + pub fn metrics_registry(&self) -> &Arc { + &self.registry + } + + /// Return the metrics associated with this server + pub fn metrics(&self) -> &Arc { + &self.metrics + } + /// Check if server is loaded. Databases are loaded and server is ready to read/write. pub fn initialized(&self) -> bool { matches!(&*self.stage.read(), ServerStage::Initialized { .. }) diff --git a/src/influxdb_ioxd/http.rs b/src/influxdb_ioxd/http.rs index 1e08830ef3..adb47016f9 100644 --- a/src/influxdb_ioxd/http.rs +++ b/src/influxdb_ioxd/http.rs @@ -486,7 +486,7 @@ where let server = Arc::clone(&server); // TODO(edd): figure out best way of catching all errors in this observation. - let obs = server.metrics.http_requests.observation(); // instrument request + let obs = server.metrics().http_requests.observation(); // instrument request // TODO - metrics. Implement a macro/something that will catch all the // early returns. @@ -538,16 +538,16 @@ where ]; server - .metrics + .metrics() .ingest_lines_total .add_with_labels(num_lines as u64, labels); server - .metrics + .metrics() .ingest_fields_total .add_with_labels(num_fields as u64, labels); - server.metrics.ingest_points_bytes_total.add_with_labels( + server.metrics().ingest_points_bytes_total.add_with_labels( body.len() as u64, &[ metrics::KeyValue::new("status", "error"), @@ -575,18 +575,18 @@ where ]; server - .metrics + .metrics() .ingest_lines_total .add_with_labels(num_lines as u64, labels); server - .metrics + .metrics() .ingest_fields_total .add_with_labels(num_fields as u64, labels); // line protocol bytes successfully written server - .metrics + .metrics() .ingest_points_bytes_total .add_with_labels(body.len() as u64, labels); @@ -617,7 +617,7 @@ async fn query( let server = Arc::clone(&req.data::>().expect("server state").app_server); // TODO(edd): figure out best way of catching all errors in this observation. - let obs = server.metrics.http_requests.observation(); // instrument request + let obs = server.metrics().http_requests.observation(); // instrument request let uri_query = req.uri().query().context(ExpectedQueryString {})?; @@ -683,7 +683,7 @@ async fn health( let server = Arc::clone(&req.data::>().expect("server state").app_server); let path = req.uri().path().to_string(); server - .metrics + .metrics() .http_requests .observation() .ok_with_labels(&[metrics::KeyValue::new("path", path)]); @@ -699,11 +699,13 @@ async fn handle_metrics( let server = Arc::clone(&req.data::>().expect("server state").app_server); let path = req.uri().path().to_string(); server - .metrics + .metrics() .http_requests .observation() .ok_with_labels(&[metrics::KeyValue::new("path", path)]); - Ok(Response::new(Body::from(server.registry.metrics_as_text()))) + Ok(Response::new(Body::from( + server.metrics_registry().metrics_as_text(), + ))) } #[derive(Deserialize, Debug)] @@ -722,7 +724,7 @@ async fn list_partitions( let server = Arc::clone(&req.data::>().expect("server state").app_server); // TODO - catch error conditions - let obs = server.metrics.http_requests.observation(); + let obs = server.metrics().http_requests.observation(); let query = req.uri().query().context(ExpectedQueryString {})?; let info: DatabaseInfo = serde_urlencoded::from_str(query).context(InvalidQueryString { diff --git a/src/influxdb_ioxd/rpc.rs b/src/influxdb_ioxd/rpc.rs index 4ca3386989..3b1f009d46 100644 --- a/src/influxdb_ioxd/rpc.rs +++ b/src/influxdb_ioxd/rpc.rs @@ -104,7 +104,7 @@ where testing::make_server(), storage::make_server( Arc::clone(&server), - Arc::clone(&server.registry), + Arc::clone(&server.metrics_registry()), serving_gate.clone(), ), flight::make_server(Arc::clone(&server), serving_gate.clone()),