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

chore: Add integration tests for Open Telemetry #276

Merged
merged 37 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c61e954
wip
o0Ignition0o Dec 15, 2021
3be9bce
wip
o0Ignition0o Dec 15, 2021
bf24d41
wip
o0Ignition0o Dec 15, 2021
11b18ad
wip
o0Ignition0o Dec 15, 2021
dd30f07
manually use a subscriber, if this work I'll probably write a macro
o0Ignition0o Dec 15, 2021
9efec19
#[test_span] macro and a couple of test tryouts
o0Ignition0o Dec 16, 2021
113deea
wip, i m going to use a sequence instead of the span ids, this should…
o0Ignition0o Dec 16, 2021
a827251
use dag index + name as span keys so we get deterministic output
o0Ignition0o Dec 16, 2021
c0575d0
wip
o0Ignition0o Dec 16, 2021
ad9a1dc
remove query from the instrumentation
o0Ignition0o Dec 16, 2021
a6b4cbe
Merge branch 'main' into igni/tracing_span_tests
o0Ignition0o Jan 4, 2022
c4e73c4
update snapshots
o0Ignition0o Jan 4, 2022
3245333
validation => validate
o0Ignition0o Jan 4, 2022
9fd9d40
wip, trying to rework the structures
o0Ignition0o Jan 5, 2022
d74ca96
Merge branch 'main' into igni/tracing_span_tests
o0Ignition0o Jan 5, 2022
ee70ef3
remove errors field from tracing
o0Ignition0o Jan 5, 2022
61f8ee3
untagged record enum
o0Ignition0o Jan 5, 2022
a6c1f81
untagged recorded value repr
o0Ignition0o Jan 5, 2022
8f41302
Merge branch 'main' into igni/tracing_span_tests
o0Ignition0o Jan 6, 2022
c6170cc
wip
o0Ignition0o Jan 6, 2022
c6a44d8
wip
o0Ignition0o Jan 6, 2022
b01ea51
almost there, i get twice the logs and none on the span side :(
o0Ignition0o Jan 6, 2022
342568a
wip
o0Ignition0o Jan 7, 2022
0a98404
ok i think i have an ok model now. let's try to make sure the snapsho…
o0Ignition0o Jan 7, 2022
abc5fa0
yay
o0Ignition0o Jan 7, 2022
1208efe
ok let s see how far this gets us
o0Ignition0o Jan 7, 2022
bc9208d
wow it works :D
o0Ignition0o Jan 9, 2022
8698f10
triggered clippy ICE \o/
o0Ignition0o Jan 9, 2022
9aa0c52
use the span id (usize) as json key so the span children are correctl…
o0Ignition0o Jan 9, 2022
f9b0215
Revert "use the span id (usize) as json key so the span children are …
o0Ignition0o Jan 9, 2022
c5b4266
use a structure that preserves the span orders when serializing + mak…
o0Ignition0o Jan 9, 2022
e715d99
(ab)use the super cool snapshots to define subfetch spans, i need to …
o0Ignition0o Jan 9, 2022
ca5b9ad
licenses check
o0Ignition0o Jan 9, 2022
22e527e
#[level(tracing::Level::DEBUG)] by default, which can be customized i…
o0Ignition0o Jan 10, 2022
0d77c2f
add an all_logs method so people can track logs across thread spawns
o0Ignition0o Jan 10, 2022
78516c6
clean up things, use the published test_span crate
o0Ignition0o Jan 10, 2022
7128963
Merge branch 'main' into igni/tracing_span_tests
o0Ignition0o Jan 10, 2022
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
84 changes: 79 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[workspace]
default-members = ["apollo-router", "apollo-router-core"]
members = ["apollo-router", "apollo-router-core", "apollo-router-benchmarks", "xtask"]
members = [
"apollo-router",
"apollo-router-core",
"apollo-router-benchmarks",
"xtask",
]
Comment on lines +3 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 🧶 You keep changing that and someone else keep changing it back.
  2. 🪛 This file is unnecessarily touched in this PR.


[patch.crates-io]
opentelemetry = { git = "https://github.com/open-telemetry/opentelemetry-rust.git", rev = "6b3aa02aa" }
Expand Down
41 changes: 21 additions & 20 deletions apollo-router-core/src/query_planner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ pub(crate) enum PlanNode {

impl QueryPlan {
/// Validate the entire request for variables and services used.
#[tracing::instrument(name = "validation", level = "debug", skip_all)]
pub fn validate_request(
&self,
service_registry: Arc<dyn ServiceRegistry>,
) -> Result<(), Response> {
#[tracing::instrument(skip_all, name = "validate", level = "debug")]
pub fn validate(&self, service_registry: Arc<dyn ServiceRegistry>) -> Result<(), Response> {
let mut early_errors = Vec::new();
for err in self
.root
Expand Down Expand Up @@ -323,14 +320,16 @@ mod fetch {

let query_span = tracing::info_span!("subfetch", service = service_name.as_str());

let Variables { variables, paths } = Variables::new(
&self.requires,
self.variable_usages.as_ref(),
data,
current_dir,
request,
schema,
)?;
let Variables { variables, paths } = query_span.in_scope(|| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧶 per our ADR on telemetry, we should prefer to put this at the source instead of the caller.

Variables::new(
&self.requires,
self.variable_usages.as_ref(),
data,
current_dir,
request,
schema,
)
})?;

let fetcher = service_registry
.get(service_name)
Expand All @@ -343,16 +342,18 @@ mod fetch {
.variables(Arc::new(variables))
.build(),
)
.instrument(query_span)
.instrument(tracing::info_span!(parent: &query_span, "subfetch_stream"))
.await?;

if !response.is_primary() {
return Err(FetchError::SubrequestUnexpectedPatchResponse {
service: service_name.to_owned(),
});
}
query_span.in_scope(|| {
if !response.is_primary() {
return Err(FetchError::SubrequestUnexpectedPatchResponse {
service: service_name.to_owned(),
});
}
Comment on lines +349 to +353
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧶 I'm don't understand why this is under the query_span


self.response_at_path(current_dir, paths, response)
self.response_at_path(current_dir, paths, response)
})
}

#[instrument(level = "debug", name = "response_insert", skip_all)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl RouterBridgeQueryPlanner {

#[async_trait]
impl QueryPlanner for RouterBridgeQueryPlanner {
#[tracing::instrument(name = "plan", level = "debug", skip_all)]
#[tracing::instrument(skip_all, name = "plan", level = "debug")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧶 File unnecessarily touch in this PR

If possible I would like to keep the commits on main focus on their actual feature. If you want to re-order all the skip_all everywhere, you can make it on a separate PR.

async fn get(
&self,
query: String,
Expand Down
3 changes: 2 additions & 1 deletion apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ tokio = { version = "1.15.0", features = ["full"] }
# don't bump it to 0.6 until opentelemetry-otlp does
tonic = { version = "0.5.2", optional = true }
tower = "0.4.11"
tower-http = {version = "0.2.0", features = ["trace"] }
tower-http = { version = "0.2.0", features = ["trace"] }
tracing = "0.1.29"
tracing-futures = "0.2.5"
tracing-opentelemetry = "0.16.0"
Expand All @@ -76,6 +76,7 @@ maplit = "1.0.2"
mockall = "0.11.0"
reqwest = { version = "0.11.8", features = ["json", "stream"] }
test-log = { version = "0.2.8", default-features = false, features = ["trace"] }
test-span = "0.1.0"
tracing-subscriber = { version = "0.3", default-features = false, features = [
"env-filter",
"fmt",
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/src/apollo_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Router<ApolloPreparedQuery> for ApolloRouter {
.await?;

tracing::debug!("query plan\n{:#?}", query_plan);
query_plan.validate_request(Arc::clone(&self.service_registry))?;
query_plan.validate(Arc::clone(&self.service_registry))?;

Ok(ApolloPreparedQuery {
query_plan,
Expand Down
36 changes: 30 additions & 6 deletions apollo-router/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde_json::to_string_pretty;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use test_log::test;
use test_span::prelude::*;
use url::Url;

macro_rules! assert_federated_response {
Expand Down Expand Up @@ -43,7 +43,7 @@ macro_rules! assert_federated_response {
};
}

#[test(tokio::test)]
#[tokio::test]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Why did you remove the logger initialization for these tests?

async fn basic_request() {
assert_federated_response!(
r#"{ topProducts { name name2:name } }"#,
Expand All @@ -53,7 +53,7 @@ async fn basic_request() {
);
}

#[test(tokio::test)]
#[tokio::test]
async fn basic_composition() {
assert_federated_response!(
r#"{ topProducts { upc name reviews {id product { name } author { id name } } } }"#,
Expand All @@ -65,7 +65,31 @@ async fn basic_composition() {
);
}

#[test(tokio::test)]
#[test_span(tokio::test)]
async fn traced_basic_request() {
assert_federated_response!(
r#"{ topProducts { name name2:name } }"#,
hashmap! {
"products".to_string()=>1,
},
);
insta::assert_json_snapshot!(get_spans());
}

#[test_span(tokio::test)]
async fn traced_basic_composition() {
assert_federated_response!(
r#"{ topProducts { upc name reviews {id product { name } author { id name } } } }"#,
hashmap! {
"products".to_string()=>2,
"reviews".to_string()=>1,
"accounts".to_string()=>1,
},
);
insta::assert_json_snapshot!(get_spans());
}

#[tokio::test]
async fn basic_mutation() {
assert_federated_response!(
r#"mutation {
Expand All @@ -88,7 +112,7 @@ async fn basic_mutation() {
);
}

#[test(tokio::test)]
#[test_span(tokio::test)]
async fn variables() {
assert_federated_response!(
r#"
Expand All @@ -113,7 +137,7 @@ async fn variables() {
);
}

#[test(tokio::test)]
#[tokio::test]
async fn missing_variables() {
let request = graphql::Request::builder()
.query(
Expand Down
Loading