Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RollingSummary to prevent summary saturation #306

Merged
merged 7 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 10 additions & 37 deletions metrics-exporter-prometheus/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use metrics_util::{
use crate::common::Matcher;
use crate::distribution::DistributionBuilder;
use crate::recorder::{Inner, PrometheusRecorder};
use crate::registry::AtomicStorage;
use crate::{common::BuildError, PrometheusHandle};

#[cfg(any(feature = "http-listener", feature = "push-gateway"))]
Expand Down Expand Up @@ -508,7 +509,7 @@ impl PrometheusBuilder {

pub(crate) fn build_with_clock(self, clock: Clock) -> PrometheusRecorder {
let inner = Inner {
registry: Registry::new(GenerationalStorage::atomic()),
registry: Registry::new(GenerationalStorage::new(AtomicStorage)),
recency: Recency::new(clock, self.recency_mask, self.idle_timeout),
distributions: RwLock::new(HashMap::new()),
distribution_builder: DistributionBuilder::new(
Expand Down Expand Up @@ -543,7 +544,8 @@ mod tests {

#[test]
fn test_render() {
let recorder = PrometheusBuilder::new().build_recorder();
let recorder =
PrometheusBuilder::new().set_quantiles(&[0.0, 1.0]).unwrap().build_recorder();

let key = Key::from_name("basic_counter");
let counter1 = recorder.register_counter(&key);
Expand Down Expand Up @@ -575,11 +577,6 @@ mod tests {
let histogram_data = concat!(
"# TYPE basic_histogram summary\n",
"basic_histogram{quantile=\"0\"} 12\n",
"basic_histogram{quantile=\"0.5\"} 12\n",
"basic_histogram{quantile=\"0.9\"} 12\n",
"basic_histogram{quantile=\"0.95\"} 12\n",
"basic_histogram{quantile=\"0.99\"} 12\n",
"basic_histogram{quantile=\"0.999\"} 12\n",
"basic_histogram{quantile=\"1\"} 12\n",
"basic_histogram_sum 12\n",
"basic_histogram_count 1\n",
Expand Down Expand Up @@ -685,6 +682,8 @@ mod tests {

let recorder = PrometheusBuilder::new()
.idle_timeout(MetricKindMask::ALL, Some(Duration::from_secs(10)))
.set_quantiles(&[0.0, 1.0])
.unwrap()
.build_with_clock(clock);

let key = Key::from_name("basic_counter");
Expand All @@ -708,11 +707,6 @@ mod tests {
"basic_gauge -3.14\n\n",
"# TYPE basic_histogram summary\n",
"basic_histogram{quantile=\"0\"} 1\n",
"basic_histogram{quantile=\"0.5\"} 1\n",
"basic_histogram{quantile=\"0.9\"} 1\n",
"basic_histogram{quantile=\"0.95\"} 1\n",
"basic_histogram{quantile=\"0.99\"} 1\n",
"basic_histogram{quantile=\"0.999\"} 1\n",
"basic_histogram{quantile=\"1\"} 1\n",
"basic_histogram_sum 1\n",
"basic_histogram_count 1\n\n",
Expand All @@ -738,6 +732,8 @@ mod tests {
MetricKindMask::COUNTER | MetricKindMask::HISTOGRAM,
Some(Duration::from_secs(10)),
)
.set_quantiles(&[0.0, 1.0])
.unwrap()
.build_with_clock(clock);

let key = Key::from_name("basic_counter");
Expand All @@ -761,11 +757,6 @@ mod tests {
"basic_gauge -3.14\n\n",
"# TYPE basic_histogram summary\n",
"basic_histogram{quantile=\"0\"} 1\n",
"basic_histogram{quantile=\"0.5\"} 1\n",
"basic_histogram{quantile=\"0.9\"} 1\n",
"basic_histogram{quantile=\"0.95\"} 1\n",
"basic_histogram{quantile=\"0.99\"} 1\n",
"basic_histogram{quantile=\"0.999\"} 1\n",
"basic_histogram{quantile=\"1\"} 1\n",
"basic_histogram_sum 1\n",
"basic_histogram_count 1\n\n",
Expand All @@ -790,6 +781,8 @@ mod tests {

let recorder = PrometheusBuilder::new()
.idle_timeout(MetricKindMask::ALL, Some(Duration::from_secs(10)))
.set_quantiles(&[0.0, 1.0])
.unwrap()
.build_with_clock(clock);

let key = Key::from_name("basic_counter");
Expand All @@ -813,11 +806,6 @@ mod tests {
"basic_gauge -3.14\n\n",
"# TYPE basic_histogram summary\n",
"basic_histogram{quantile=\"0\"} 1\n",
"basic_histogram{quantile=\"0.5\"} 1\n",
"basic_histogram{quantile=\"0.9\"} 1\n",
"basic_histogram{quantile=\"0.95\"} 1\n",
"basic_histogram{quantile=\"0.99\"} 1\n",
"basic_histogram{quantile=\"0.999\"} 1\n",
"basic_histogram{quantile=\"1\"} 1\n",
"basic_histogram_sum 1\n",
"basic_histogram_count 1\n\n",
Expand All @@ -840,20 +828,10 @@ mod tests {
"basic_gauge -3.14\n\n",
"# TYPE basic_histogram summary\n",
"basic_histogram{quantile=\"0\"} 1\n",
"basic_histogram{quantile=\"0.5\"} 1\n",
"basic_histogram{quantile=\"0.9\"} 1\n",
"basic_histogram{quantile=\"0.95\"} 1\n",
"basic_histogram{quantile=\"0.99\"} 1\n",
"basic_histogram{quantile=\"0.999\"} 1\n",
"basic_histogram{quantile=\"1\"} 1\n",
"basic_histogram_sum 1\n",
"basic_histogram_count 1\n",
"basic_histogram{type=\"special\",quantile=\"0\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.5\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.9\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.95\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.99\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.999\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"1\"} 2\n",
"basic_histogram_sum{type=\"special\"} 2\n",
"basic_histogram_count{type=\"special\"} 1\n\n",
Expand All @@ -864,11 +842,6 @@ mod tests {
let expected_after = concat!(
"# TYPE basic_histogram summary\n",
"basic_histogram{type=\"special\",quantile=\"0\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.5\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.9\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.95\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.99\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"0.999\"} 2\n",
"basic_histogram{type=\"special\",quantile=\"1\"} 2\n",
"basic_histogram_sum{type=\"special\"} 2\n",
"basic_histogram_count{type=\"special\"} 1\n\n",
Expand Down
Loading