-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add List method to gRPC Health service #8155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This change introduces a new `List` RPC endpoint for the Health service, allowing clients to retrieve the statuses of all monitored services. This feature simplifies integration with status-reporting dashboards and enhances observability for microservices. Proposal: grpc/proposal#468 gRPC-proto change: grpc/grpc-proto#143 Signed-off-by: Marcos Huck <marcos@huck.com.ar>
health/grpc_health_v1/health.pb.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I regenerated the Go stubs using the work in progress version of grpc/grpc-proto#143
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I regenerated the Go stubs using the work in progress version of grpc/grpc-proto#143
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8155 +/- ##
==========================================
- Coverage 82.09% 82.02% -0.07%
==========================================
Files 412 412
Lines 40491 40503 +12
==========================================
- Hits 33242 33224 -18
- Misses 5876 5896 +20
- Partials 1373 1383 +10
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcoshuck i think we need to wait for the proposal and proto change to be merged before this? I still see them in review
@dfawley cc
Signed-off-by: Marcos Huck <marcos@huck.com.ar>
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
Signed-off-by: Marcos Huck <marcos@huck.com.ar>
Co-authored-by: Purnesh Dixit <purnesh.dixit92@gmail.com>
Signed-off-by: Marcos Huck <marcos@huck.com.ar>
@marcoshuck could you resolve the merge conflicts? |
health/server_internal_test.go
Outdated
} | ||
} | ||
|
||
// TestListResourceExhausted verifies that the service status list returns an error when it exceeds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: restrict the comments to 80 cols
Signed-off-by: Marcos Huck <marcos@huck.com.ar>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Please wrap comments under 80 cols per line.
@@ -30,6 +30,12 @@ import ( | |||
"google.golang.org/grpc/status" | |||
) | |||
|
|||
const ( | |||
// maxAllowedServices defines the maximum number of resources a List operation can return. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wrap comments to 80 cols per line.
if len(out.GetStatuses()) != len(s.statusMap) { | ||
t.Fatalf("len(out.GetStatuses()) = %d, want %d", len(out.GetStatuses()), len(s.statusMap)) | ||
} | ||
for key := range out.GetStatuses() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for k, v := range out.GetStatuses()
then don't need line 115
t.Fatalf("s.List(ctx, &in) return nil error, want non-nil") | ||
} | ||
if !errors.Is(err, status.Errorf(codes.ResourceExhausted, "server health list exceeds maximum capacity: %d", maxAllowedServices)) { | ||
t.Fatal("List should have failed with resource exhausted") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Fatal("List should have failed with resource exhausted") | |
t.Fatal("s.List() = %v, want %v, err, status.Errorf(codes.ResourceExhausted, "server health list exceeds maximum capacity: %d", maxAllowedServices)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: don't spell status.Errorf....
twice. Assign to a want
instead.
Could you run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some comments about the tests. Otherwise LGTM, thanks!
// Remove the zero value | ||
delete(s.statusMap, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
delete(s.statusMap, "") | ||
// Fill out status map with information | ||
for i := 1; i <= 3; i++ { | ||
s.statusMap[fmt.Sprintf("%d", i)] = healthpb.HealthCheckResponse_SERVING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this use s.SetServingStatus
instead, if possible?
if err != nil { | ||
t.Fatalf("s.List(ctx, &in) returned err %v, want nil", err) | ||
} | ||
if len(out.GetStatuses()) != len(s.statusMap) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why len(s.statusMap)
? We added 3 things, so we should know it's 3?
for key := range out.GetStatuses() { | ||
v, ok := s.statusMap[key] | ||
if !ok { | ||
t.Fatalf("key %s does not exist in s.statusMap", key) | ||
} | ||
if v != healthpb.HealthCheckResponse_SERVING { | ||
t.Fatalf("%s returned status %d, want %d", key, healthpb.HealthCheckResponse_SERVING, v) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace this with something that confirms it is what we expect it to be statically, not what exists in s.statusMap
dynamically. I.e.
want := healthpb.HealthListRequest{
Statuses: map[string]*healthpb.HealthCheckResponse{
"1": healthpb.HealthCheckResponse_SERVING.Enum(), // etc
}
}
if diff := cmp.Diff(got, want); diff != "" {
t.Fatalf("....: %s", diff)
}
// Remove the zero value | ||
delete(s.statusMap, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above?
for i := 1; i <= maxAllowedServices+1; i++ { | ||
s.statusMap[fmt.Sprintf("%d", i)] = healthpb.HealthCheckResponse_SERVING | ||
} | ||
s.mu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also as above: please use s.SetServingStatus
if err == nil { | ||
t.Fatalf("s.List(ctx, &in) return nil error, want non-nil") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary since you check the error code next anyway.
t.Fatalf("s.List(ctx, &in) return nil error, want non-nil") | ||
} | ||
if !errors.Is(err, status.Errorf(codes.ResourceExhausted, "server health list exceeds maximum capacity: %d", maxAllowedServices)) { | ||
t.Fatal("List should have failed with resource exhausted") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: don't spell status.Errorf....
twice. Assign to a want
instead.
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
This change introduces a new
List
RPC endpoint for the Health service, allowing clients to retrieve the statuses of all monitored services. This feature simplifies integration with status-reporting dashboards and enhances observability for microservices.Proposal: grpc/proposal#468
gRPC-proto change: grpc/grpc-proto#143