-
Notifications
You must be signed in to change notification settings - Fork 4.6k
internal/stats: Add metrics recorder list and usage in ClientConn #7428
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 2 commits
dc37567
6c69fc7
e410855
b9fedbf
619b20e
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 |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * Copyright 2024 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package stats | ||
|
|
||
| import ( | ||
| estats "google.golang.org/grpc/experimental/stats" | ||
| "google.golang.org/grpc/grpclog" | ||
| "google.golang.org/grpc/stats" | ||
| ) | ||
|
|
||
| var logger = grpclog.Component("metrics-recorder-list") | ||
|
|
||
| // MetricsRecorderList forwards Record calls to all of it's metricsRecorders. | ||
| // | ||
| // It eats any record calls where the label values provided do not match the | ||
| // number of label keys. | ||
| type MetricsRecorderList struct { | ||
| // metricsRecorders are the metrics recorders this list will forward to. | ||
| metricsRecorders []estats.MetricsRecorder | ||
| } | ||
|
|
||
| // NewMetricsRecorderList creates a new metric recorder list with all the stats | ||
| // handlers provided which implement the MetricsRecorder interface. | ||
| // If no stats handlers provided implement the MetricsRecorder interface, | ||
| // the MetricsRecorder list returned is a no-op. | ||
| func NewMetricsRecorderList(shs []stats.Handler) *MetricsRecorderList { | ||
| var mrs []estats.MetricsRecorder | ||
| for _, sh := range shs { | ||
| if mr, ok := sh.(estats.MetricsRecorder); ok { | ||
| mrs = append(mrs, mr) | ||
| } | ||
| } | ||
| return &MetricsRecorderList{ | ||
| metricsRecorders: mrs, | ||
| } | ||
| } | ||
|
|
||
| func verifyLabels(labels []string, optionalLabels []string, labelsRecv ...string) { | ||
dfawley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if got, want := len(labelsRecv), len(labels)+len(optionalLabels); got != want { | ||
| logger.Fatalf("Length of labels passed to Record incorrect, got: %v, want: %v.", got, want) | ||
|
||
| } | ||
| } | ||
|
|
||
| func (l *MetricsRecorderList) RecordInt64Count(handle *estats.Int64CountHandle, incr int64, labels ...string) { | ||
| verifyLabels(handle.Labels, handle.OptionalLabels, labels...) | ||
|
|
||
| for _, metricRecorder := range l.metricsRecorders { | ||
| metricRecorder.RecordInt64Count(handle, incr, labels...) | ||
| } | ||
| } | ||
|
|
||
| func (l *MetricsRecorderList) RecordFloat64Count(handle *estats.Float64CountHandle, incr float64, labels ...string) { | ||
| verifyLabels(handle.Labels, handle.OptionalLabels, labels...) | ||
|
|
||
| for _, metricRecorder := range l.metricsRecorders { | ||
| metricRecorder.RecordFloat64Count(handle, incr, labels...) | ||
| } | ||
| } | ||
|
|
||
| func (l *MetricsRecorderList) RecordInt64Histo(handle *estats.Int64HistoHandle, incr int64, labels ...string) { | ||
| verifyLabels(handle.Labels, handle.OptionalLabels, labels...) | ||
|
|
||
| for _, metricRecorder := range l.metricsRecorders { | ||
| metricRecorder.RecordInt64Histo(handle, incr, labels...) | ||
| } | ||
| } | ||
|
|
||
| func (l *MetricsRecorderList) RecordFloat64Histo(handle *estats.Float64HistoHandle, incr float64, labels ...string) { | ||
| verifyLabels(handle.Labels, handle.OptionalLabels, labels...) | ||
|
|
||
| for _, metricRecorder := range l.metricsRecorders { | ||
| metricRecorder.RecordFloat64Histo(handle, incr, labels...) | ||
| } | ||
| } | ||
|
|
||
| func (l *MetricsRecorderList) RecordInt64Gauge(handle *estats.Int64GaugeHandle, incr int64, labels ...string) { | ||
| verifyLabels(handle.Labels, handle.OptionalLabels, labels...) | ||
|
|
||
| for _, metricRecorder := range l.metricsRecorders { | ||
| metricRecorder.RecordInt64Gauge(handle, incr, labels...) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.