Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: add config key filter for show configurations cmd #235

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions states/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

"github.com/milvus-io/birdwatcher/framework"
"github.com/milvus-io/birdwatcher/proto/v2.2/commonpb"
datapbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/datapb"
indexpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/indexpb"
querypbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/querypb"
rootcoordpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/rootcoordpb"
"github.com/milvus-io/birdwatcher/states/etcd/common"
"github.com/samber/lo"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

type GetConfigurationParam struct {
framework.ParamBase `use:"show configurations" desc:"iterate all online components and inspect configuration"`
Format string `name:"format" default:"line" desc:"output format"`
Filter string `name:"filter" default:"" desc:"configuration key filter sub string"`
}

func (s *InstanceState) GetConfigurationCommand(ctx context.Context, p *GetConfigurationParam) error {
Expand All @@ -31,9 +34,8 @@ func (s *InstanceState) GetConfigurationCommand(ctx context.Context, p *GetConfi

for _, session := range sessions {
opts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithTimeout(2 * time.Second),
}

conn, err := grpc.DialContext(ctx, session.Address, opts...)
Expand Down Expand Up @@ -68,6 +70,10 @@ func (s *InstanceState) GetConfigurationCommand(ctx context.Context, p *GetConfi
continue
}

configurations = lo.Filter(configurations, func(configuration *commonpb.KeyValuePair, _ int) bool {
return p.Filter == "" || strings.Contains(configuration.GetKey(), p.Filter)
})

results[fmt.Sprintf("%s-%d", session.ServerName, session.ServerID)] = common.KVListMap(configurations)
}

Expand Down
4 changes: 2 additions & 2 deletions states/etcd/show/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func printIndex(index IndexInfoV1) {
common.GetKVPair(indexParams, "metric_type"),
)
fmt.Printf("Index Params: %s\n", common.GetKVPair(index.info.GetIndexParams(), "params"))
for _ , v := range indexParams {
for _, v := range indexParams {
fmt.Printf("%s:%s", v.GetKey(), v.GetValue())
}
fmt.Println("==================================================================")
Expand All @@ -100,7 +100,7 @@ func printIndexV2(index indexpbv2.FieldIndex) {
common.GetKVPair(indexParams, "metric_type"),
)
fmt.Printf("Index Params: %s\n", common.GetKVPair(index.GetIndexInfo().GetUserIndexParams(), "params"))
for _ , v := range indexParams {
for _, v := range indexParams {
fmt.Printf("%s:%s", v.GetKey(), v.GetValue())
}
fmt.Println("==================================================================")
Expand Down