feat: add DB and table name to job metrics

pull/24376/head
Marco Neumann 2021-09-08 15:38:55 +02:00
parent a6416d145f
commit 40d3f53aee
2 changed files with 29 additions and 61 deletions

View File

@ -164,7 +164,7 @@ impl JobRegistryMetrics {
let metadata = job.metadata();
let status = job.get_status();
metric::Attributes::from(&[
let mut attributes = metric::Attributes::from(&[
("description", metadata.description()),
(
"status",
@ -173,7 +173,15 @@ impl JobRegistryMetrics {
.map(|result| result.name())
.unwrap_or_else(|| status.name()),
),
])
]);
if let Some(db_name) = metadata.db_name() {
attributes.insert("db_name", db_name.to_string());
}
if let Some(table) = metadata.table_name() {
attributes.insert("table", table.to_string());
}
attributes
}
fn process_completed_job(&mut self, job: &TaskTracker<Job>) {

View File

@ -2439,7 +2439,7 @@ mod tests {
let wait_nanos = 1000;
let job = application
.job_registry()
.spawn_dummy_job(vec![wait_nanos], None);
.spawn_dummy_job(vec![wait_nanos], Some(Arc::from("some_db")));
job.join().await;
@ -2453,77 +2453,37 @@ mod tests {
server.join().await.unwrap();
// ========== influxdb_iox_job_count ==========
let observations: Vec<_> = reporter
.observations()
.iter()
.filter(|observation| observation.metric_name == "influxdb_iox_job_count")
.collect();
assert_eq!(observations.len(), 1);
let gauge = observations[0];
assert_eq!(gauge.kind, metric::MetricKind::U64Gauge);
let observations: Vec<_> = gauge
.observations
.iter()
.filter(|(attributes, _)| {
attributes
.iter()
.any(|(k, v)| (k == &"status") && (v == "Success"))
})
.collect();
assert_eq!(observations.len(), 1);
let (attributes, observation) = &observations[0];
assert_eq!(
attributes,
&metric::Attributes::from(&[
let metric = reporter.metric("influxdb_iox_job_count").unwrap();
assert_eq!(metric.kind, metric::MetricKind::U64Gauge);
let observation = metric
.observation(&[
("description", "Dummy Job, for testing"),
("status", "Success"),
("db_name", "some_db"),
])
);
.unwrap();
assert_eq!(observation, &metric::Observation::U64Gauge(1));
// ========== influxdb_iox_job_completed_cpu ==========
let observations: Vec<_> = reporter
.observations()
.iter()
.filter(|observation| observation.metric_name == "influxdb_iox_job_completed_cpu")
.collect();
assert_eq!(observations.len(), 1);
let histogram = observations[0];
assert_eq!(histogram.kind, metric::MetricKind::DurationHistogram);
assert_eq!(histogram.observations.len(), 1);
let (attributes, _) = &histogram.observations[0];
assert_eq!(
attributes,
&metric::Attributes::from(&[
let metric = reporter.metric("influxdb_iox_job_completed_cpu").unwrap();
assert_eq!(metric.kind, metric::MetricKind::DurationHistogram);
metric
.observation(&[
("description", "Dummy Job, for testing"),
("status", "Success"),
("db_name", "some_db"),
])
);
.unwrap();
// ========== influxdb_iox_job_completed_wall ==========
let observations: Vec<_> = reporter
.observations()
.iter()
.filter(|observation| observation.metric_name == "influxdb_iox_job_completed_wall")
.collect();
assert_eq!(observations.len(), 1);
let histogram = observations[0];
assert_eq!(histogram.kind, metric::MetricKind::DurationHistogram);
assert_eq!(histogram.observations.len(), 1);
let (attributes, _) = &histogram.observations[0];
assert_eq!(
attributes,
&metric::Attributes::from(&[
let metric = reporter.metric("influxdb_iox_job_completed_wall").unwrap();
assert_eq!(metric.kind, metric::MetricKind::DurationHistogram);
metric
.observation(&[
("description", "Dummy Job, for testing"),
("status", "Success"),
("db_name", "some_db"),
])
);
.unwrap();
}
}