grpc: put grpcwebui behind environment variable (#56314)

This commit is contained in:
Geoffrey Gilmore 2023-08-31 07:13:16 -07:00 committed by GitHub
parent 23ad498c62
commit 3cb0b12b11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -6,12 +6,15 @@ import (
"github.com/fullstorydev/grpcui/standalone"
"github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/internal/env"
"google.golang.org/grpc"
"github.com/sourcegraph/sourcegraph/internal/grpc/defaults"
"github.com/sourcegraph/sourcegraph/lib/errors"
)
var envEnableGRPCWebUI = env.MustGetBool("GRPC_WEB_UI_ENABLED", false, "Enable the gRPC Web UI to debug and explore gRPC services")
const gRPCWebUIPath = "/debug/grpcui"
// NewGRPCWebUIEndpoint returns a new Endpoint that serves a gRPC Web UI instance
@ -50,6 +53,11 @@ type grpcHandler struct {
}
func (g *grpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !envEnableGRPCWebUI {
http.Error(w, "gRPC Web UI is disabled", http.StatusNotFound)
return
}
ctx := r.Context()
cc, err := grpc.DialContext(ctx, g.target, g.dialOpts...)

View File

@ -119,6 +119,9 @@ env:
# OTEL_EXPORTER_OTLP_ENDPOINT: http://127.0.0.1:4318
# OTEL_EXPORTER_OTLP_PROTOCOL: http/json
# Enable gRPC Web UI for debugging
GRPC_WEB_UI_ENABLED: "true"
# Enable full protobuf message logging when an internal error occurred
SRC_GRPC_INTERNAL_ERROR_LOGGING_LOG_PROTOBUF_MESSAGES_ENABLED: "true"
SRC_GRPC_INTERNAL_ERROR_LOGGING_LOG_PROTOBUF_MESSAGES_JSON_TRUNCATION_SIZE_BYTES: "1KB"