Add the user rpc counter (#22872)

Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
SimFG 2023-03-21 11:37:56 +08:00 committed by GitHub
parent 28f8dc89e5
commit 8259ca6929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -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.

View File

@ -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 {