-
Notifications
You must be signed in to change notification settings - Fork 4k
rpc, server: add DRPC metrics server interceptor #153651
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,15 @@ | |
|
|
||
| package server | ||
|
|
||
| import "sync/atomic" | ||
| import ( | ||
| "strings" | ||
| "sync/atomic" | ||
|
|
||
| "github.com/cockroachdb/cockroach/pkg/settings" | ||
| "github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
| "google.golang.org/grpc/codes" | ||
| grpcstatus "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| type serveModeHandler struct { | ||
| mode serveMode | ||
|
|
@@ -61,3 +69,33 @@ func (s *serveMode) set(mode serveMode) { | |
| func (s *serveMode) get() serveMode { | ||
| return serveMode(atomic.LoadInt32((*int32)(s))) | ||
| } | ||
|
|
||
| const ( | ||
| serverPrefix = "/cockroach.server" | ||
| tsdbPrefix = "/cockroach.ts" | ||
| ) | ||
|
|
||
| // serverRPCRequestMetricsEnabled is a cluster setting that enables the | ||
| // collection of gRPC and DRPC request duration metrics. This uses export only | ||
| // metrics so the metrics are only exported to external sources such as | ||
| // /_status/vars and DataDog. | ||
| var serverRPCRequestMetricsEnabled = settings.RegisterBoolSetting( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok will update this doc accordingly. |
||
| settings.ApplicationLevel, | ||
| "server.rpc.request_metrics.enabled", | ||
| "enables the collection of rpc metrics", | ||
| false, /* defaultValue */ | ||
| settings.WithRetiredName("server.grpc.request_metrics.enabled"), | ||
| ) | ||
|
|
||
| func shouldRecordRequestDuration(settings *cluster.Settings, method string) bool { | ||
| return serverRPCRequestMetricsEnabled.Get(&settings.SV) && | ||
| (strings.HasPrefix(method, serverPrefix) || | ||
| strings.HasPrefix(method, tsdbPrefix)) | ||
| } | ||
|
|
||
| // NewWaitingForInitError creates an error indicating that the server cannot run | ||
| // the specified method until the node has been initialized. | ||
| func NewWaitingForInitError(methodName string) error { | ||
| // NB: this error string is sadly matched in grpcutil.IsWaitingForInit(). | ||
| return grpcstatus.Errorf(codes.Unavailable, "node waiting for init; %s not available", methodName) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.