Skip to content

[core][gcs] Export GCS storage operation metrics on the Redis backend - #66882

Merged
rueian merged 4 commits into
ray-project:masterfrom
zzchun:ray-17-gcs-redis-observable-store-metrics
Oct 19, 2026
Merged

rueian merged 4 commits into
ray-project:masterfrom
zzchun:ray-17-gcs-redis-observable-store-metrics

Conversation

@zzchun

@zzchun zzchun commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

gcs_storage_operation_count and gcs_storage_operation_latency_ms are exported by the in-memory and RocksDB GCS storage backends, but not at all on the external-Redis backend: RedisStoreClient is the only StoreClient that GcsServer never wraps in ObservableStoreClient. Dashboards built on these metrics therefore go blank on Redis-backed clusters.

This PR routes both REDIS_PERSIST construction sites in GcsServer (cluster tables and internal KV) through a small gcs::MaybeObserve helper, gated by a new gcs_redis_storage_metrics_enabled config (default true).

Related issues

Split out of #65583 at review. That PR adds a TableName label to the same two metrics; this one makes them exist on Redis. The two are independent and can land in either order.

Additional information

Kill switch

Redis is the one backend that gains Record calls where it had none, so it gets a rollback switch: RAY_gcs_redis_storage_metrics_enabled=false restores the previous behavior. The in-memory and RocksDB backends have always been wrapped and are not gated.

Ownership

ObservableStoreClient now takes its delegate as a shared_ptr instead of a unique_ptr. AsyncCheckHealth is declared on RedisStoreClient and not on the StoreClient interface, so GcsServer keeps a concrete pointer for the periodic health check while handing the same client to the wrapper. StoreClientInternalKV takes a shared_ptr too, because it now consumes MaybeObserve's result. Existing construction sites pass unique_ptr rvalues, which convert implicitly, so none of them change.

Health-check PINGs keep bypassing the wrapper: a probe is not a storage operation and should not appear in gcs_storage_operation_count.

Compatibility

Purely additive: on Redis, series that did not exist begin to exist. No existing series on any backend changes.

Not a duplicate

This is the Redis half of #65583, split out at the reviewer's request; #65583 no longer contains it. Searching open PRs for "observable store client", "gcs_storage_operation redis" and "MaybeObserve" finds no other PR doing this. #66847 adds a metric_context parameter to the ObservableStoreClient constructor; whichever lands second threads it through MaybeObserve.

Testing

bazel test //src/ray/gcs/store_client/tests:observable_store_client_test \
  //src/ray/gcs/store_client/tests:in_memory_store_client_test \
  //src/ray/gcs/tests:redis_gcs_table_storage_test \
  //src/ray/gcs/tests:gcs_kv_manager_test \
  //src/ray/gcs/tests:gcs_server_rpc_test \
  //src/ray/gcs:gcs_server
# Executed 5 out of 5 tests: 5 tests pass; gcs_server builds.
# New cases: MaybeObserveTest.{RecordsWhenEnabled,RecordsNothingWhenDisabled},
# RedisObservableGcsTableStorageTest.{RecordsOnTheRedisBackend,
# RecordsNothingWhenTheKillSwitchIsOff} (against a real redis-server).

pre-commit run --from-ref upstream/master --to-ref HEAD
# All hooks passed.

The new tests match on the Operation tag only, so they keep passing whether or not #65583's TableName label lands first.

@zzchun
zzchun requested a review from a team as a code owner October 9, 2026 12:21

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enables storage operation metrics (count and latency) for the external Redis backend by conditionally wrapping the Redis store client in ObservableStoreClient using a new MaybeObserve helper, controlled by the gcs_redis_storage_metrics_enabled configuration. To facilitate this, ObservableStoreClient and StoreClientInternalKV have been updated to use std::shared_ptr instead of std::unique_ptr. The review feedback recommends adding a RAY_CHECK in the StoreClientInternalKV constructor to defensively guard against null pointer dereferences.

Comment thread src/ray/gcs/store_client_kv.cc Resolved
@zzchun
zzchun force-pushed the ray-17-gcs-redis-observable-store-metrics branch from 4a061d7 to 6375687 Compare October 9, 2026 12:33
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Oct 9, 2026
@rueian rueian self-assigned this Oct 9, 2026
@rueian rueian added the go add ONLY when ready to merge, run all tests label Oct 9, 2026
@rueian rueian assigned karticam and unassigned rueian Oct 9, 2026
Comment thread src/ray/common/ray_config_def.h Resolved
Comment thread src/ray/common/ray_config_def.h Resolved
@karticam

