Skip to content

Commit

Permalink
enhance: [Cherry-pick]Add collection name label for some metric (#36951
Browse files Browse the repository at this point in the history
…) (#37159)

pr: #36951

Signed-off-by: aoiasd <[email protected]>
  • Loading branch information
aoiasd authored Oct 29, 2024
1 parent 05c4052 commit 8370caa
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/datacoord/index_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ func (m *indexMeta) SetStoredIndexFileSizeMetric(collections map[UniqueID]*colle
for _, segmentIdx := range m.buildID2SegmentIndex {
coll, ok := collections[segmentIdx.CollectionID]
if ok {
metrics.DataCoordStoredIndexFilesSize.WithLabelValues(coll.DatabaseName,
metrics.DataCoordStoredIndexFilesSize.WithLabelValues(coll.DatabaseName, coll.Schema.GetName(),
fmt.Sprint(segmentIdx.CollectionID), fmt.Sprint(segmentIdx.SegmentID)).Set(float64(segmentIdx.IndexSize))
total += segmentIdx.IndexSize
}
Expand Down
2 changes: 1 addition & 1 deletion internal/datacoord/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (m *meta) GetQuotaInfo() *metricsinfo.DataCoordQuotaMetrics {
coll, ok := m.collections[collectionID]
if ok {
for state, rows := range statesRows {
metrics.DataCoordNumStoredRows.WithLabelValues(coll.DatabaseName, fmt.Sprint(collectionID), state.String()).Set(float64(rows))
metrics.DataCoordNumStoredRows.WithLabelValues(coll.DatabaseName, fmt.Sprint(collectionID), coll.Schema.GetName(), state.String()).Set(float64(rows))
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions internal/querynodev2/metrics_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func getQuotaMetrics(node *QueryNode) (*metricsinfo.QueryNodeQuotaMetrics, error
}

minTsafeChannel, minTsafe := node.tSafeManager.Min()
collections := node.manager.Collection.List()
collections := node.manager.Collection.ListWithName()
nodeID := fmt.Sprint(node.GetNodeID())

metrics.QueryNodeNumEntities.Reset()
Expand All @@ -70,7 +70,7 @@ func getQuotaMetrics(node *QueryNode) (*metricsinfo.QueryNodeQuotaMetrics, error
growingGroupByCollection := lo.GroupBy(growingSegments, func(seg segments.Segment) int64 {
return seg.Collection()
})
for _, collection := range collections {
for collection := range collections {
segs := growingGroupByCollection[collection]
size := lo.SumBy(segs, func(seg segments.Segment) int64 {
return seg.MemSize()
Expand All @@ -90,6 +90,7 @@ func getQuotaMetrics(node *QueryNode) (*metricsinfo.QueryNodeQuotaMetrics, error
segment := segs[0]
metrics.QueryNodeNumEntities.WithLabelValues(
segment.DatabaseName(),
collections[segment.Collection()],
nodeID,
fmt.Sprint(segment.Collection()),
fmt.Sprint(segment.Partition()),
Expand All @@ -101,7 +102,7 @@ func getQuotaMetrics(node *QueryNode) (*metricsinfo.QueryNodeQuotaMetrics, error
sealedGroupByCollection := lo.GroupBy(sealedSegments, func(seg segments.Segment) int64 {
return seg.Collection()
})
for _, collection := range collections {
for collection := range collections {
segs := sealedGroupByCollection[collection]
size := lo.SumBy(segs, func(seg segments.Segment) int64 {
return seg.MemSize()
Expand All @@ -119,6 +120,7 @@ func getQuotaMetrics(node *QueryNode) (*metricsinfo.QueryNodeQuotaMetrics, error
segment := segs[0]
metrics.QueryNodeNumEntities.WithLabelValues(
segment.DatabaseName(),
collections[segment.Collection()],
nodeID,
fmt.Sprint(segment.Collection()),
fmt.Sprint(segment.Partition()),
Expand Down Expand Up @@ -148,7 +150,7 @@ func getQuotaMetrics(node *QueryNode) (*metricsinfo.QueryNodeQuotaMetrics, error
GrowingSegmentsSize: totalGrowingSize,
Effect: metricsinfo.NodeEffect{
NodeID: node.GetNodeID(),
CollectionIDs: collections,
CollectionIDs: lo.Keys(collections),
},
DeleteBufferInfo: metricsinfo.DeleteBufferInfo{
CollectionDeleteBufferNum: deleteBufferNum,
Expand Down
11 changes: 11 additions & 0 deletions internal/querynodev2/segments/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (

type CollectionManager interface {
List() []int64
ListWithName() map[int64]string
Get(collectionID int64) *Collection
PutOrRef(collectionID int64, schema *schemapb.CollectionSchema, meta *segcorepb.CollectionIndexMeta, loadMeta *querypb.LoadMetaInfo)
Ref(collectionID int64, count uint32) bool
Expand Down Expand Up @@ -75,6 +76,16 @@ func (m *collectionManager) List() []int64 {
return lo.Keys(m.collections)
}

// return all collections by map id --> name
func (m *collectionManager) ListWithName() map[int64]string {
m.mut.RLock()
defer m.mut.RUnlock()

return lo.MapValues(m.collections, func(coll *Collection, _ int64) string {
return coll.Schema().GetName()
})
}

func (m *collectionManager) Get(collectionID int64) *Collection {
m.mut.RLock()
defer m.mut.RUnlock()
Expand Down
47 changes: 47 additions & 0 deletions internal/querynodev2/segments/mock_collection_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/metrics/datacoord_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var (
}, []string{
databaseLabelName,
collectionIDLabelName,
collectionName,
segmentStateLabelName,
})

Expand Down Expand Up @@ -162,6 +163,7 @@ var (
Help: "index files size of the segments",
}, []string{
databaseLabelName,
collectionName,
collectionIDLabelName,
segmentIDLabelName,
})
Expand Down Expand Up @@ -390,7 +392,7 @@ func CleanupDataCoordSegmentMetrics(dbName string, collectionID int64, segmentID
collectionIDLabelName: fmt.Sprint(collectionID),
segmentIDLabelName: fmt.Sprint(segmentID),
})
DataCoordStoredIndexFilesSize.Delete(prometheus.Labels{
DataCoordStoredIndexFilesSize.DeletePartialMatch(prometheus.Labels{
databaseLabelName: dbName,
collectionIDLabelName: fmt.Sprint(collectionID),
segmentIDLabelName: fmt.Sprint(segmentID),
Expand Down
1 change: 1 addition & 0 deletions pkg/metrics/querynode_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ var (
Help: "number of entities which can be searched/queried, clustered by collection, partition and state",
}, []string{
databaseLabelName,
collectionName,
nodeIDLabelName,
collectionIDLabelName,
partitionIDLabelName,
Expand Down

0 comments on commit 8370caa

Please sign in to comment.