Skip to content

Commit

Permalink
Changes to telemetry configuration discovered during docs (#4133)
Browse files Browse the repository at this point in the history
Note that this code is not currently used, but is needed for the other
telemetry PR changes.

Various issues with telemetry next config were discovered during
documentation. The code changes are addressed in this PR with a separate
docs PR in the works.


Part of #3226


<!-- start metadata -->
---

**Checklist**

Complete the checklist (and note appropriate exceptions) before the PR
is marked ready-for-review.

- [ ] Changes are compatible[^1]
- [ ] Documentation[^2] completed
- [ ] Performance impact assessed and acceptable
- Tests added and passing[^3]
    - [ ] Unit Tests
    - [ ] Integration Tests
    - [ ] Manual Tests

**Exceptions**

*Note any exceptions here*

**Notes**

[^1]: It may be appropriate to bring upcoming changes to the attention
of other (impacted) groups. Please endeavour to do this before seeking
PR approval. The mechanism for doing this will vary considerably, so use
your judgement as to how and when to do this.
[^2]: Configuration is an important part of many changes. Where
applicable please try to document configuration examples.
[^3]: Tick whichever testing boxes are applicable. If you are adding
Manual Tests, please document the manual testing (extensively) in the
Exceptions.

Co-authored-by: bryn <[email protected]>
  • Loading branch information
BrynCooke and bryn authored Nov 3, 2023
1 parent 89ea712 commit 606dad0
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 29 deletions.
8 changes: 8 additions & 0 deletions apollo-router/src/configuration/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ fn validate_project_config_files() {
{
continue;
}
#[cfg(not(telemetry_next))]
if entry.path().to_string_lossy().contains("telemetry_next") {
continue;
}

let name = entry.file_name().to_string_lossy();
if filename_matcher.is_match(&name) {
Expand Down Expand Up @@ -679,6 +683,10 @@ fn visit_schema(path: &str, schema: &Value, errors: &mut Vec<String>) {
for (k, v) in o {
if k.as_str() == "properties" {
let properties = v.as_object().expect("properties must be an object");
if properties.len() == 1 {
// This is probably an enum property
continue;
}
for (k, v) in properties {
let path = format!("{path}.{k}");
if v.as_object().and_then(|o| o.get("description")).is_none() {
Expand Down
33 changes: 20 additions & 13 deletions apollo-router/src/plugins/telemetry/config_new/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,12 @@ pub(crate) enum RouterEvent {
#[derive(Deserialize, JsonSchema, Clone, Debug, Default)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub(crate) enum DefaultAttributeRequirementLevel {
/// Attributes that are marked as required or recommended in otel semantic conventions and apollo documentation will be included
Recommended,

/// Attributes that are marked as required in otel semantic conventions and apollo documentation will be included (default)
#[default]
Required,
/// Attributes that are marked as required or recommended in otel semantic conventions and apollo documentation will be included
Recommended,
/// Attributes that are marked as required, recommended or opt-in in otel semantic conventions and apollo documentation will be included
OptIn,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -415,6 +414,14 @@ pub(crate) enum SubgraphCustomAttribute {
/// The supergraph query operation kind (query|mutation|subscription).
supergraph_operation_kind: OperationKind,
},
SupergraphQuery {
/// The supergraph query to the subgraph.
supergraph_query: Query,
/// Optional redaction pattern.
redact: Option<String>,
/// Optional default value.
default: Option<String>,
},
SupergraphQueryVariable {
/// The supergraph query variable name.
supergraph_query_variable: String,
Expand Down Expand Up @@ -528,28 +535,28 @@ pub(crate) struct SubgraphAttributes {
/// Examples:
/// * products
/// Requirement level: Required
#[serde(rename = "graphql.federation.subgraph.name")]
graphql_federation_subgraph_name: Option<bool>,
#[serde(rename = "subgraph.name")]
subgraph_name: Option<bool>,
/// The GraphQL document being executed.
/// Examples:
/// * query findBookById { bookById(id: ?) { name } }
/// Requirement level: Recommended
#[serde(rename = "graphql.document")]
graphql_document: Option<bool>,
#[serde(rename = "subgraph.graphql.document")]
subgraph_graphql_document: Option<bool>,
/// The name of the operation being executed.
/// Examples:
/// * findBookById
/// Requirement level: Recommended
#[serde(rename = "graphql.operation.name")]
graphql_operation_name: Option<bool>,
#[serde(rename = "subgraph.graphql.operation.name")]
subgraph_graphql_operation_name: Option<bool>,
/// The type of the operation being executed.
/// Examples:
/// * query
/// * subscription
/// * mutation
/// Requirement level: Recommended
#[serde(rename = "graphql.operation.type")]
graphql_operation_type: Option<bool>,
#[serde(rename = "subgraph.graphql.operation.type")]
subgraph_graphql_operation_type: Option<bool>,
}

/// Common attributes for http server and client.
Expand Down Expand Up @@ -737,7 +744,7 @@ pub(crate) struct HttpServerAttributes {
url_scheme: Option<bool>,
}

/// Attrubtes for HTTP clients
/// Attributes for HTTP clients
/// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#http-client
#[allow(dead_code)]
#[derive(Deserialize, JsonSchema, Clone, Default, Debug)]
Expand Down
34 changes: 34 additions & 0 deletions apollo-router/src/plugins/telemetry/config_new/conditions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use schemars::JsonSchema;
use serde::Deserialize;

use crate::plugins::telemetry::config::AttributeValue;

#[allow(dead_code)]
#[derive(Deserialize, JsonSchema, Clone, Debug)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub(crate) enum Condition<T> {
/// A condition to check a selection against a value.
Eq([SelectorOrValue<T>; 2]),
/// All sub-conditions must be true.
All(Vec<Condition<T>>),
/// At least one sub-conditions must be true.
Any(Vec<Condition<T>>),
/// The sub-condition must not be true
Not(Box<Condition<T>>),
}

impl Condition<()> {
pub(crate) fn empty<T>() -> Condition<T> {
Condition::Any(vec![])
}
}

#[allow(dead_code)]
#[derive(Deserialize, JsonSchema, Clone, Debug)]
#[serde(deny_unknown_fields, rename_all = "snake_case", untagged)]
pub(crate) enum SelectorOrValue<T> {
/// A constant value.
Value(AttributeValue),
/// Selector to extract a value from the pipeline.
Selector(T),
}
29 changes: 26 additions & 3 deletions apollo-router/src/plugins/telemetry/config_new/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::plugins::telemetry::config_new::attributes::SubgraphAttributes;
use crate::plugins::telemetry::config_new::attributes::SubgraphCustomAttribute;
use crate::plugins::telemetry::config_new::attributes::SupergraphAttributes;
use crate::plugins::telemetry::config_new::attributes::SupergraphCustomAttribute;
use crate::plugins::telemetry::config_new::conditions::Condition;

/// Events are
#[allow(dead_code)]
Expand All @@ -30,11 +31,11 @@ pub(crate) struct Events {
#[serde(deny_unknown_fields, default)]
struct RouterEvents {
/// Log the router request
request: bool,
request: EventLevel,
/// Log the router response
response: bool,
response: EventLevel,
/// Log the router error
error: bool,
error: EventLevel,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -84,9 +85,31 @@ where
{
/// The log level of the event.
level: EventLevel,

/// The event message.
message: String,

/// When to trigger the event.
on: EventOn,

/// The event attributes.
#[serde(default = "Extendable::empty::<A, E>")]
attributes: Extendable<A, E>,

/// The event conditions.
#[serde(default = "Condition::empty::<E>")]
condition: Condition<E>,
}

/// When to trigger the event.
#[allow(dead_code)]
#[derive(Deserialize, JsonSchema, Clone, Debug)]
#[serde(rename_all = "snake_case")]
pub(crate) enum EventOn {
/// Log the event on request
Request,
/// Log the event on response
Response,
/// Log the event on error
Error,
}
43 changes: 37 additions & 6 deletions apollo-router/src/plugins/telemetry/config_new/instruments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::plugins::telemetry::config_new::attributes::SubgraphAttributes;
use crate::plugins::telemetry::config_new::attributes::SubgraphCustomAttribute;
use crate::plugins::telemetry::config_new::attributes::SupergraphAttributes;
use crate::plugins::telemetry::config_new::attributes::SupergraphCustomAttribute;
use crate::plugins::telemetry::config_new::conditions::Condition;

#[allow(dead_code)]
#[derive(Clone, Deserialize, JsonSchema, Debug, Default)]
Expand All @@ -37,19 +38,37 @@ pub(crate) struct Instruments {
struct RouterInstruments {
/// Histogram of server request duration
#[serde(rename = "http.server.request.duration")]
http_server_request_duration: bool,
http_server_request_duration:
DefaultedStandardInstrument<Extendable<RouterAttributes, RouterCustomAttribute>>,

/// Gauge of active requests
#[serde(rename = "http.server.active_requests")]
http_server_active_requests: bool,
http_server_active_requests:
DefaultedStandardInstrument<Extendable<RouterAttributes, RouterCustomAttribute>>,

/// Histogram of server request body size
#[serde(rename = "http.server.request.body.size")]
http_server_request_body_size: bool,
http_server_request_body_size:
DefaultedStandardInstrument<Extendable<RouterAttributes, RouterCustomAttribute>>,

/// Histogram of server response body size
#[serde(rename = "http.server.response.body.size")]
http_server_response_body_size: bool,
http_server_response_body_size:
DefaultedStandardInstrument<Extendable<RouterAttributes, RouterCustomAttribute>>,
}

#[allow(dead_code)]
#[derive(Clone, Deserialize, JsonSchema, Debug)]
#[serde(deny_unknown_fields, untagged)]
enum DefaultedStandardInstrument<T> {
Bool(bool),
Extendable { attributes: T },
}

impl<T> Default for DefaultedStandardInstrument<T> {
fn default() -> Self {
DefaultedStandardInstrument::Bool(true)
}
}

#[allow(dead_code)]
Expand Down Expand Up @@ -86,7 +105,7 @@ where
ty: InstrumentType,

/// The value of the instrument.
value: InstrumentValue,
value: InstrumentValue<E>,

/// The description of the instrument.
description: String,
Expand All @@ -97,6 +116,10 @@ where
/// Attributes to include on the instrument.
#[serde(default = "Extendable::empty::<A, E>")]
attributes: Extendable<A, E>,

/// The instrument conditions.
#[serde(default = "Condition::empty::<E>")]
condition: Condition<E>,
}

#[allow(dead_code)]
Expand All @@ -116,10 +139,18 @@ pub(crate) enum InstrumentType {
Gauge,
}

#[allow(dead_code)]
#[derive(Clone, Deserialize, JsonSchema, Debug)]
#[serde(deny_unknown_fields, rename_all = "snake_case", untagged)]
pub(crate) enum InstrumentValue<T> {
Standard(Standard),
Custom(T),
}

#[allow(dead_code)]
#[derive(Clone, Deserialize, JsonSchema, Debug)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub(crate) enum InstrumentValue {
pub(crate) enum Standard {
Duration,
Unit,
Active,
Expand Down
Loading

0 comments on commit 606dad0

Please sign in to comment.