Skip to content

Commit

Permalink
Add describe index (#165)
Browse files Browse the repository at this point in the history
Signed-off-by: Enwei Jiao <[email protected]>
  • Loading branch information
jiaoew1991 authored Jul 10, 2023
1 parent c6f2cd8 commit e1a31bb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions states/visit_indexcoord.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package states

import (
"context"
"fmt"

"github.com/milvus-io/birdwatcher/models"
"github.com/milvus-io/birdwatcher/proto/v2.0/indexpb"
indexpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/indexpb"
"github.com/milvus-io/birdwatcher/states/etcd/common"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)
Expand All @@ -28,6 +30,8 @@ func (s *indexCoordState) SetupCommands() {
getMetricsCmd(s.client),
// configuration
getConfigurationCmd(s.clientv2, s.session.ServerID),
// build index progress
getDescribeIndex(s.clientv2, s.session.ServerID),
//back
getBackCmd(s, s.prevState),
// exit
Expand Down Expand Up @@ -57,3 +61,43 @@ func getIndexCoordState(client indexpb.IndexCoordClient, conn *grpc.ClientConn,

return state
}

func getDescribeIndex(client indexpbv2.IndexCoordClient, serverID int64) *cobra.Command {
cmd := &cobra.Command{
Use: "describe",
Run: func(cmd *cobra.Command, args []string) {
collectionID, err := cmd.Flags().GetInt64("collection")
if err != nil {
fmt.Println("empty collectionID, err:", err.Error())
cmd.Usage()
return
}
resp, err := client.DescribeIndex(context.Background(), &indexpbv2.DescribeIndexRequest{
CollectionID: collectionID,
})
if err != nil {
fmt.Println("failed to call grpc, err:", err.Error())
return
}
for _, info := range resp.GetIndexInfos() {
printIndexV2(info)
}
},
}
cmd.Flags().Int64("collection", 0, "collection id")
return cmd
}

func printIndexV2(index *indexpbv2.IndexInfo) {
fmt.Println("==================================================================")
fmt.Printf("Index ID: %d\tIndex Name: %s\tCollectionID:%d\n", index.GetIndexID(), index.GetIndexName(), index.GetCollectionID())
fmt.Printf("Indexed Rows: %d\n", index.GetIndexedRows())
fmt.Printf("Total Rows: %d\n", index.GetTotalRows())
indexParams := index.GetIndexParams()
fmt.Printf("Index Type: %s\tMetric Type: %s\n",
common.GetKVPair(indexParams, "index_type"),
common.GetKVPair(indexParams, "metric_type"),
)
fmt.Printf("Index Params: %s\n", common.GetKVPair(index.GetUserIndexParams(), "params"))
fmt.Println("==================================================================")
}

0 comments on commit e1a31bb

Please sign in to comment.