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 support of instruments in configuration for telemetry #4771

Merged
merged 30 commits into from Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a049747
wip
bnjjj Feb 9, 2024
6913b16
standard subgraph instruments
bnjjj Feb 12, 2024
224352b
wip
bnjjj Feb 22, 2024
40e60b0
add support of histogram
bnjjj Feb 22, 2024
4b0df6a
add support of supergraph and subgraph
bnjjj Feb 23, 2024
d896e29
add support of condition
bnjjj Feb 23, 2024
d7ae2f2
add exist condition
bnjjj Mar 3, 2024
215cd19
add test for instruments
bnjjj Mar 8, 2024
61e0bb1
Merge branch 'dev' of github.com:apollographql/router into bnjjj/feat…
bnjjj Mar 8, 2024
360f1e8
fix tests
bnjjj Mar 8, 2024
c727277
refactor
bnjjj Mar 8, 2024
0f50dd8
switch from LinkedList to Vec as the performance gain was not that bi…
bnjjj Mar 8, 2024
a15279b
wrap selectors into an Arc
bnjjj Mar 11, 2024
3d90a79
Merge branch 'dev' of github.com:apollographql/router into bnjjj/feat…
bnjjj Mar 11, 2024
a5174c1
Merge branch 'dev' of github.com:apollographql/router into bnjjj/feat…
bnjjj Mar 13, 2024
7258849
fix a bug with views
bnjjj Mar 15, 2024
1e366f9
update docs
bnjjj Mar 15, 2024
090703b
Merge branch 'dev' into bnjjj/feat_4319
bnjjj Mar 25, 2024
83bb542
add metrics
bnjjj Mar 26, 2024
28e9063
add unit test for router instrument
bnjjj Mar 26, 2024
52dde11
add unit test for supergraph instruments
bnjjj Mar 27, 2024
b536a07
add support of default_attribute_requirement_level
bnjjj Mar 27, 2024
3a449f5
update metrics snapshot
bnjjj Mar 28, 2024
d9bc51f
fix tests and docs
bnjjj Mar 28, 2024
c79f6be
changelog
bnjjj Mar 28, 2024
9a1bf08
Merge branch 'dev' of github.com:apollographql/router into bnjjj/feat…
bnjjj Mar 28, 2024
1b4f369
fix requirement_level configuration
bnjjj Mar 29, 2024
3b0559f
fix tests
bnjjj Mar 29, 2024
82b5215
update snapshot
bnjjj Mar 29, 2024
ed41bfb
Update .changesets/feat_bnjjj_feat_4319.md
bnjjj Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions apollo-router/src/configuration/metrics.rs
Expand Up @@ -307,6 +307,14 @@ impl InstrumentData {
"$..events",
opt.instruments,
"$..instruments",
opt.instruments.router,
"$..instruments.router",
opt.instruments.supergraph,
"$..instruments.supergraph",
opt.instruments.subgraph,
"$..instruments.subgraph",
opt.instruments.default_attribute_requirement_level,
"$..instruments.default_attribute_requirement_level",
opt.spans,
"$..spans",
opt.spans.mode,
Expand Down
Expand Up @@ -9,6 +9,10 @@ expression: "&metrics.non_zero()"
attributes:
opt.events: false
opt.instruments: false
opt.instruments.default_attribute_requirement_level: false
opt.instruments.router: false
opt.instruments.subgraph: false
opt.instruments.supergraph: false
opt.logging.experimental_when_header: true
opt.metrics.otlp: true
opt.metrics.prometheus: true
Expand Down

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions apollo-router/src/metrics/mod.rs
Expand Up @@ -231,11 +231,9 @@ pub(crate) mod test_utils {
} else if let Some(histogram) = metric.data.as_any().downcast_ref::<Histogram<T>>()
{
if matches!(ty, MetricType::Histogram) {
if let Some(value) = value.to_u64() {
return histogram.data_points.iter().any(|datapoint| {
datapoint.attributes == *attributes && datapoint.count == value
});
}
return histogram.data_points.iter().any(|datapoint| {
datapoint.attributes == *attributes && datapoint.sum == value
});
}
}
}
Expand Down Expand Up @@ -905,7 +903,7 @@ macro_rules! assert_gauge {
}

