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: Usage Reporting. #898

Merged
merged 70 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
abc2917
ok we have the usage_reporting_signature now
o0Ignition0o Apr 5, 2022
86448c0
extract usage_reporting_signature
o0Ignition0o Apr 6, 2022
98f4d12
wip, let's put the usage_reporting in the right span and retrieve it now
o0Ignition0o Apr 6, 2022
ff67553
add an error snapshot test with usage_reporting_signature
o0Ignition0o Apr 6, 2022
de81dc8
Merge branch 'main' into igni/usage_reporting
o0Ignition0o Apr 11, 2022
7a12a8e
Merge branch 'main' into igni/usage_reporting
o0Ignition0o Apr 12, 2022
d81363e
wip: add metrics to the telemetry plugin
o0Ignition0o Apr 12, 2022
a431ac2
fixed a json_ext bug that would lead to panics when trying to update …
o0Ignition0o Apr 12, 2022
4edd359
wip
o0Ignition0o Apr 13, 2022
2173e17
Use latest router bridge + Merge branch 'main' into igni/usage_reporting
o0Ignition0o Apr 22, 2022
50d6720
make tests pass
o0Ignition0o Apr 22, 2022
237a3cc
compliance
o0Ignition0o Apr 22, 2022
ef99264
Merge with main
Apr 26, 2022
37c70f4
WIP, in theory everything in place before collecting metrics.
Apr 28, 2022
4b66938
fix failing test
Apr 28, 2022
915dc06
Clippy licenses
Apr 28, 2022
f96ad40
Add broken map_future_with_context layer
Apr 29, 2022
5338ce7
bump router bridge + add a couple of comments
o0Ignition0o Apr 29, 2022
9cedf52
Progress
Apr 29, 2022
b7e508f
Merge branch 'igni/usage_reporting' of github.com:apollographql/route…
o0Ignition0o Apr 29, 2022
f4f7658
make sure we clone the sender before each requests async move
o0Ignition0o Apr 29, 2022
2e260d1
Remove stats report key added by mistake.
Apr 29, 2022
73fed02
merge main
Apr 30, 2022
bbf0e3b
Add unit test for map future with context
Apr 30, 2022
7a8c768
Update doc for map_future_with_context
Apr 30, 2022
7d611c0
Move to AddAssign
May 2, 2022
737d8b1
bump router bridge version
o0Ignition0o May 2, 2022
418fa67
Add aggregation test. Fixed a few bugs
May 2, 2022
ae748fb
Prepare for apollo metrics. Simplify telemetry pipeline.
May 3, 2022
599eeb0
Fill out basic usage reporting.
May 3, 2022
ab93391
Merge with main
May 3, 2022
2a414ac
bump router bridge version + accomodate the changes
o0Ignition0o May 4, 2022
7c4ab3d
compliance check
o0Ignition0o May 4, 2022
e03fc58
Add testing for metrics.
May 4, 2022
0161a84
Add testing for metrics.
May 5, 2022
b6f39d1
Add testing for metrics.
May 5, 2022
1c76de8
Move usage report storage to caching query planner.
May 5, 2022
e95b03a
Move usage report storage to caching query planner.
May 5, 2022
a162a55
Add client name and version to tests.
May 5, 2022
729cfc5
Add multiple operations test
May 5, 2022
c2b6f92
almost there
o0Ignition0o May 5, 2022
83ec75c
Add correct reporting snapshots. Exclude unknown operation.
May 5, 2022
6902ea2
Add correct reporting snapshots. Fix unknown operation test.
May 5, 2022
33dcd59
Add exclude functionality
May 5, 2022
19eb810
Add latency info
May 5, 2022
78b9e97
Fix client version to stats.
May 5, 2022
4c2b668
Reset batch limit for spaceport
May 5, 2022
5661c7c
Fix apollo key and graph ref being picked up outside of serialisation.
May 5, 2022
4e9828c
Clippy
May 5, 2022
9a51789
update query and schema validation tests now that the router bridge v…
o0Ignition0o May 5, 2022
aaf7c40
Merge branch 'main' into igni/usage_reporting
o0Ignition0o May 5, 2022
3d0904a
first draft of a changelog
o0Ignition0o May 5, 2022
baa53d5
bump router bridge
o0Ignition0o May 5, 2022
0f63e5f
Add license key functionality comment.
May 6, 2022
3ab07ce
Make spaceport submit message debug.
May 6, 2022
91162f2
Rename EXCLUDE to STUDIO_EXCLUDE
May 6, 2022
5056658
Disable studio metrics id sender is Noop
May 6, 2022
46e9a51
Simplify populate_context so that it does not clone the context as pa…
May 6, 2022
bd7e960
revert json_ext behavior change
o0Ignition0o May 6, 2022
5067b39
remove unused dependency + leftover as
o0Ignition0o May 6, 2022
546b9ba
Update apollo-router/src/plugins/telemetry/mod.rs
BrynCooke May 6, 2022
accbbb3
remove dependency to apollo-rs in the router
o0Ignition0o May 6, 2022
2d9400e
Merge branch 'igni/usage_reporting' of github.com:apollographql/route…
o0Ignition0o May 6, 2022
dfc69d3
Replace QueryPlan::for_tests with QueryPlan::fake_new.
May 6, 2022
f7a3a85
Make canned data private, add docs.
May 9, 2022
0def32e
Removed comment around checking the tick, it looks like it's working.
May 9, 2022
07dbd97
Merge main
May 9, 2022
d201310
Update changelog
May 9, 2022
a9debc1
Merge branch 'main' into igni/usage_reporting
May 9, 2022
c402095
Update NEXT_CHANGELOG.md
BrynCooke May 9, 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
78 changes: 59 additions & 19 deletions Cargo.lock

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

