chipingress: fix retry policy service-config, make it configurable - #2373
Draft
pkcll wants to merge 1 commit into
Draft
chipingress: fix retry policy service-config, make it configurable#2373pkcll wants to merge 1 commit into
pkcll wants to merge 1 commit into
Conversation
The retry policy passed to grpc.WithDefaultServiceConfig was a bare
retry-policy object, missing the required methodConfig[].retryPolicy
wrapper that gRPC service config requires. gRPC's parser silently
discards unknown top-level fields via plain json.Unmarshal, so the
config parsed to a valid-but-empty result (MethodConfig == nil) with
no error. grpc.NewClient succeeded silently. This client has never
performed a single gRPC-level retry.
Fixes the JSON shape via a typed RetryPolicy struct and a JSON builder
(buildRetryServiceConfigJSON) instead of a hand-written literal, so this
bug class can't recur silently. Adds WithRetryPolicy so callers can
override without hand-writing service-config JSON themselves. Pairs the
retry policy with retryThrottling (10 tokens, 0.1 ratio) so a genuinely
degraded server cannot be amplified by a newly-functioning retry policy.
Verified from source rather than assumed:
- Duration format: grpc-go's internal serviceconfig.Duration requires
protobuf-JSON seconds strings ("0.1s"); the original "100ms" does not
parse. Once methodConfig is correctly nested, an invalid duration now
makes grpc.NewClient return a hard error instead of silently doing
nothing -- confirmed with a test.
- Service name: read from pb.ChipIngress_ServiceDesc.ServiceName at
runtime rather than hardcoding a copy of the string.
- Call sites: only pkg/beholder/client.go and pkg/durableemitter/setup.go
call chipingress.NewClient, both via variadic Opt, so this is
non-breaking; existing callers get the corrected default policy.
The regression test drives the constructed JSON through gRPC's real
service-config parser (via a manual resolver + ClientConn.ParseServiceConfig)
and asserts MethodConfig is actually populated -- a bare "no error"
assertion would not have caught the original bug, since the original bug
never produced an error. Also includes a test proving the old malformed
JSON parses with zero MethodConfig entries, and a test proving "100ms"
is rejected.
Does not address DEADLINE_EXCEEDED failures, and would not have changed
the root cause of a separate incident this fix was found while
investigating -- retries share the caller's deadline, and the dominant
failure mode there had already exhausted it. This closes a chronic,
unrelated data-loss gap: every UNAVAILABLE/RESOURCE_EXHAUSTED failure
that should have retried was instead an immediate permanent drop, on a
path with no persistence.
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The retry policy passed to
grpc.WithDefaultServiceConfiginpkg/chipingress/client.gowas a bareretry-policy object, missing the
methodConfig[].retryPolicywrapper gRPC service config requires.gRPC's parser silently discards unknown top-level fields via plain
json.Unmarshal, so the configparsed to a valid-but-empty result (
MethodConfig == nil) with no error.grpc.NewClientsucceeded silently. This client has never performed a single gRPC-level retry.
RetryPolicystruct and a JSON builder(
buildRetryServiceConfigJSON) instead of a hand-written literal, so this bug class can't recursilently.
WithRetryPolicyso callers can override without hand-writing service-config JSON themselves.retryThrottling(10 tokens, 0.1 ratio) so a genuinely degraded servercannot be amplified by a newly-functioning retry policy.
Verified from source, not assumed
serviceconfig.Durationrequires protobuf-JSON secondsstrings (
"0.1s"); the original"100ms"does not parse. OncemethodConfigis correctlynested, an invalid duration now makes
grpc.NewClientreturn a hard error instead of silentlydoing nothing — confirmed with a test.
pb.ChipIngress_ServiceDesc.ServiceNameat runtime rather thanhardcoding a copy of the string.
pkg/beholder/client.goandpkg/durableemitter/setup.gocallchipingress.NewClient, both via variadicOpt, so this is non-breaking — existing callers getthe corrected default policy.
Regression test
The defining property of this bug is that it produces no error, so a bare "no error" assertion
would not have caught it.
retry_policy_test.godrives the constructed JSON through gRPC's realservice-config parser (manual resolver +
ClientConn.ParseServiceConfig) and assertsMethodConfigis actually populated. Also includes a test proving the old malformed JSON parses with zero
MethodConfigentries, and a test proving"100ms"is rejected.Non-goal
This does not address
DEADLINE_EXCEEDEDfailures and would not have changed the root cause ofa separate production incident found while investigating this — retries share the caller's
deadline, and the dominant failure mode there had already exhausted it. This closes a chronic,
unrelated data-loss gap: every
UNAVAILABLE/RESOURCE_EXHAUSTEDfailure that should have retriedwas instead an immediate permanent drop, on a path with no persistence.
Test plan
go build ./...,go vet ./pkg/chipingress/...,gofmt -lcleanretry_policy_test.gopasspkg/beholder/...full suite passes