Skip to content

Commit 9d996c5

Browse files
authored
refactor(query): record physical plan level metrics into profiling log (#15092)
* refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): tracking plan metrics * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): support scoped metrics registry * refactor(metrics): keep metric name suffix * refactor(metrics): fix unit test failure
1 parent 79d8329 commit 9d996c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2952
-741
lines changed

Cargo.lock

Lines changed: 4 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/base/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pprof = { version = "0.11.1", features = [
4646
"protobuf-codec",
4747
"protobuf",
4848
] }
49+
prometheus-client = { workspace = true }
50+
prometheus-parse = "0.2.3"
4951
regex = { workspace = true }
5052
replace_with = "0.1.7"
5153
semver = { workspace = true }

src/common/base/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![feature(slice_swap_unchecked)]
2626
#![feature(lint_reasons)]
2727
#![feature(variant_count)]
28+
#![feature(lazy_cell)]
2829

2930
pub mod base;
3031
pub mod containers;

src/common/metrics/src/counter.rs renamed to src/common/base/src/runtime/metrics/counter.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,49 @@ use prometheus_client::encoding::MetricEncoder;
2121
use prometheus_client::metrics::MetricType;
2222
use prometheus_client::metrics::TypedMetric;
2323

24+
use crate::runtime::metrics::registry::DatabendMetric;
25+
use crate::runtime::metrics::registry::ScopedRegistry;
26+
use crate::runtime::metrics::sample::MetricSample;
27+
use crate::runtime::metrics::sample::MetricValue;
28+
2429
#[derive(Debug)]
2530
pub struct Counter {
2631
value: Arc<AtomicU64>,
32+
index: usize,
2733
}
2834

2935
impl Clone for Counter {
3036
fn clone(&self) -> Self {
3137
Self {
38+
index: self.index,
3239
value: self.value.clone(),
3340
}
3441
}
3542
}
3643

37-
impl Default for Counter {
38-
fn default() -> Self {
44+
impl Counter {
45+
pub fn create(index: usize) -> Counter {
3946
Counter {
47+
index,
4048
value: Arc::new(AtomicU64::new(0)),
4149
}
4250
}
43-
}
4451

45-
impl Counter {
4652
/// Increase the [`Counter`] by 1, returning the previous value.
4753
pub fn inc(&self) -> u64 {
54+
ScopedRegistry::op(self.index, |m: &Self| {
55+
m.value.fetch_add(1, Ordering::Relaxed);
56+
});
57+
4858
self.value.fetch_add(1, Ordering::Relaxed)
4959
}
5060

5161
/// Increase the [`Counter`] by `v`, returning the previous value.
5262
pub fn inc_by(&self, v: u64) -> u64 {
63+
ScopedRegistry::op(self.index, |m: &Self| {
64+
m.value.fetch_add(v, Ordering::Relaxed);
65+
});
66+
5367
self.value.fetch_add(v, Ordering::Relaxed)
5468
}
5569

@@ -77,3 +91,17 @@ impl EncodeMetric for Counter {
7791
Self::TYPE
7892
}
7993
}
94+
95+
impl DatabendMetric for Counter {
96+
fn reset_metric(&self) {
97+
self.value.store(0, Ordering::Release);
98+
}
99+
100+
fn sample(&self, name: &str, samples: &mut Vec<MetricSample>) {
101+
samples.push(MetricSample {
102+
name: format!("{}_total", name),
103+
labels: Default::default(),
104+
value: MetricValue::Counter(self.get() as f64),
105+
});
106+
}
107+
}

0 commit comments

Comments
 (0)