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

feat(telemetry): add configurable histogram buckets for metrics #3098

Merged
merged 4 commits into from
May 30, 2023
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
21 changes: 21 additions & 0 deletions .changesets/feat_swan_cub_foot_audience.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Configurable histogram buckets for metrics ([Issue #2333](https://github.com/apollographql/router/issues/2333))

You can customize the buckets for all generated histograms:

```yaml title="router.yaml"
telemetry:
metrics:
common:
buckets:
- 0.05
- 0.10
- 0.25
- 0.50
- 1.00
- 2.50
- 5.00
- 10.00
- 20.00
```

By [@bnjjj](https://github.com/bnjjj) in https://github.com/apollographql/router/pull/3098
Original file line number Diff line number Diff line change
Expand Up @@ -3711,6 +3711,28 @@ expression: "&schema"
"additionalProperties": false,
"nullable": true
},
"buckets": {
"description": "Custom buckets for histograms",
"default": [
0.001,
0.005,
0.015,
0.05,
0.1,
0.2,
0.3,
0.4,
0.5,
1.0,
5.0,
10.0
],
"type": "array",
"items": {
"type": "number",
"format": "double"
}
},
"resources": {
"description": "Resources",
"default": {},
Expand All @@ -3721,11 +3743,13 @@ expression: "&schema"
},
"service_name": {
"description": "Set a service.name resource in your metrics",
"default": null,
"type": "string",
"nullable": true
},
"service_namespace": {
"description": "Set a service.namespace attribute in your metrics",
"default": null,
"type": "string",
"nullable": true
}
Expand Down
12 changes: 10 additions & 2 deletions apollo-router/src/plugins/telemetry/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,25 @@ pub(crate) struct Metrics {
}

#[derive(Clone, Default, Debug, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
#[serde(deny_unknown_fields, rename_all = "snake_case", default)]
pub(crate) struct MetricsCommon {
/// Configuration to add custom labels/attributes to metrics
pub(crate) attributes: Option<MetricsAttributesConf>,
/// Set a service.name resource in your metrics
pub(crate) service_name: Option<String>,
/// Set a service.namespace attribute in your metrics
pub(crate) service_namespace: Option<String>,
#[serde(default)]
/// Resources
pub(crate) resources: HashMap<String, String>,
/// Custom buckets for histograms
#[serde(default = "default_buckets")]
pub(crate) buckets: Vec<f64>,
}

fn default_buckets() -> Vec<f64> {
vec![
0.001, 0.005, 0.015, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1.0, 5.0, 10.0,
]
}

/// Tracing configuration
Expand Down
4 changes: 1 addition & 3 deletions apollo-router/src/plugins/telemetry/metrics/otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ impl MetricsConfigurator for super::super::otlp::Config {
Some(exporter) => {
let exporter = opentelemetry_otlp::new_pipeline()
.metrics(
selectors::simple::histogram([
0.001, 0.005, 0.015, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1.0, 5.0, 10.0,
]),
selectors::simple::histogram(metrics_config.buckets.clone()),
aggregation::stateless_temporality_selector(),
opentelemetry::runtime::Tokio,
)
Expand Down
4 changes: 1 addition & 3 deletions apollo-router/src/plugins/telemetry/metrics/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ impl MetricsConfigurator for Config {
if self.enabled {
let mut controller = controllers::basic(
processors::factory(
selectors::simple::histogram([
0.001, 0.005, 0.015, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1.0, 5.0, 10.0,
]),
selectors::simple::histogram(metrics_config.buckets.clone()),
aggregation::stateless_temporality_selector(),
)
.with_memory(true),
Expand Down
Loading