Skip to content
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

add gRPC health check #8397

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/grpc-healthcheck.yaml
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: configgrpc

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: gRPC servers now have the option to register the standard grpc.health.v1.Health healthcheck service.

# One or more tracking issues or pull requests related to the change
issues: [3040]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
1 change: 1 addition & 0 deletions config/configgrpc/README.md
Expand Up @@ -110,4 +110,5 @@ see [confignet README](../confignet/README.md).
- [`read_buffer_size`](https://godoc.org/google.golang.org/grpc#ReadBufferSize)
- [`tls`](../configtls/README.md)
- [`write_buffer_size`](https://godoc.org/google.golang.org/grpc#WriteBufferSize)
- [`healthcheck`](https://github.com/grpc/grpc/blob/master/doc/health-checking.md): registers the health check service
- [`auth`](../configauth/README.md)
13 changes: 12 additions & 1 deletion config/configgrpc/configgrpc.go
Expand Up @@ -21,6 +21,8 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"
Expand Down Expand Up @@ -143,6 +145,10 @@ type GRPCServerSettings struct {
// Keepalive anchor for all the settings related to keepalive.
Keepalive *KeepaliveServerConfig `mapstructure:"keepalive"`

// HealthCheck service for the gRPC server. See gRPC health checking.
// (https://github.com/grpc/grpc/blob/master/doc/health-checking.md)
HealthCheck bool `mapstructure:"healthcheck"`

// Auth for this receiver
Auth *configauth.Authentication `mapstructure:"auth"`

Expand Down Expand Up @@ -280,7 +286,12 @@ func (gss *GRPCServerSettings) ToServer(host component.Host, settings component.
return nil, err
}
opts = append(opts, extraOpts...)
return grpc.NewServer(opts...), nil
grpcServer := grpc.NewServer(opts...)
if gss.HealthCheck {
healthServer := health.NewServer()
grpc_health_v1.RegisterHealthServer(grpcServer, healthServer)
}
return grpcServer, nil
}

func (gss *GRPCServerSettings) toServerOption(host component.Host, settings component.TelemetrySettings) ([]grpc.ServerOption, error) {
Expand Down
16 changes: 15 additions & 1 deletion config/configgrpc/configgrpc_test.go
Expand Up @@ -19,6 +19,7 @@ import (
"go.uber.org/zap/zaptest/observer"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"

Expand Down Expand Up @@ -236,6 +237,20 @@ func TestGrpcServerAuthSettings(t *testing.T) {
assert.NotNil(t, srv)
}

func TestGrpcHealthCheck(t *testing.T) {
gss := &GRPCServerSettings{
NetAddr: confignet.NetAddr{
Endpoint: "localhost:1234",
Transport: "tcp",
},
HealthCheck: true,
}
gsvr, err := gss.ToServer(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings())
assert.NoError(t, err)
info := gsvr.GetServiceInfo()[grpc_health_v1.Health_ServiceDesc.ServiceName]
assert.Len(t, info.Methods, 2) // assert the 2 grpc health check endpoints were registered
}

func TestGRPCClientSettingsError(t *testing.T) {
tt, err := obsreporttest.SetupTelemetry(component.NewID("component"))
require.NoError(t, err)
Expand Down Expand Up @@ -424,7 +439,6 @@ func TestGRPCServerWarning(t *testing.T) {
require.Len(t, observed.FilterLevelExact(zap.WarnLevel).All(), test.len)
})
}

}

func TestGRPCServerSettingsError(t *testing.T) {
Expand Down