generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
353 changed files
with
73,374 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package metrics | ||
|
||
import ( | ||
"sync" | ||
|
||
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"google.golang.org/grpc" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
) | ||
|
||
var ( | ||
// metricsList is a list of all raw metrics that should be registered always, regardless of any feature gate's value. | ||
metricsList []prometheus.Collector | ||
grpcServerMetrics *grpcprom.ServerMetrics | ||
registerMetrics sync.Once | ||
) | ||
|
||
func initMetrics() { | ||
grpcServerMetrics = grpcprom.NewServerMetrics( | ||
grpcprom.WithServerHandlingTimeHistogram( | ||
grpcprom.WithHistogramBuckets([]float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120}), | ||
), | ||
) | ||
|
||
metricsList = []prometheus.Collector{ | ||
grpcServerMetrics, | ||
} | ||
} | ||
|
||
// Register registers a list of metrics. | ||
func Register() { | ||
registerMetrics.Do(func() { | ||
initMetrics() | ||
for _, metric := range metricsList { | ||
legacyregistry.RawMustRegister(metric) | ||
} | ||
}) | ||
} | ||
|
||
func GRPCMetricsOptions() []grpc.ServerOption { | ||
return []grpc.ServerOption{ | ||
grpc.ChainUnaryInterceptor( | ||
grpcServerMetrics.UnaryServerInterceptor(), | ||
), | ||
grpc.ChainStreamInterceptor( | ||
grpcServerMetrics.StreamServerInterceptor(), | ||
), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.