#9464·grpc-go

xds/clients: pass context.Context and extensible structs to Decoder and ResourceWatcher

Author: dashpoleCreated Sep 30, 2026Updated Sep 30, 2026

Use case(s) - what problem will this feature solve?

In internal/xds/clients/xdsclient:

  1. Neither Decoder.Decode(resource *AnyProto, opts DecodeOptions) (*DecodeResult, error) nor ResourceWatcher callbacks (ResourceChanged, ResourceError, AmbientError) accept a context.Context—even though authority.go invokes watcher callbacks via watcherCallbackSerializer.TrySchedule(func(context.Context) { ... }) and currently discards the context.Context parameter. Consumers recording metrics, events, or context-aware slog logs inside Decode or ResourceWatcher callbacks have no context.Context available.
  2. DecodeOptions exposes the entire *Config pointer (allowing decoders to mutate the client's Config map fields), whereas ResourceWatcher.ResourceChanged(data ResourceData, done func()) takes ResourceData directly with no way to pass resource metadata (such as the resource name or version) without breaking the interface signature in the future.

Proposed Solution

  1. Pass ctx context.Context as the first parameter to Decoder.Decode and ResourceWatcher methods:
    • Decode(ctx context.Context, resource AnyProto, opts DecodeOptions) (*DecodeResult, error)
    • ResourceChanged(ctx context.Context, update ResourceUpdate, done func())
    • ResourceError(ctx context.Context, err error, done func())
    • AmbientError(ctx context.Context, err error, done func())
  2. Pass an extensible ResourceUpdate struct (type ResourceUpdate struct { Name string; Data ResourceData; Version string }) to ResourceChanged so future fields can be added backwards-compatibly.
  3. Narrow DecodeOptions to expose only the read-only server/authority context needed by decoders rather than mutable *Config.

Alternatives Considered

Keeping the existing signatures without context.Context or ResourceUpdate. Changing these interface signatures after xdsclient is exported publicly would be a breaking v1 API change.

Additional Context

Part of #9455.