#[cfg(test)]
macro_rules! assert_histogram {
macro_rules! assert_histogram_sum {

($($name:ident).+, $value: expr, $($attr_key:literal = $attr_value:expr),+) => {
let attributes = vec![$(opentelemetry::KeyValue::new($attr_key, $attr_value)),+];
Expand All @@ -932,7 +930,7 @@ macro_rules! assert_histogram {
};

($name:literal, $value: expr) => {
let result = crate::metrics::collect_metrics().assert($name, $value, &[]);
let result = crate::metrics::collect_metrics().assert($name, crate::metrics::test_utils::MetricType::Histogram, $value, &[]);
assert_metric!(result, $name, None, Some($value.into()), &[]);
};
}
Expand Down Expand Up @@ -1143,7 +1141,7 @@ mod test {
async fn test_u64_histogram() {
async {
u64_histogram!("test", "test description", 1, "attr" = "val");
assert_histogram!("test", 1, "attr" = "val");
assert_histogram_sum!("test", 1, "attr" = "val");
}
.with_metrics()
.await;
Expand All @@ -1153,7 +1151,7 @@ mod test {
async fn test_i64_histogram() {
async {
i64_histogram!("test", "test description", 1, "attr" = "val");
assert_histogram!("test", 1, "attr" = "val");
assert_histogram_sum!("test", 1, "attr" = "val");
}
.with_metrics()
.await;
Expand All @@ -1163,7 +1161,7 @@ mod test {
async fn test_f64_histogram() {
async {
f64_histogram!("test", "test description", 1.0, "attr" = "val");
assert_histogram!("test", 1, "attr" = "val");
assert_histogram_sum!("test", 1, "attr" = "val");
}
.with_metrics()
.await;
Expand All @@ -1185,7 +1183,7 @@ mod test {
async fn test_type_counter() {
async {
f64_counter!("test", "test description", 1.0, "attr" = "val");
assert_histogram!("test", 1, "attr" = "val");
assert_histogram_sum!("test", 1, "attr" = "val");
}
.with_metrics()
.await;
Expand All @@ -1196,7 +1194,7 @@ mod test {
async fn test_type_up_down_counter() {
async {
f64_up_down_counter!("test", "test description", 1.0, "attr" = "val");
assert_histogram!("test", 1, "attr" = "val");
assert_histogram_sum!("test", 1, "attr" = "val");
}
.with_metrics()
.await;
Expand All @@ -1211,7 +1209,7 @@ mod test {
.u64_observable_gauge("test")
.with_callback(|m| m.observe(5, &[]))
.init();
assert_histogram!("test", 1, "attr" = "val");
assert_histogram_sum!("test", 1, "attr" = "val");
}
.with_metrics()
.await;
Expand Down
11 changes: 5 additions & 6 deletions apollo-router/src/plugins/telemetry/config.rs
Expand Up @@ -88,9 +88,8 @@ pub(crate) struct Instrumentation {
pub(crate) events: config_new::events::Events,
/// Span configuration
pub(crate) spans: config_new::spans::Spans,
#[serde(skip)]
/// Instrument configuration
pub(crate) instruments: config_new::instruments::Instruments,
pub(crate) instruments: config_new::instruments::InstrumentsConfig,
}

/// Metrics configuration
Expand Down Expand Up @@ -168,14 +167,14 @@ impl TryInto<Box<dyn View>> for MetricView {
record_min_max: true,
},
);
let mut instrument = Instrument::new().name(self.name);
let instrument = Instrument::new().name(self.name);
let mut mask = Stream::new();
if let Some(desc) = self.description {
instrument = instrument.description(desc);
mask = mask.description(desc);
}
if let Some(unit) = self.unit {
instrument = instrument.unit(Unit::new(unit));
mask = mask.unit(Unit::new(unit));
}
let mut mask = Stream::new();
if let Some(aggregation) = aggregation {
mask = mask.aggregation(aggregation);
}
Expand Down