Skip to content

Commit

Permalink
enhance: support access log print cluster prefix (milvus-io#29646)
Browse files Browse the repository at this point in the history
relate: milvus-io#29645

Signed-off-by: aoiasd <[email protected]>
  • Loading branch information
aoiasd authored Jan 5, 2024
1 parent 1c1f2a1 commit 70ec00c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/proxy/accesslog/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var metricFuncMap = map[string]getMetricFunc{
"$time_end": getTimeEnd,
"$method_expr": getExpr,
"$sdk_version": getSdkVersion,
"$cluster_prefix": getClusterPrefix,
}

var BaseFormatterKey = "base"
Expand Down
5 changes: 5 additions & 0 deletions internal/proxy/accesslog/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus/internal/proxy/connection"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable"
"github.com/milvus-io/milvus/pkg/util/requestutil"
)

Expand Down Expand Up @@ -272,3 +273,7 @@ func getSdkVersion(i *GrpcAccessInfo) string {
}
return clientInfo.SdkType + "-" + clientInfo.SdkVersion
}

func getClusterPrefix(i *GrpcAccessInfo) string {
return paramtable.Get().CommonCfg.ClusterPrefix.GetValue()
}
9 changes: 9 additions & 0 deletions internal/proxy/accesslog/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/milvus-io/milvus/pkg/util"
"github.com/milvus-io/milvus/pkg/util/crypto"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable"
)

type GrpcAccessInfoSuite struct {
Expand Down Expand Up @@ -148,6 +149,14 @@ func (s *GrpcAccessInfoSuite) TestExpression() {
s.Equal(testExpr, result[0])
}

func (s *GrpcAccessInfoSuite) TestClusterPrefix() {
cluster := "instance-test"
paramtable.Init()
paramtable.Get().Save(paramtable.Get().CommonCfg.ClusterPrefix.Key, cluster)
result := s.info.Get("$cluster_prefix")
s.Equal(cluster, result[0])
}

func TestGrpcAccssInfo(t *testing.T) {
suite.Run(t, new(GrpcAccessInfoSuite))
}

0 comments on commit 70ec00c

Please sign in to comment.