mirror of
https://github.com/milvus-io/milvus.git
synced 2026-07-21 10:15:43 +00:00
issue: #51493 ### What #50221 split the `status` label values of `milvus_proxy_req_count` / `milvus_proxy_grpc_latency` in place. Released in **v2.6.19**, that silently zeroes every existing dashboard panel and alert rule matching `status="fail"` / `status="rejected"` — an alert that stops firing rather than erroring. This keeps the classification but moves it onto its own dimension, restoring the status domain to what <= v2.6.18 emitted: ``` status: success | fail | rejected | retry | total | abandon (as before v2.6.19) cause: user | system | cancel | na (new) ``` | v2.6.19 / v2.6.20 | this PR | |---|---| | `status="fail_input"` | `status="fail", cause="user"` | | `status="fail_system"` | `status="fail", cause="system"` | | `status="rejected_user"` | `status="rejected", cause="user"` | | `status="rejected_system"` | `status="rejected", cause="system"` | | `status="cancel"` | `status="fail"` or `"rejected"`, `cause="cancel"` | | `success` / `retry` / `total` / `abandon` | unchanged, `cause="na"` | ### Why a label instead of new status values - **Old queries work unchanged and count each request once.** `status="fail"` is again every hard failure; Prometheus aggregates over `cause` for free. That rollup is what a label dimension *is* — the split forces every consumer who just wants "how many failures" to hand-write `status=~"fail_.*"`. - **Cardinality is unchanged.** `cause` is functionally dependent on the outcome, so the realized `(status, cause)` pairs are exactly the series the split already produces. Additive, not multiplicative. - **New consumers lose nothing**: alert on `status="fail", cause="system"`; route `cause="user"` to the owning application team. The alternative — emitting old and new `status` values side by side during a transition — was rejected: it defers the break rather than removing it (the old values must still be dropped eventually, forcing the same migration later), and meanwhile double-counts every request in unfiltered aggregations. `cancel` is folded into `cause` for the same reason: before v2.6.19 client cancellations were counted as `fail` (cancel in the response status) or `rejected` (cancel at the interceptor), so promoting it to a `status` value quietly makes `status="fail"` under-count versus older releases. As a cause it stays excludable via `cause!="cancel"` without redefining `status`. ### Also in this PR - The 7 `snapshot_impl` sites that emitted a bare `fail` with no classification now report their real cause via `failMetricLabel(err)` (e.g. `snapshot_metadata_uri is required` is `cause="user"`, not a system fault). Their `status` is unchanged. - `deployments/monitor/grafana/milvus-dashboard.json`: the "Faild Request Rate" panel goes back to `status="fail"` — a verbatim revert of what #50221 changed, which is the compatibility claim demonstrated. - Dev docs and stale comments that named the old label values. ### Verification - `TestParseMetricLabelStatusDomainIsStable` pins the status domain, so re-splitting it fails CI rather than shipping. - Adding a label makes every `WithLabelValues` site arity-sensitive **at runtime, not compile time** — a missed site panics in production. Unit tests do not reach all of them (coverage shows `GetRestoreSnapshotState`, `ListRestoreSnapshotJobs`, `PinSnapshotData`, `UnpinSnapshotData` at 0%), so all **58 emit sites were verified statically via AST**, not only the ones tests happen to hit. - Passing: `pkg/metrics`, `pkg/util/requestutil`, `pkg/util/merr`, `internal/distributed/proxy` (incl. `httpserver`, which covers the REST emit path), and the `internal/proxy` snapshot / metric-label tests. `golangci-lint` clean on every touched package. - Pre-existing and unrelated: `service_test.go` bind failures (`listen tcp :19529: address already in use`) reproduce identically on unmodified master — a local process holds the port. ### Rollout Should be cherry-picked to 2.6 so the window in which the fine-grained `status` values exist stays confined to v2.6.19–v2.6.20. Users who already adopted the new values on those two releases need a one-time query change (`status="fail_system"` -> `status="fail", cause="system"`); that is a known, bounded set, and preferable to leaving every pre-2.6.19 dashboard silently broken. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: zhenshan.cao <zhenshan.cao@zilliz.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
143 lines
4.7 KiB
Go
143 lines
4.7 KiB
Go
// Licensed to the LF AI & Data foundation under one
|
|
// or more contributor license agreements. See the NOTICE file
|
|
// distributed with this work for additional information
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
// to you under the Apache License, Version 2.0 (the
|
|
// "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package grpcproxy
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/stretchr/testify/suite"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v3/milvuspb"
|
|
"github.com/milvus-io/milvus/pkg/v3/metrics"
|
|
"github.com/milvus-io/milvus/pkg/v3/util/merr"
|
|
"github.com/milvus-io/milvus/pkg/v3/util/paramtable"
|
|
"github.com/milvus-io/milvus/pkg/v3/util/testutils"
|
|
)
|
|
|
|
type StatsInterceptorSuite struct {
|
|
testutils.PromMetricsSuite
|
|
}
|
|
|
|
func (suite *StatsInterceptorSuite) TestUnaryRequestStatsInterceptor() {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
type testCase struct {
|
|
tag string
|
|
req any
|
|
info *grpc.UnaryServerInfo
|
|
handler grpc.UnaryHandler
|
|
expectLabels [][]string
|
|
}
|
|
|
|
dbName := "default"
|
|
collection := "test"
|
|
|
|
cases := []testCase{
|
|
{
|
|
tag: "normal",
|
|
req: &milvuspb.CreateCollectionRequest{
|
|
DbName: dbName,
|
|
CollectionName: collection,
|
|
},
|
|
info: &grpc.UnaryServerInfo{
|
|
FullMethod: milvuspb.MilvusService_CreateCollection_FullMethodName,
|
|
},
|
|
handler: func(ctx context.Context, req any) (interface{}, error) {
|
|
return merr.Success(), nil
|
|
},
|
|
expectLabels: [][]string{
|
|
{paramtable.GetStringNodeID(), "CreateCollection", metrics.TotalLabel, metrics.CauseNA, dbName, collection},
|
|
{paramtable.GetStringNodeID(), "CreateCollection", metrics.SuccessLabel, metrics.CauseNA, dbName, collection},
|
|
},
|
|
},
|
|
{
|
|
tag: "service_internal",
|
|
req: &milvuspb.CreateCollectionRequest{
|
|
DbName: dbName,
|
|
CollectionName: collection,
|
|
},
|
|
info: &grpc.UnaryServerInfo{
|
|
FullMethod: milvuspb.MilvusService_CreateCollection_FullMethodName,
|
|
},
|
|
handler: func(ctx context.Context, req any) (interface{}, error) {
|
|
return merr.Status(merr.WrapErrServiceInternal("unexpcted")), nil
|
|
},
|
|
expectLabels: [][]string{
|
|
{paramtable.GetStringNodeID(), "CreateCollection", metrics.TotalLabel, metrics.CauseNA, dbName, collection},
|
|
{paramtable.GetStringNodeID(), "CreateCollection", metrics.FailLabel, metrics.CauseSystem, dbName, collection},
|
|
},
|
|
},
|
|
{
|
|
tag: "rate_limited",
|
|
req: &milvuspb.InsertRequest{
|
|
DbName: dbName,
|
|
CollectionName: collection,
|
|
},
|
|
info: &grpc.UnaryServerInfo{
|
|
FullMethod: milvuspb.MilvusService_Insert_FullMethodName,
|
|
},
|
|
handler: func(ctx context.Context, req any) (interface{}, error) {
|
|
return &milvuspb.MutationResult{
|
|
Status: merr.Status(merr.ErrServiceRateLimit),
|
|
}, nil
|
|
},
|
|
expectLabels: [][]string{
|
|
{paramtable.GetStringNodeID(), "Insert", metrics.TotalLabel, metrics.CauseNA, dbName, collection},
|
|
{paramtable.GetStringNodeID(), "Insert", metrics.RetryLabel, metrics.CauseNA, dbName, collection},
|
|
},
|
|
},
|
|
{
|
|
tag: "not_authorized",
|
|
req: &milvuspb.CreateCollectionRequest{
|
|
DbName: dbName,
|
|
CollectionName: collection,
|
|
},
|
|
info: &grpc.UnaryServerInfo{
|
|
FullMethod: milvuspb.MilvusService_CreateCollection_FullMethodName,
|
|
},
|
|
handler: func(ctx context.Context, req any) (interface{}, error) {
|
|
return nil, status.Error(codes.Unauthenticated, "auth check failure, please check api key is correct")
|
|
},
|
|
expectLabels: [][]string{
|
|
{paramtable.GetStringNodeID(), "CreateCollection", metrics.TotalLabel, metrics.CauseNA, dbName, collection},
|
|
// Unauthenticated is the caller's fault -> rejected, cause=user.
|
|
{paramtable.GetStringNodeID(), "CreateCollection", metrics.RejectedLabel, metrics.CauseUser, dbName, collection},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
suite.Run(tc.tag, func() {
|
|
UnaryRequestStatsInterceptor(ctx, tc.req, tc.info, tc.handler)
|
|
for _, labels := range tc.expectLabels {
|
|
suite.MetricsEqual(metrics.ProxyFunctionCall.WithLabelValues(labels...), 1)
|
|
}
|
|
metrics.ProxyFunctionCall.DeletePartialMatch(prometheus.Labels{})
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestUnaryRequestStatsInterceptor(t *testing.T) {
|
|
suite.Run(t, new(StatsInterceptorSuite))
|
|
}
|