Skip to content

fix: listener race condition, cleanup metrics - #901

Open
senthilsam wants to merge 1 commit into
openconfig:mainfrom
senthilsam:feat/emit-rpc-message-as-metric
Open

fix: listener race condition, cleanup metrics#901
senthilsam wants to merge 1 commit into
openconfig:mainfrom
senthilsam:feat/emit-rpc-message-as-metric

Conversation

@senthilsam

Copy link
Copy Markdown
Contributor

Fixed:

  • Target listener getting stuck during a race condition
    Introduces uuid as an internal identifier for a target, so even if we remove and add quickly each time it will generate a new id, and we wil never end up gettign listener struck due to name

  • Clean target metrics when it's removed

  • Introduces gnmic_target_grpc_status_code gauge (app + collector paths) and registers it with the relevant registries.

  • Updates target subscription loops to set the metric to OK (0) on successful responses and to a non-OK code on subscription errors (when available).

  • Ensures the new per-target metric series is deleted when a target is removed.
    Metric Output:

Positive case


# HELP gnmic_target_grpc_status_code The last gRPC status code received from the target. Default is 2 (Unknown) until the first response is received. See https://pkg.go.dev/google.golang.org/grpc/codes. Values: 0=OK, 1=Canceled, 2=Unknown, 3=InvalidArgument, 4=DeadlineExceeded, 5=NotFound, 6=AlreadyExists, 7=PermissionDenied, 8=ResourceExhausted, 9=FailedPrecondition, 10=Aborted, 11=OutOfRange, 12=Unimplemented, 13=Internal, 14=Unavailable, 15=DataLoss, 16=Unauthenticated.
# TYPE gnmic_target_grpc_status_code gauge
gnmic_target_grpc_status_code{name="test-sim-amps-device-1"} 0

During authentication error:

gnmic log
time=2026-07-22T09:33:39.375+05:30 level=INFO msg="subscription receive error" target=test.device.net subscription=test-sample-5m err="rpc error: code = Unauthenticated desc = Authentication has failed"
Generated metric


# HELP gnmic_target_grpc_status_code The last gRPC status code received from the target. Default is 2 (Unknown) until the first response is received. See https://pkg.go.dev/google.golang.org/grpc/codes. Values: 0=OK, 1=Canceled, 2=Unknown, 3=InvalidArgument, 4=DeadlineExceeded, 5=NotFound, 6=AlreadyExists, 7=PermissionDenied, 8=ResourceExhausted, 9=FailedPrecondition, 10=Aborted, 11=OutOfRange, 12=Unimplemented, 13=Internal, 14=Unavailable, 15=DataLoss, 16=Unauthenticated.
# TYPE gnmic_target_grpc_status_code gauge
gnmic_target_grpc_status_code{name="test.device.net"} 16

@senthilsam
senthilsam force-pushed the feat/emit-rpc-message-as-metric branch from cc470f9 to 59122b6 Compare July 31, 2026 14:39
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.

1 participant