Skip to content

grpc-js: accept canonical Duration representations in outlier detection config - #3126

Open
Jah-yee wants to merge 1 commit into
grpc:masterfrom
Jah-yee:fix/outlier-detection-canonical-duration
Open

Jah-yee wants to merge 1 commit into
grpc:masterfrom
Jah-yee:fix/outlier-detection-canonical-duration

Conversation

@Jah-yee

@Jah-yee Jah-yee commented Nov 5, 2026

Copy link
Copy Markdown

Description

Fixes #2442.

The outlier detection load balancer config parser only accepted the internal
object form of a Duration ({seconds, nanos}). The canonical protobuf JSON
representation of a Duration is a string such as "10s", so a config using the
standard representation was rejected with:

outlier detection config interval parse error: expected Duration, got string

This makes the outlier_detection LB policy unusable with canonical JSON
config, while other duration-bearing policies in this repo
(weighted_round_robin) already accept the string form.

Change

packages/grpc-js/src/load-balancer-outlier-detection.ts

  • Add parseDurationValue(), which accepts the canonical string form
    ("10s", "1.5s"), the DurationMessage form ({seconds: "10", nanos: 0}),
    and the existing internal object form ({seconds: 10, nanos: 0}).
  • validatePositiveDuration() now returns the parsed Duration, and range
    validation is performed against that parsed value rather than the raw input.
  • createFromJson() uses the parsed durations when converting to milliseconds,
    so interval, base_ejection_time and max_ejection_time all honour the
    canonical representation.

The existing object form remains fully supported, so this is backwards
compatible.

Testing

packages/grpc-js/test/test-outlier-detection.ts

Added tests covering the canonical string form (including a fractional value),
the DurationMessage form, the pre-existing object form, and rejection of an
unparseable duration string.

$ npm install
$ npx tsc -p .
$ npx mocha build/test/test-outlier-detection.js
  32 passing

All 26 pre-existing tests in that file still pass.

…on config

The outlier detection load balancer config parser only accepted the
internal object form of a Duration ({seconds, nanos}). The canonical
protobuf JSON representation of a Duration is a string such as "10s",
so a config using the standard representation was rejected with
"expected Duration, got string".

Accept the canonical string form and the DurationMessage form, in
addition to the existing object form, and use the parsed value for
range validation and conversion to milliseconds.

Fixes grpc#2442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Outlier Detection LB config JSON representation does not use standard Duration representation

1 participant