From 8259ca69295c76394d33abe628b50a2d46eea8db Mon Sep 17 00:00:00 2001 From: SimFG Date: Tue, 21 Mar 2023 11:37:56 +0800 Subject: [PATCH] Add the user rpc counter (#22872) Signed-off-by: SimFG --- internal/metrics/proxy_metrics.go | 9 +++++++++ internal/proxy/authentication_interceptor.go | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/internal/metrics/proxy_metrics.go b/internal/metrics/proxy_metrics.go index 2887fb38b2..cd0ffaf0fc 100644 --- a/internal/metrics/proxy_metrics.go +++ b/internal/metrics/proxy_metrics.go @@ -232,6 +232,14 @@ var ( Name: "hook_func_count", Help: "the hook function count", }, []string{functionLabelName, fullMethodLabelName}) + + UserRPCCounter = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: milvusNamespace, + Subsystem: typeutil.ProxyRole, + Name: "user_rpc_count", + Help: "the rpc count of a user", + }, []string{usernameLabelName}) ) // RegisterProxy registers Proxy metrics @@ -267,6 +275,7 @@ func RegisterProxy(registry *prometheus.Registry) { registry.MustRegister(ProxyLimiterRate) registry.MustRegister(ProxyHookFunc) + registry.MustRegister(UserRPCCounter) } // SetRateGaugeByRateType sets ProxyLimiterRate metrics. diff --git a/internal/proxy/authentication_interceptor.go b/internal/proxy/authentication_interceptor.go index 73131b1367..8aa8b754fd 100644 --- a/internal/proxy/authentication_interceptor.go +++ b/internal/proxy/authentication_interceptor.go @@ -4,11 +4,10 @@ import ( "context" "strings" - "google.golang.org/grpc/metadata" - + "github.com/milvus-io/milvus/internal/metrics" "github.com/milvus-io/milvus/internal/util" - "github.com/milvus-io/milvus/internal/util/crypto" + "google.golang.org/grpc/metadata" ) // validAuth validates the authentication @@ -27,8 +26,11 @@ func validAuth(ctx context.Context, authorization []string) bool { secrets := strings.SplitN(rawToken, util.CredentialSeperator, 2) username := secrets[0] password := secrets[1] - - return passwordVerify(ctx, username, password, globalMetaCache) + isSuccess := passwordVerify(ctx, username, password, globalMetaCache) + if isSuccess { + metrics.UserRPCCounter.WithLabelValues(username).Inc() + } + return isSuccess } func validSourceID(ctx context.Context, authorization []string) bool {