Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions .changesets/feat_enhanced_observability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### New `apollo.router.cache.storage.estimated_size` gauge ([PR #5770](https://github.com/apollographql/router/pull/5770))

The router supports the new metric `apollo.router.cache.storage.estimated_size` that helps users understand and monitor the amount of memory that query planner cache entries consume.

The `apollo.router.cache.storage.estimated_size` metric gives an estimated size in bytes of a cache entry. It has the following attributes:
- `kind`: `query planner`.
- `storage`: `memory`.

Before using the estimate to decide whether to update the cache, users should validate that the estimate correlates with their pod's memory usage.

To learn how to troubleshoot with this metric, see the [Pods terminating due to memory pressure](https://www.apollographql.com/docs/router/containerization/kubernetes#pods-terminating-due-to-memory-pressure) guide in docs.

By [@BrynCooke](https://github.com/BrynCooke) in https://github.com/apollographql/router/pull/5770
5 changes: 5 additions & 0 deletions .changesets/fix_missing_cache_gauge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Fix missing `apollo_router_cache_size` metric ([PR #5770](https://github.com/apollographql/router/pull/5770))

Previously, if the in-memory cache wasn't mutated, the `apollo_router_cache_size` metric wouldn't be available. This has been fixed in this release.

By [@BrynCooke](https://github.com/BrynCooke) in https://github.com/apollographql/router/pull/5770
6 changes: 4 additions & 2 deletions apollo-router/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use self::storage::ValueType;
use crate::configuration::RedisCache;

pub(crate) mod redis;
mod size_estimation;
pub(crate) mod storage;
pub(crate) use size_estimation::estimate_size;

type WaitMap<K, V> = Arc<Mutex<HashMap<K, broadcast::Sender<V>>>>;
pub(crate) const DEFAULT_CACHE_CAPACITY: NonZeroUsize = match NonZeroUsize::new(512) {
Expand All @@ -37,7 +39,7 @@ where
pub(crate) async fn with_capacity(
capacity: NonZeroUsize,
redis: Option<RedisCache>,
caller: &str,
caller: &'static str,
) -> Result<Self, BoxError> {
Ok(Self {
wait_map: Arc::new(Mutex::new(HashMap::new())),
Expand All @@ -47,7 +49,7 @@ where

pub(crate) async fn from_configuration(
config: &crate::configuration::Cache,
caller: &str,
caller: &'static str,
) -> Result<Self, BoxError> {
Self::with_capacity(config.in_memory.limit, config.redis.clone(), caller).await
}
Expand Down
7 changes: 7 additions & 0 deletions apollo-router/src/cache/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,19 @@ mod test {

use url::Url;

use crate::cache::storage::ValueType;

#[test]
fn ensure_invalid_payload_serialization_doesnt_fail() {
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
struct Stuff {
time: SystemTime,
}
impl ValueType for Stuff {
fn estimated_size(&self) -> Option<usize> {
None
}
}

let invalid_json_payload = super::RedisValue(Stuff {
// this systemtime is invalid, serialization will fail
Expand Down
Loading