Skip to content

Feature/grpc healthcheck #4853

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

Merged
merged 5 commits into from
Jul 25, 2025
Merged

Conversation

tbourrely
Copy link
Contributor

@tbourrely tbourrely commented Jun 15, 2025

What?

Add a healthcheck method to gRPC JS client.

Why?

Remove invoke boilerplate as specified in #3428

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Related PR(s)/Issue(s)

Closes #3428

@tbourrely tbourrely requested a review from a team as a code owner June 15, 2025 23:05
@tbourrely tbourrely requested review from ankur22 and codebien and removed request for a team June 15, 2025 23:05
@tbourrely
Copy link
Contributor Author

Hello 👋

I would like some feedback on the changes related to issue #3428.
Please let me know if I'm going in the wrong direction.

Cheers !

@joanlopez joanlopez added this to the v1.2.0 milestone Jun 16, 2025
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tbourrely,
this is a great start! The general architecture seems fine to me. I've spotted a few details in comments. However, the unique major missing point is a unit test for the JavaScript API. You can find them here https://github.com/grafana/k6/blob/master/internal/js/modules/k6/grpc/client_test.go

export default () => {
client.connect(GRPC_ADDR, { plaintext: true });

const response = client.healthcheck("")
Copy link
Contributor

@codebien codebien Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const response = client.healthcheck("")
const response = client.healthcheck()

I would prefer if we support null instead of empty string for the default case.

export default () => {
client.connect(GRPC_ADDR, { plaintext: true });

const response = client.healthcheck("")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const response = client.healthcheck("")
const response = client.healthCheck("")

I see you've originally proposed this name, that resonates with me because it matches the namespace of the API. Did you encounter any obstacle with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none at all :)

@@ -278,6 +278,11 @@ func (c *Client) Connect(addr string, params sobek.Value) (bool, error) {
return true, err
}

// Healthcheck runs healtcheck
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Healthcheck runs healtcheck
// Healthcheck checks if the server side is up and ready to serve responses.

@@ -86,6 +91,11 @@ func (mi *ModuleInstance) defineConstants() {
mustAddCode("StatusUnavailable", codes.Unavailable)
mustAddCode("StatusDataLoss", codes.DataLoss)
mustAddCode("StatusUnauthenticated", codes.Unauthenticated)

mustAddServingStatus("HealthcheckUnknown", healthpb.HealthCheckResponse_UNKNOWN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mustAddServingStatus("HealthcheckUnknown", healthpb.HealthCheckResponse_UNKNOWN)
mustAddServingStatus("HealthCheckUnknown", healthpb.HealthCheckResponse_UNKNOWN)

It seems consistent with the current API. What is the case used on JavaScript-grpc library?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HealthCheck is more consistent with the current method.

panic("not implemented")
}

func TestHealthcheck(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestHealthcheck(t *testing.T) {
func TestHealthCheckServing(t *testing.T) {

We are missing a not serving case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ive also added the unknown case

@tbourrely tbourrely force-pushed the feature/grpc-healthcheck branch from 05f2d36 to 225969a Compare June 20, 2025 15:34
@tbourrely
Copy link
Contributor Author

Thanks for the review @codebien 👍
I'll address the js test concerns asap !

@tbourrely
Copy link
Contributor Author

I've added the JS client tests.
I was unsure whether i should put the healthcheck server on the HTTPMultiBin struct or not 🤔

google.golang.org/genproto/googleapis/rpc/errdetails
google.golang.org/genproto/googleapis/rpc/status
# google.golang.org/grpc v1.72.1
## explicit; go 1.23
# google.golang.org/grpc v1.73.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't happen here, can you rollback it, please? If this is a requirement, then we need a dedicated pull request for it.

@@ -86,6 +91,11 @@ func (mi *ModuleInstance) defineConstants() {
mustAddCode("StatusUnavailable", codes.Unavailable)
mustAddCode("StatusDataLoss", codes.DataLoss)
mustAddCode("StatusUnauthenticated", codes.Unauthenticated)

mustAddServingStatus("HealthcheckUnknown", healthpb.HealthCheckResponse_UNKNOWN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HealthCheck is more consistent with the current method.

return nil
}
c := Conn{raw: healthcheckmock(healthReply)}
res, err := c.HealthCheck(context.Background(), "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
res, err := c.HealthCheck(context.Background(), "")
res, err := c.HealthCheck(context.Background(), "HERE-SERVICE")

We're missing a case where we test a specific service

@codebien
Copy link
Contributor

@tbourrely can you rebase and resolve the conflicts, please?

@tbourrely tbourrely force-pushed the feature/grpc-healthcheck branch from 886dc73 to ca96658 Compare June 26, 2025 23:20
@tbourrely tbourrely closed this Jun 26, 2025
@tbourrely tbourrely force-pushed the feature/grpc-healthcheck branch from ca96658 to 0e3fb95 Compare June 26, 2025 23:21
@tbourrely tbourrely reopened this Jun 26, 2025
@tbourrely tbourrely force-pushed the feature/grpc-healthcheck branch from 68ec422 to b054618 Compare July 5, 2025 20:39
@tbourrely tbourrely force-pushed the feature/grpc-healthcheck branch from b054618 to 129be31 Compare July 5, 2025 20:40
@codebien codebien self-requested a review July 15, 2025 13:55
Copy link
Contributor

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@codebien codebien mentioned this pull request Jul 22, 2025
8 tasks
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉 @tbourrely thanks for the contribution 🙇

As soon as we have resolved the linter issue, we're working internally on it, we will merge this pull request.

@codebien codebien merged commit 602467d into grafana:master Jul 25, 2025
47 of 48 checks passed
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.

gRPC HealthV1 support without .proto files
4 participants