26 changes: 26 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# [v0.1.0-preview.8] - (unreleased)
## ❗ BREAKING ❗
## 🚀 Features ( :rocket: )

### Apollo studio Usage Reporting [PR #898](https://github.com/apollographql/router/pull/898)
If you have [enabled telemetry](https://www.apollographql.com/docs/router/configuration/apollo-telemetry#enabling-usage-reporting), you can now see field usage reporting for your queries by heading to the Apollo studio fields section.
Here is more information on how to [set up telemetry](https://www.apollographql.com/docs/studio/metrics/usage-reporting#pushing-metrics-from-apollo-server) and [Field Usage](https://www.apollographql.com/docs/studio/metrics/field-usage)

### PluginTestHarness [PR #898](https://github.com/apollographql/router/pull/898)
Added a simple plugin test harness that provides can provide canned responses to queries. This harness is early in development and the functionality and APIs will change going forward.
BrynCooke marked this conversation as resolved.
Show resolved Hide resolved
```rust
let mut test_harness = PluginTestHarness::builder()
.plugin(plugin)
.schema(Canned)
.build()
.await?;

let _ = test_harness
.call(
RouterRequest::fake_builder()
.header("name_header", "test_client")
.header("version_header", "1.0-test")
.query(query)
.and_operation_name(operation_name)
.and_context(context)
.build()?,
)
.await;
```
## 🐛 Fixes ( :bug: )

### Improve the configuration error report [PR #963](https://github.com/apollographql/router/pull/963)
Expand Down
4 changes: 2 additions & 2 deletions apollo-router-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apollo-parser = "0.2.5"
async-trait = "0.1.53"
atty = "0.2.14"
axum = { version = "0.5.4" }
buildstructor = "0.1.10"
buildstructor = "0.1.12"
bytes = "1.1.0"
dashmap = { version = "5.1.0", features = ["serde"] }
derivative = "2.2.0"
Expand All @@ -42,7 +42,7 @@ opentelemetry = "0.17.0"
opentelemetry-http = "0.6.0"
paste = "1.0.6"
regex = "1.5.5"
router-bridge = { git = "https://github.com/apollographql/federation-rs.git", rev = "33659ef40f44af593da047d7f3349a1b3d86136c" }
router-bridge = { git = "https://github.com/apollographql/federation-rs.git", rev = "58506ee81a9247f4353bb5b892911ad837ba9b55" }
schemars = { version = "0.8.8", features = ["url"] }
serde = { version = "1.0.136", features = ["derive", "rc"] }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
Expand Down
44 changes: 13 additions & 31 deletions apollo-router-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::prelude::graphql::*;
use displaydoc::Display;
use miette::{Diagnostic, NamedSource, Report, SourceSpan};
pub use router_bridge::planner::{PlanError, PlannerSetupError};
pub use router_bridge::planner::{PlanError, PlannerError};
use router_bridge::planner::{PlanErrors, UsageReporting};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use thiserror::Error;
Expand Down Expand Up @@ -229,7 +230,7 @@ pub enum ServiceBuildError {
#[derive(Error, Debug, Display, Clone)]
pub enum QueryPlannerError {
/// couldn't instantiate query planner; invalid schema: {0}
SchemaValidationErrors(PlannerSetupErrors),
SchemaValidationErrors(PlannerErrors),

/// couldn't plan query: {0}
PlanningErrors(PlanErrors),
Expand All @@ -241,7 +242,7 @@ pub enum QueryPlannerError {
CacheResolverError(Arc<CacheResolverError>),

/// empty query plan. This often means an unhandled Introspection query was sent. Please file an issue to apollographql/router.
EmptyPlan,
EmptyPlan(UsageReporting), // usage_reporting_signature

/// unhandled planner result
UnhandledPlannerResult,
Expand All @@ -252,49 +253,30 @@ pub enum QueryPlannerError {

#[derive(Clone, Debug, Error)]
/// Container for planner setup errors
pub struct PlannerSetupErrors(Arc<Vec<PlannerSetupError>>);
pub struct PlannerErrors(Arc<Vec<PlannerError>>);

impl std::fmt::Display for PlannerSetupErrors {
impl std::fmt::Display for PlannerErrors {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!(
"schema validation errors: {}",
self.0
.iter()
.map(|e| e
.message
.clone()
.unwrap_or_else(|| "UNKNWON ERROR".to_string()))
.map(std::string::ToString::to_string)
.collect::<Vec<String>>()
.join(", ")
))
}
}

impl From<Vec<PlannerSetupError>> for QueryPlannerError {
fn from(errors: Vec<PlannerSetupError>) -> Self {
QueryPlannerError::SchemaValidationErrors(PlannerSetupErrors(Arc::new(errors)))
impl From<Vec<PlannerError>> for QueryPlannerError {
fn from(errors: Vec<PlannerError>) -> Self {
QueryPlannerError::SchemaValidationErrors(PlannerErrors(Arc::new(errors)))
}
}

#[derive(Debug, Clone)]
pub struct PlanErrors(Arc<Vec<PlanError>>);

impl From<Vec<PlanError>> for QueryPlannerError {
fn from(errors: Vec<PlanError>) -> Self {
QueryPlannerError::PlanningErrors(PlanErrors(Arc::new(errors)))
}
}

impl std::fmt::Display for PlanErrors {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!(
"query validation errors: {}",
self.0
.iter()
.map(|e| e.to_string())
.collect::<Vec<String>>()
.join(", ")
))
impl From<PlanErrors> for QueryPlannerError {
fn from(errors: PlanErrors) -> Self {
QueryPlannerError::PlanningErrors(errors)
}
}

Expand Down
Loading