Skip to content

Commit

Permalink
Merge branch 'dev' into tninesling/demand-control-opt
Browse files Browse the repository at this point in the history
  • Loading branch information
tninesling authored Jan 8, 2025
2 parents 8973127 + 4dd7df8 commit 526d81d
Show file tree
Hide file tree
Showing 29 changed files with 309 additions and 109 deletions.
34 changes: 0 additions & 34 deletions .changesets/fix_bryn_datadog_agent_sampling.md

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions .changesets/fix_bryn_parent_based_sampling_fix_with_fix.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changesets/fix_tninesling_subscription_operation_init.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Eagerly init subgraph operation for subscription primary nodes ([PR #6509](https://github.com/apollographql/router/pull/6509))

When subgraph operations are deserialized, typically from a query plan cache, they are not automatically parsed into a full document. Instead, each node needs to initialize its operation(s) prior to execution. With this change, the primary node inside SubscriptionNode is initialized in the same way as other nodes in the plan.

By [@tninesling](https://github.com/tninesling) in https://github.com/apollographql/router/pull/6509
58 changes: 58 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,64 @@ All notable changes to Router will be documented in this file.

This project adheres to [Semantic Versioning v2.0.0](https://semver.org/spec/v2.0.0.html).

# [1.59.1] - 2025-01-08

## 🐛 Fixes

### Fix transmitted header value for Datadog priority sampling resolution ([PR #6017](https://github.com/apollographql/router/pull/6017))

The router now transmits correct values of `x-datadog-sampling-priority` to downstream services.

Previously, an `x-datadog-sampling-priority` of `-1` was incorrectly converted to `0` for downstream requests, and `2` was incorrectly converted to `1`. When propagating to downstream services, this resulted in values of `USER_REJECT` being incorrectly transmitted as `AUTO_REJECT`.

### Enable accurate Datadog APM metrics ([PR #6017](https://github.com/apollographql/router/pull/6017))

The router supports a new preview feature, the `preview_datadog_agent_sampling` option, to enable sending all spans to the Datadog Agent so APM metrics and views are accurate.

Previously, the sampler option in `telemetry.exporters.tracing.common.sampler` wasn't Datadog-aware. To get accurate Datadog APM metrics, all spans must be sent to the Datadog Agent with a `psr` or `sampling.priority` attribute set appropriately to record the sampling decision.

The `preview_datadog_agent_sampling` option enables accurate Datadog APM metrics. It should be used when exporting to the Datadog Agent, via OTLP or Datadog-native.

```yaml
telemetry:
exporters:
tracing:
common:
# Only 10 percent of spans will be forwarded from the Datadog agent to Datadog. Experiment to find a value that is good for you!
sampler: 0.1
# Send all spans to the Datadog agent.
preview_datadog_agent_sampling: true
```

Using these options can decrease your Datadog bill, because you will be sending only a percentage of spans from the Datadog Agent to Datadog.

> [!IMPORTANT]
> - Users must enable `preview_datadog_agent_sampling` to get accurate APM metrics. Users that have been using recent versions of the router will have to modify their configuration to retain full APM metrics.
> - The router doesn't support [`in-agent` ingestion control](https://docs.datadoghq.com/tracing/trace_pipeline/ingestion_mechanisms/?tab=java#in-the-agent).
> - Configuring `traces_per_second` in the Datadog Agent won't dynamically adjust the router's sampling rate to meet the target rate.
> - Sending all spans to the Datadog Agent may require that you tweak the `batch_processor` settings in your exporter config. This applies to both OTLP and Datadog native exporters.

Learn more by reading the [updated Datadog tracing documentation](https://apollographql.com/docs/router/configuration/telemetry/exporters/tracing/datadog) for more information on configuration options and their implications.

### Fix non-parent sampling ([PR #6481](https://github.com/apollographql/router/pull/6481))

When the user specifies a non-parent sampler the router should ignore the information from upstream and use its own sampling rate.

The following configuration would not work correctly:

```
exporters:
tracing:
common:
service_name: router
sampler: 0.00001
parent_based_sampler: false
```
All spans are being sampled.
This is now fixed and the router will correctly ignore any upstream sampling decision.

By [@BrynCooke](https://github.com/BrynCooke) in https://github.com/apollographql/router/pull/6481

# [1.59.0] - 2024-12-17

> [!IMPORTANT]
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ dependencies = [

[[package]]
name = "apollo-federation"
version = "1.59.0"
version = "1.59.1"
dependencies = [
"apollo-compiler",
"derive_more",
Expand Down Expand Up @@ -256,7 +256,7 @@ dependencies = [

[[package]]
name = "apollo-router"
version = "1.59.0"
version = "1.59.1"
dependencies = [
"access-json",
"ahash",
Expand Down Expand Up @@ -423,7 +423,7 @@ dependencies = [

[[package]]
name = "apollo-router-benchmarks"
version = "1.59.0"
version = "1.59.1"
dependencies = [
"apollo-parser",
"apollo-router",
Expand All @@ -439,7 +439,7 @@ dependencies = [

[[package]]
name = "apollo-router-scaffold"
version = "1.59.0"
version = "1.59.1"
dependencies = [
"anyhow",
"cargo-scaffold",
Expand Down Expand Up @@ -854,9 +854,9 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"

[[package]]
name = "async-trait"
version = "0.1.84"
version = "0.1.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1244b10dcd56c92219da4e14caa97e312079e185f04ba3eea25061561dc0a0"
checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056"
dependencies = [
"proc-macro2",
"quote",
Expand Down
2 changes: 1 addition & 1 deletion apollo-federation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apollo-federation"
version = "1.59.0"
version = "1.59.1"
authors = ["The Apollo GraphQL Contributors"]
edition = "2021"
description = "Apollo Federation"
Expand Down
2 changes: 1 addition & 1 deletion apollo-router-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apollo-router-benchmarks"
version = "1.59.0"
version = "1.59.1"
authors = ["Apollo Graph, Inc. <[email protected]>"]
edition = "2021"
license = "Elastic-2.0"
Expand Down
2 changes: 1 addition & 1 deletion apollo-router-scaffold/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apollo-router-scaffold"
version = "1.59.0"
version = "1.59.1"
authors = ["Apollo Graph, Inc. <[email protected]>"]
edition = "2021"
license = "Elastic-2.0"
Expand Down
2 changes: 1 addition & 1 deletion apollo-router-scaffold/templates/base/Cargo.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ apollo-router = { path ="{{integration_test}}apollo-router" }
apollo-router = { git="https://github.com/apollographql/router.git", branch="{{branch}}" }
{{else}}
# Note if you update these dependencies then also update xtask/Cargo.toml
apollo-router = "1.59.0"
apollo-router = "1.59.1"
{{/if}}
{{/if}}
async-trait = "0.1.52"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apollo-router-scaffold = { path ="{{integration_test}}apollo-router-scaffold" }
{{#if branch}}
apollo-router-scaffold = { git="https://github.com/apollographql/router.git", branch="{{branch}}" }
{{else}}
apollo-router-scaffold = { git = "https://github.com/apollographql/router.git", tag = "v1.59.0" }
apollo-router-scaffold = { git = "https://github.com/apollographql/router.git", tag = "v1.59.1" }
{{/if}}
{{/if}}
anyhow = "1.0.58"
Expand Down
4 changes: 2 additions & 2 deletions apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apollo-router"
version = "1.59.0"
version = "1.59.1"
authors = ["Apollo Graph, Inc. <[email protected]>"]
repository = "https://github.com/apollographql/router/"
documentation = "https://docs.rs/apollo-router"
Expand Down Expand Up @@ -59,7 +59,7 @@ ci = []
access-json = "0.1.0"
anyhow = "1.0.86"
apollo-compiler.workspace = true
apollo-federation = { path = "../apollo-federation", version = "=1.59.0" }
apollo-federation = { path = "../apollo-federation", version = "=1.59.1" }
arc-swap = "1.6.0"
async-channel = "1.9.0"
async-compression = { version = "0.4.6", features = [
Expand Down
8 changes: 4 additions & 4 deletions apollo-router/src/axum_factory/axum_http_server_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ fn session_count_instrument() -> ObservableGauge<u64> {
.init()
}

struct SessionCountGuard;
struct ActiveSessionCountGuard;

impl SessionCountGuard {
impl ActiveSessionCountGuard {
fn start() -> Self {
ACTIVE_SESSION_COUNT.fetch_add(1, Ordering::Acquire);
Self
}
}

impl Drop for SessionCountGuard {
impl Drop for ActiveSessionCountGuard {
fn drop(&mut self) {
ACTIVE_SESSION_COUNT.fetch_sub(1, Ordering::Acquire);
}
Expand Down Expand Up @@ -655,7 +655,7 @@ async fn handle_graphql(
experimental_log_on_broken_pipe: bool,
http_request: Request<DecompressionBody<Body>>,
) -> impl IntoResponse {
let _guard = SessionCountGuard::start();
let _guard = ActiveSessionCountGuard::start();

let (parts, body) = http_request.into_parts();

Expand Down
53 changes: 33 additions & 20 deletions apollo-router/src/axum_factory/listeners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use futures::channel::oneshot;
use futures::prelude::*;
use hyper::server::conn::Http;
use multimap::MultiMap;
use opentelemetry::metrics::MeterProvider;
use opentelemetry::KeyValue;
#[cfg(unix)]
use tokio::net::UnixListener;
use tokio::sync::mpsc;
Expand All @@ -26,13 +28,29 @@ use crate::axum_factory::ENDPOINT_CALLBACK;
use crate::configuration::Configuration;
use crate::http_server_factory::Listener;
use crate::http_server_factory::NetworkStream;
use crate::metrics::meter_provider;
use crate::router::ApolloRouterError;
use crate::router_factory::Endpoint;
use crate::ListenAddr;

static SESSION_COUNT: AtomicU64 = AtomicU64::new(0);
static TOTAL_SESSION_COUNT: AtomicU64 = AtomicU64::new(0);
static MAX_FILE_HANDLES_WARN: AtomicBool = AtomicBool::new(false);

struct TotalSessionCountGuard;

impl TotalSessionCountGuard {
fn start() -> Self {
TOTAL_SESSION_COUNT.fetch_add(1, Ordering::Acquire);
Self
}
}

impl Drop for TotalSessionCountGuard {
fn drop(&mut self) {
TOTAL_SESSION_COUNT.fetch_sub(1, Ordering::Acquire);
}
}

#[derive(Clone, Debug)]
pub(crate) struct ListenAddrAndRouter(pub(crate) ListenAddr, pub(crate) Router);

Expand Down Expand Up @@ -214,9 +232,19 @@ pub(super) fn serve_router_on_listen_addr(
let server = async move {
tokio::pin!(shutdown_receiver);

let connection_shutdown = Arc::new(Notify::new());
let _total_session_count_instrument = meter_provider()
.meter("apollo/router")
.u64_observable_gauge("apollo_router_session_count_total")
.with_description("Number of currently connected clients")
.with_callback(move |gauge| {
gauge.observe(
TOTAL_SESSION_COUNT.load(Ordering::Relaxed),
&[KeyValue::new("listener", address.to_string())],
);
})
.init();

let address = address.to_string();
let connection_shutdown = Arc::new(Notify::new());

loop {
tokio::select! {
Expand All @@ -234,16 +262,10 @@ pub(super) fn serve_router_on_listen_addr(
tracing::info!("can accept connections again");
MAX_FILE_HANDLES_WARN.store(false, Ordering::SeqCst);
}

// We only want to recognise sessions if we are the main graphql port.
if main_graphql_port {
let session_count = SESSION_COUNT.fetch_add(1, Ordering::Acquire)+1;
tracing::info!(
value.apollo_router_session_count_total = session_count,
listener = &address
);
}
let _guard = main_graphql_port.then(TotalSessionCountGuard::start);

let address = address.clone();
let mut http_config = http_config.clone();
tokio::task::spawn(async move {
// this sender must be moved into the session to track that it is still running
Expand Down Expand Up @@ -352,15 +374,6 @@ pub(super) fn serve_router_on_listen_addr(
}
}
}

// We only want to recognise sessions if we are the main graphql port.
if main_graphql_port {
let session_count = SESSION_COUNT.fetch_sub(1, Ordering::Acquire)-1;
tracing::info!(
value.apollo_router_session_count_total = session_count,
listener = &address
);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
subscription MessageSubscription {
messages {
subject
content
}
}
Loading

0 comments on commit 526d81d

Please sign in to comment.