karticam commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

The changes LGTM. can you please shorten/clean-up the redundancies in the comments? And also, lets update the docs too.

@rueian, I am not sure if we should add in a config for this change, or let it go without a config flag since in-memory and rocksDB store already have the behaviour. Can you please help here?

rueian pushed a commit that referenced this pull request Oct 13, 2026
…ncy metrics (#65583)

## Description

`gcs_storage_operation_count` and `gcs_storage_operation_latency_ms` are
labeled by `Operation` only, so a slow `GetAll` on the actor table can't
be told apart from one on the job table without correlating logs.

`ObservableStoreClient` already receives a `table_name` on every call.
This PR:

- records it as a bounded `TableName` label on both metrics, for `Put`,
`Get`, `GetAll`, `MultiGet`, `Delete`, `BatchDelete`, `GetKeys` and
`Exists`;
- instruments `GetNextJobID`, the one storage operation the wrapper used
to skip;
- measures latency on the monotonic clock instead of wall time;
- documents both metrics in `system-metrics.md`.

Exporting these metrics on the external-Redis backend, where they don't
exist today, was split out of this PR at review into #66882.

## Related issues

Closes #65582.

## Additional information

### Label cardinality

`StoreClient` accepts any string as a table name (the shared test base
passes `"test_table"`), so the label is bounded explicitly:
`NormalizeTableNameLabel` keeps names from the `rpc::TablePrefix` enum
and maps anything else to `OTHER`.

In practice the GCS produces seven values: `JOB`, `ACTOR`,
`ACTOR_TASK_SPEC`, `PLACEMENT_GROUP`, `NODE`, `WORKERS` and `KV`. The
hard upper bound is 161 `Operation` × `TableName` combinations per GCS
process (8 table operations × 20 values, plus `GetNextJobID` ×
`JobCounter`), independent of cluster size or actor count.

No user-controlled string reaches a label: the internal KV puts the
user's namespace in the key (`MakeKey` in `store_client_kv.cc`), not in
the table name. `NoUserDataInLabels` covers this.

### `GetNextJobID`

It addresses a counter key rather than a table, so it reports the
`JobCounter` sentinel. It can't simply leave `TableName` unset:
`tag_keys` is the tag allowlist on both metric stacks, and a declared
tag that a call site doesn't record is exported as an empty string, so
it would show up as `TableName=""`.

### Latency clock

Latency used to be the difference of two `NowUnixNanos()` readings,
which is wall time, so an NTP step could record a negative or inflated
value. Every recording site is rewritten here anyway, so they now use
`SteadyNow()`, which `ClockInterface` documents as the clock for
durations.

### Compatibility / release note

This changes series identity: each `Operation` now has up to seven
series instead of one, and `GetNextJobID` is a new `Operation` value.
Label matchers are unaffected. A dashboard or alert that assumed one
series per operation can aggregate the new label away:

```promql
sum without (TableName) (rate(ray_gcs_storage_operation_count_total[5m]))
```

Use `without (TableName)` rather than `by (Operation)`, because `by`
also drops `SessionName`, `Component` and the other global labels.
Aggregations sensitive to series count (`avg`, `max`, `count`) still
change.

### Not a duplicate

Searching open PRs for `"TableName gcs_storage_operation"`, `"observable
store client"`, `"gcs_storage_operation redis"` and `"MaybeObserve"`
finds no other PR labeling these metrics. #66847 edits the same `Record`
call sites to move recording onto a separate io_context. It changes
where recording runs, not what is recorded, so the two compose and
whichever lands second rebases.

### Testing

```bash
bazel test //src/ray/gcs/store_client/tests:table_name_label_test \
  //src/ray/gcs/store_client/tests:observable_store_client_test \
  //src/ray/gcs/store_client/tests:in_memory_store_client_test
# Executed 3 out of 3 tests: 3 tests pass.

pre-commit run --from-ref upstream/master --to-ref HEAD
# All hooks passed.
```

AI assistance (Claude Code) was used to prepare this change. I reviewed
every changed line and ran the tests above locally.

---------

Signed-off-by: zzchun <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Douglas Strodtman <[email protected]>
RedisStoreClient is the only StoreClient that GcsServer never wraps in
ObservableStoreClient, so gcs_storage_operation_count and
gcs_storage_operation_latency_ms are not exported at all when the GCS
uses external Redis.

Route both REDIS_PERSIST construction sites (cluster tables and internal
KV) through a new gcs::MaybeObserve helper, gated by
gcs_redis_storage_metrics_enabled (default true) so the new Record calls
can be rolled back. ObservableStoreClient and StoreClientInternalKV now
hold their delegate as a shared_ptr, because GcsServer keeps a concrete
RedisStoreClient pointer for the periodic health check; health-check
PINGs keep bypassing the wrapper.

Split out of ray-project#65583 at review.

Signed-off-by: zzchun <[email protected]>
…trics flag

Address review feedback on ray-project#66882:
- Shorten the gcs_redis_storage_metrics_enabled comment and drop the
  description of pre-change behavior.
- Remove the duplicated explanation from MaybeObserve, the
  ObservableStoreClient constructor, GcsServer, StoreClientInternalKV and
  the test fixtures.
- system-metrics.md: the storage operation metrics are now exported on every
  backend; document RAY_gcs_redis_storage_metrics_enabled and how the count
  differs from ray_gcs_redis_command_count_total.
- RedisObservableGcsTableStorageTest also asserts TableName=JOB.

Signed-off-by: zzchun <[email protected]>
@zzchun
zzchun force-pushed the ray-17-gcs-redis-observable-store-metrics branch from 6375687 to d4c5402 Compare October 14, 2026 16:42
@zzchun
zzchun requested review from a team as code owners October 14, 2026 16:42
@zzchun

zzchun commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

@karticam Thanks for the review! Addressed in d4c5402:

  • Comments: removed the duplicated explanation and the pre-change wording. The flag comment in ray_config_def.h is now the single place that explains it.
  • Docs: system-metrics.md now says ray_gcs_storage_operation_count_total / ray_gcs_storage_operation_latency_ms are exported on every backend, documents RAY_gcs_redis_storage_metrics_enabled=false, and explains how the count differs from ray_gcs_redis_command_count_total.
  • Rebase: rebased onto the latest master now that [core][gcs] Add a bounded TableName label to GCS Store count and latency metrics #65583 is merged. The Redis test now also asserts TableName=JOB, so the new label is checked end to end against a real Redis.

Tests run locally after the rebase and fixes:

bazel test //src/ray/gcs/store_client/tests:observable_store_client_test \
           //src/ray/gcs/tests:redis_gcs_table_storage_test \
           //src/ray/gcs/tests:gcs_kv_manager_test
# 3 tests pass

The full //src/ray/gcs:gcs_server build couldn't finish locally because the compiler ran out of memory on files this PR doesn't touch. The gcs_server.cc changes since the last green CI run are comments only, and CI will cover the full build.

On whether to keep the flag: happy to go either way, depending on what @rueian thinks. It's there so the extra per-operation metric recording on the Redis path can be turned off without a redeploy. If it isn't worth having, removing it is a small change: drop MaybeObserve and the config, and always wrap the Redis client.

…docs

- MaybeObserveTest writes to the JOB table and asserts TableName=JOB,
  matching RedisObservableGcsTableStorageTest.
- system-metrics.md: shorten the note on the Redis backend.

Signed-off-by: zzchun <[email protected]>
@rueian rueian self-assigned this Oct 16, 2026
Comment thread src/ray/gcs/store_client_kv.h Resolved
The KV store client is never shared, so InitKVManager builds the Redis
client as a unique_ptr and wraps it in ObservableStoreClient only when
gcs_redis_storage_metrics_enabled is set. StoreClientInternalKV is back to
taking and holding a unique_ptr, unchanged from master. MaybeObserve stays
on the table storage path, where the health check shares ownership of the
RedisStoreClient.

Signed-off-by: zzchun <[email protected]>
@rueian
rueian merged commit 885945c into ray-project:master Oct 19, 2026
6 checks passed
@zzchun
zzchun deleted the ray-17-gcs-redis-observable-store-metrics branch October 20, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants