feat(metric): adds accepted/closed connections counters to worker and controller servers (#2668)

* adds counters and changelog entry
This commit is contained in:
Haotian authored and GitHub committed 2022-12-06 10:13:44 -08:00
1 parent 2d90dc2c97
commit fbd0a8272b
10 files changed
+385 -16

No files matched your search

@@ -2,6 +2,7 @@ package metric
import (
"context"
"net"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/daemon/metric"
@@ -12,7 +13,7 @@ import (
)
const (
clusterSubSystem = "controller_cluster"
clusterSubsystem = "controller_cluster"
)
// Because we use grpc's stats.Handler to track close-to-the-wire server-side communication over grpc,
@@ -25,7 +26,7 @@ const (
var grpcRequestLatency prometheus.ObserverVec = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: globals.MetricNamespace,
Subsystem: clusterSubSystem,
Subsystem: clusterSubsystem,
Name: "grpc_request_duration_seconds",
Help: "Histogram of latencies for gRPC requests.",
Buckets: prometheus.DefBuckets,
@@ -33,6 +34,28 @@ var grpcRequestLatency prometheus.ObserverVec = prometheus.NewHistogramVec(
metric.ListGrpcLabels,
)
// acceptedConnsTotal keeps a count of the total accepted connections to a controller.
var acceptedConnsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: globals.MetricNamespace,
Subsystem: clusterSubsystem,
Name: "accepted_connections_total",
Help: "Count of total accepted network connections to this controller.",
},
[]string{metric.LabelConnectionType},
)
// closedConnsTotal keeps a count of the total closed connections to a controller.
var closedConnsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: globals.MetricNamespace,
Subsystem: clusterSubsystem,
Name: "closed_connections_total",
Help: "Count of total closed network connections to this controller.",
},
[]string{metric.LabelConnectionType},
)
// All the codes expected to be returned by boundary or the grpc framework to
// requests to the cluster server.
var expectedGrpcCodes = []codes.Code{
@@ -45,6 +68,11 @@ var expectedGrpcCodes = []codes.Code{
codes.Unavailable, codes.Unauthenticated,
}
func InstrumentClusterTrackingListener(l net.Listener, purpose string) net.Listener {
p := prometheus.Labels{metric.LabelConnectionType: purpose}
return metric.NewConnectionTrackingListener(l, acceptedConnsTotal.With(p), closedConnsTotal.With(p))
}
// InstrumentClusterStatsHandler returns a gRPC stats.Handler which observes
// cluster specific metrics. Use with the cluster gRPC server.
func InstrumentClusterStatsHandler(ctx context.Context) (stats.Handler, error) {
@@ -57,3 +85,7 @@ func InstrumentClusterStatsHandler(ctx context.Context) (stats.Handler, error) {
func InitializeClusterCollectors(r prometheus.Registerer, server *grpc.Server) {
metric.InitializeGrpcCollectorsFromServer(r, grpcRequestLatency, server, expectedGrpcCodes)
}
func InitializeConnectionCounters(r prometheus.Registerer) {
metric.InitializeConnectionCounters(r, []prometheus.CounterVec{*acceptedConnsTotal, *closedConnsTotal})
}