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

Remove experimental_when_header feature #6285

Merged
merged 6 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 2 additions & 3 deletions apollo-router/feature_discussions.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"experimental": {
"experimental_retry": "https://github.com/apollographql/router/discussions/2241",
"experimental_response_trace_id": "https://github.com/apollographql/router/discussions/2147",
"experimental_when_header": "https://github.com/apollographql/router/discussions/1961"
"experimental_response_trace_id": "https://github.com/apollographql/router/discussions/2147"
},
"preview": {
"preview_entity_cache": "https://github.com/apollographql/router/discussions/4592"
}
}
}
4 changes: 1 addition & 3 deletions apollo-router/src/configuration/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,7 @@ impl InstrumentData {
opt.spans.subgraph,
"$..spans.subgraph",
opt.spans.supergraph,
"$..spans.supergraph",
opt.logging.experimental_when_header,
"$..logging.experimental_when_header"
"$..spans.supergraph"
);

populate_config_instrument!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ expression: "&metrics.non_zero()"
opt.instruments.router: true
opt.instruments.subgraph: true
opt.instruments.supergraph: true
opt.logging.experimental_when_header: true
opt.metrics.otlp: true
opt.metrics.prometheus: true
opt.spans: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3545,68 +3545,6 @@ expression: "&schema"
],
"description": "Configuration to forward header values in metric labels"
},
"HeaderLoggingCondition": {
"anyOf": [
{
"additionalProperties": false,
"description": "Match header value given a regex to display logs",
"properties": {
"body": {
"default": false,
"description": "Display request/response body (default: false)",
"type": "boolean"
},
"headers": {
"default": false,
"description": "Display request/response headers (default: false)",
"type": "boolean"
},
"match": {
"description": "Regex to match the header value",
"type": "string"
},
"name": {
"description": "Header name",
"type": "string"
}
},
"required": [
"match",
"name"
],
"type": "object"
},
{
"additionalProperties": false,
"description": "Match header value given a value to display logs",
"properties": {
"body": {
"default": false,
"description": "Display request/response body (default: false)",
"type": "boolean"
},
"headers": {
"default": false,
"description": "Display request/response headers (default: false)",
"type": "boolean"
},
"name": {
"description": "Header name",
"type": "string"
},
"value": {
"description": "Header value",
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
}
]
},
"HeadersLocation": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -4266,14 +4204,6 @@ expression: "&schema"
"$ref": "#/definitions/LoggingCommon",
"description": "#/definitions/LoggingCommon"
},
"experimental_when_header": {
"description": "Log configuration to log request and response for subgraphs and supergraph Note that this will be removed when events are implemented.",
"items": {
"$ref": "#/definitions/HeaderLoggingCondition",
"description": "#/definitions/HeaderLoggingCondition"
},
"type": "array"
},
"stdout": {
"$ref": "#/definitions/StdOut",
"description": "#/definitions/StdOut"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ telemetry:
enabled: true
agent:
endpoint: default
logging:
experimental_when_header:
- name: apollo-router-log-request
value: test
headers: true # default: false
body: true # default: false
# log request for all requests coming from Iphones
- name: custom-header
match: ^foo.*
headers: true
instrumentation:
spans:
mode: spec_compliant
Expand Down

This file was deleted.

134 changes: 1 addition & 133 deletions apollo-router/src/plugins/telemetry/config_new/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ use serde::de::Visitor;
use serde::Deserialize;
use serde::Deserializer;

use crate::configuration::ConfigurationError;
use crate::plugins::telemetry::config::AttributeValue;
use crate::plugins::telemetry::config::TraceIdFormat;
use crate::plugins::telemetry::config_new::experimental_when_header::HeaderLoggingCondition;
use crate::plugins::telemetry::resource::ConfigResource;
use crate::services::SupergraphRequest;

/// Logging configuration.
#[derive(Deserialize, JsonSchema, Clone, Default, Debug)]
Expand All @@ -35,44 +32,6 @@ pub(crate) struct Logging {
#[serde(skip)]
/// Settings for logging to a file.
pub(crate) file: File,

/// Log configuration to log request and response for subgraphs and supergraph
/// Note that this will be removed when events are implemented.
#[serde(rename = "experimental_when_header")]
pub(crate) when_header: Vec<HeaderLoggingCondition>,
}

impl Logging {
pub(crate) fn validate(&self) -> Result<(), ConfigurationError> {
let misconfiguration = self.when_header.iter().any(|cfg| match cfg {
HeaderLoggingCondition::Matching { headers, body, .. }
| HeaderLoggingCondition::Value { headers, body, .. } => !body && !headers,
});

if misconfiguration {
Err(ConfigurationError::InvalidConfiguration {
message: "'experimental_when_header' configuration for logging is invalid",
error: String::from(
"body and headers must not be both false because it doesn't enable any logs",
),
})
} else {
Ok(())
}
}

/// Returns if we should display the request/response headers and body given the `SupergraphRequest`
pub(crate) fn should_log(&self, req: &SupergraphRequest) -> (bool, bool) {
self.when_header
.iter()
.fold((false, false), |(log_headers, log_body), current| {
let (current_log_headers, current_log_body) = current.should_log(req);
(
log_headers || current_log_headers,
log_body || current_log_body,
)
})
}
}

#[derive(Clone, Debug, Deserialize, JsonSchema, Default)]
Expand Down Expand Up @@ -470,13 +429,10 @@ pub(crate) enum Rollover {

#[cfg(test)]
mod test {
use regex::Regex;
use serde_json::json;

use crate::plugins::telemetry::config_new::experimental_when_header::HeaderLoggingCondition;
use crate::plugins::telemetry::config_new::logging::Format;
use crate::plugins::telemetry::config_new::logging::Logging;
use crate::services::SupergraphRequest;

#[test]
fn format_de() {
let format = serde_json::from_value::<Format>(json!("text")).unwrap();
Expand All @@ -488,92 +444,4 @@ mod test {
let format = serde_json::from_value::<Format>(json!({"json":{}})).unwrap();
assert_eq!(format, Format::Json(Default::default()));
}

#[test]
fn test_logging_conf_validation() {
let logging_conf = Logging {
when_header: vec![HeaderLoggingCondition::Value {
name: "test".to_string(),
value: String::new(),
headers: true,
body: false,
}],
..Default::default()
};

logging_conf.validate().unwrap();

let logging_conf = Logging {
when_header: vec![HeaderLoggingCondition::Value {
name: "test".to_string(),
value: String::new(),
headers: false,
body: false,
}],
..Default::default()
};

let validate_res = logging_conf.validate();
assert!(validate_res.is_err());
assert_eq!(validate_res.unwrap_err().to_string(), "'experimental_when_header' configuration for logging is invalid: body and headers must not be both false because it doesn't enable any logs");
}

#[test]
fn test_logging_conf_should_log() {
let logging_conf = Logging {
when_header: vec![HeaderLoggingCondition::Matching {
name: "test".to_string(),
matching: Regex::new("^foo*").unwrap(),
headers: true,
body: false,
}],
..Default::default()
};
let req = SupergraphRequest::fake_builder()
.header("test", "foobar")
.build()
.unwrap();
assert_eq!(logging_conf.should_log(&req), (true, false));

let logging_conf = Logging {
when_header: vec![HeaderLoggingCondition::Value {
name: "test".to_string(),
value: String::from("foobar"),
headers: true,
body: false,
}],
..Default::default()
};
assert_eq!(logging_conf.should_log(&req), (true, false));

let logging_conf = Logging {
when_header: vec![
HeaderLoggingCondition::Matching {
name: "test".to_string(),
matching: Regex::new("^foo*").unwrap(),
headers: true,
body: false,
},
HeaderLoggingCondition::Matching {
name: "test".to_string(),
matching: Regex::new("^*bar$").unwrap(),
headers: false,
body: true,
},
],
..Default::default()
};
assert_eq!(logging_conf.should_log(&req), (true, true));

let logging_conf = Logging {
when_header: vec![HeaderLoggingCondition::Matching {
name: "testtest".to_string(),
matching: Regex::new("^foo*").unwrap(),
headers: true,
body: false,
}],
..Default::default()
};
assert_eq!(logging_conf.should_log(&req), (false, false));
}
}
1 change: 0 additions & 1 deletion apollo-router/src/plugins/telemetry/config_new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ mod conditional;
pub(crate) mod connector;
pub(crate) mod cost;
pub(crate) mod events;
mod experimental_when_header;
pub(crate) mod extendable;
pub(crate) mod graphql;
pub(crate) mod instruments;
Expand Down
Loading