Skip to content

Commit 02de363

Browse files
fix(metrics): grpc prometheus stats missing (argoproj#23877) (argoproj#23838)
Signed-off-by: pbhatnagar-oss <[email protected]>
1 parent 79943d8 commit 02de363

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

docs/operator-manual/metrics.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ argocd_cluster_labels{label_environment="production",label_team_name="team3",nam
209209

210210
Metrics about API Server API request and response activity (request totals, response codes, etc...).
211211
Scraped at the `argocd-server-metrics:8083/metrics` endpoint.
212+
For GRPC metrics to show up environment variable ARGOCD_ENABLE_GRPC_TIME_HISTOGRAM must be set to true.
212213

213214
| Metric | Type | Description
214215
|---------------------------------------------------|:---------:|---------------------------------------------------------------------------------------------|
@@ -249,9 +250,11 @@ Scraped at the `argocd-server-metrics:8083/metrics` endpoint.
249250

250251
## Repo Server Metrics
251252

252-
Metrics about the Repo Server.
253+
Metrics about the Repo Server. The gRPC metrics are not exposed by default. Metrics can be enabled using
254+
`ARGOCD_ENABLE_GRPC_TIME_HISTOGRAM=true` environment variable.
253255
Scraped at the `argocd-repo-server:8084/metrics` endpoint.
254256

257+
255258
| Metric | Type | Description |
256259
| --------------------------------------- | :-------: | ------------------------------------------------------------------------- |
257260
| `argocd_git_request_duration_seconds` | histogram | Git requests duration seconds. |

reposerver/metrics/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type MetricsServer struct {
1919
repoPendingRequestsGauge *prometheus.GaugeVec
2020
redisRequestCounter *prometheus.CounterVec
2121
redisRequestHistogram *prometheus.HistogramVec
22+
PrometheusRegistry *prometheus.Registry
2223
}
2324

2425
type GitRequestType string
@@ -108,6 +109,7 @@ func NewMetricsServer() *MetricsServer {
108109
repoPendingRequestsGauge: repoPendingRequestsGauge,
109110
redisRequestCounter: redisRequestCounter,
110111
redisRequestHistogram: redisRequestHistogram,
112+
PrometheusRegistry: registry,
111113
}
112114
}
113115

reposerver/server.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
1010
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
1111
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/recovery"
12-
"github.com/prometheus/client_golang/prometheus"
1312
log "github.com/sirupsen/logrus"
1413
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
1514
"google.golang.org/grpc"
@@ -63,8 +62,7 @@ func NewServer(metricsServer *metrics.MetricsServer, cache *reposervercache.Cach
6362
serverMetricsOptions = append(serverMetricsOptions, grpc_prometheus.WithServerHandlingTimeHistogram())
6463
}
6564
serverMetrics := grpc_prometheus.NewServerMetrics(serverMetricsOptions...)
66-
reg := prometheus.NewRegistry()
67-
reg.MustRegister(serverMetrics)
65+
metricsServer.PrometheusRegistry.MustRegister(serverMetrics)
6866

6967
serverLog := log.NewEntry(log.StandardLogger())
7068
streamInterceptors := []grpc.StreamServerInterceptor{

server/metrics/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type MetricsServer struct {
2121
extensionRequestCounter *prometheus.CounterVec
2222
extensionRequestDuration *prometheus.HistogramVec
2323
loginRequestCounter *prometheus.CounterVec
24+
PrometheusRegistry *prometheus.Registry
2425
}
2526

2627
var (
@@ -102,6 +103,7 @@ func NewMetricsServer(host string, port int) *MetricsServer {
102103
extensionRequestCounter: extensionRequestCounter,
103104
extensionRequestDuration: extensionRequestDuration,
104105
loginRequestCounter: loginRequestCounter,
106+
PrometheusRegistry: registry,
105107
}
106108
}
107109

server/server.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ func (server *ArgoCDServer) Run(ctx context.Context, listeners *Listeners) {
561561
server.Shutdown()
562562
}
563563
}()
564-
565564
metricsServ := metrics.NewMetricsServer(server.MetricsHost, server.MetricsPort)
566565
if server.RedisClient != nil {
567566
cacheutil.CollectMetrics(server.RedisClient, metricsServ, server.userStateStorage.GetLockObject())
@@ -576,7 +575,7 @@ func (server *ArgoCDServer) Run(ctx context.Context, listeners *Listeners) {
576575
server.sessionMgr.CollectMetrics(metricsServ)
577576
}
578577
server.serviceSet = svcSet
579-
grpcS, appResourceTreeFn := server.newGRPCServer()
578+
grpcS, appResourceTreeFn := server.newGRPCServer(metricsServ.PrometheusRegistry)
580579
grpcWebS := grpcweb.WrapServer(grpcS)
581580
var httpS *http.Server
582581
var httpsS *http.Server
@@ -899,14 +898,13 @@ func (server *ArgoCDServer) useTLS() bool {
899898
return true
900899
}
901900

902-
func (server *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResourceTreeFn) {
901+
func (server *ArgoCDServer) newGRPCServer(prometheusRegistry *prometheus.Registry) (*grpc.Server, application.AppResourceTreeFn) {
903902
var serverMetricsOptions []grpc_prometheus.ServerMetricsOption
904903
if enableGRPCTimeHistogram {
905904
serverMetricsOptions = append(serverMetricsOptions, grpc_prometheus.WithServerHandlingTimeHistogram())
906905
}
907906
serverMetrics := grpc_prometheus.NewServerMetrics(serverMetricsOptions...)
908-
reg := prometheus.NewRegistry()
909-
reg.MustRegister(serverMetrics)
907+
prometheusRegistry.MustRegister(serverMetrics)
910908

911909
sOpts := []grpc.ServerOption{
912910
// Set the both send and receive the bytes limit to be 100MB
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,6 @@ func TestKubectlMetrics(t *testing.T) {
103103
assert.Contains(t, string(body), "argocd_kubectl_response_size_bytes", "metrics should have contained argocd_kubectl_response_size_bytes")
104104
assert.Contains(t, string(body), "argocd_kubectl_rate_limiter_duration_seconds", "metrics should have contained argocd_kubectl_rate_limiter_duration_seconds")
105105
assert.Contains(t, string(body), "argocd_kubectl_requests_total", "metrics should have contained argocd_kubectl_requests_total")
106+
assert.Contains(t, string(body), "grpc_server_handled_total", "metrics should have contained grpc_server_handled_total for all the reflected methods")
107+
assert.Contains(t, string(body), "grpc_server_msg_received_total", "metrics should have contained grpc_server_msg_received_total for all the reflected methods")
106108
}

0 commit comments

Comments
 (0)