enhance: use Delete instead of DeletePartialMatch to remove metrics (#33029)

Signed-off-by: jaime <yun.zhang@zilliz.com>
This commit is contained in:
jaime 2024-05-14 18:49:33 +08:00 committed by GitHub
parent 89a7c34c7a
commit f48a7ff8ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 14 deletions

View File

@ -176,8 +176,20 @@ func (m *meta) AddCollection(collection *collectionInfo) {
// DropCollection drop a collection from meta // DropCollection drop a collection from meta
func (m *meta) DropCollection(collectionID int64) { func (m *meta) DropCollection(collectionID int64) {
log.Info("meta update: drop collection", zap.Int64("collectionID", collectionID)) log.Info("meta update: drop collection", zap.Int64("collectionID", collectionID))
segments := m.SelectSegments(WithCollection(collectionID))
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
coll, ok := m.collections[collectionID]
if ok {
metrics.CleanupDataCoordNumStoredRows(coll.DatabaseName, collectionID)
metrics.CleanupDataCoordBulkInsertVectors(coll.DatabaseName, collectionID)
for _, seg := range segments {
metrics.CleanupDataCoordSegmentMetrics(coll.DatabaseName, collectionID, seg.ID)
}
} else {
log.Warn("not found database name", zap.Int64("collectionID", collectionID))
}
delete(m.collections, collectionID) delete(m.collections, collectionID)
metrics.DataCoordNumCollections.WithLabelValues().Set(float64(len(m.collections))) metrics.DataCoordNumCollections.WithLabelValues().Set(float64(len(m.collections)))
log.Info("meta update: drop collection - complete", zap.Int64("collectionID", collectionID)) log.Info("meta update: drop collection - complete", zap.Int64("collectionID", collectionID))
@ -321,6 +333,8 @@ func (m *meta) GetCollectionBinlogSize() (int64, map[UniqueID]int64, map[UniqueI
// GetCollectionIndexFilesSize returns the total index files size of all segment for each collection. // GetCollectionIndexFilesSize returns the total index files size of all segment for each collection.
func (m *meta) GetCollectionIndexFilesSize() uint64 { func (m *meta) GetCollectionIndexFilesSize() uint64 {
m.RLock()
defer m.RUnlock()
var total uint64 var total uint64
for _, segmentIdx := range m.indexMeta.GetAllSegIndexes() { for _, segmentIdx := range m.indexMeta.GetAllSegIndexes() {
coll, ok := m.collections[segmentIdx.CollectionID] coll, ok := m.collections[segmentIdx.CollectionID]
@ -385,6 +399,11 @@ func (m *meta) DropSegment(segmentID UniqueID) error {
return err return err
} }
metrics.DataCoordNumSegments.WithLabelValues(segment.GetState().String(), segment.GetLevel().String()).Dec() metrics.DataCoordNumSegments.WithLabelValues(segment.GetState().String(), segment.GetLevel().String()).Dec()
coll, ok := m.collections[segment.CollectionID]
if ok {
metrics.CleanupDataCoordSegmentMetrics(coll.DatabaseName, segment.CollectionID, segment.ID)
}
m.segments.DropSegment(segmentID) m.segments.DropSegment(segmentID)
log.Info("meta update: dropping segment - complete", log.Info("meta update: dropping segment - complete",
zap.Int64("segmentID", segmentID)) zap.Int64("segmentID", segmentID))

View File

@ -586,7 +586,6 @@ func (s *Server) DropVirtualChannel(ctx context.Context, req *datapb.DropVirtual
return resp, nil return resp, nil
} }
var collectionID int64
segments := make([]*SegmentInfo, 0, len(req.GetSegments())) segments := make([]*SegmentInfo, 0, len(req.GetSegments()))
for _, seg2Drop := range req.GetSegments() { for _, seg2Drop := range req.GetSegments() {
info := &datapb.SegmentInfo{ info := &datapb.SegmentInfo{
@ -602,7 +601,6 @@ func (s *Server) DropVirtualChannel(ctx context.Context, req *datapb.DropVirtual
} }
segment := NewSegmentInfo(info) segment := NewSegmentInfo(info)
segments = append(segments, segment) segments = append(segments, segment)
collectionID = seg2Drop.GetCollectionID()
} }
err := s.meta.UpdateDropChannelSegmentInfo(channel, segments) err := s.meta.UpdateDropChannelSegmentInfo(channel, segments)
@ -619,11 +617,7 @@ func (s *Server) DropVirtualChannel(ctx context.Context, req *datapb.DropVirtual
} }
s.segmentManager.DropSegmentsOfChannel(ctx, channel) s.segmentManager.DropSegmentsOfChannel(ctx, channel)
s.compactionHandler.removeTasksByChannel(channel) s.compactionHandler.removeTasksByChannel(channel)
metrics.CleanupDataCoordNumStoredRows(collectionID)
metrics.DataCoordCheckpointUnixSeconds.DeleteLabelValues(fmt.Sprint(paramtable.GetNodeID()), channel) metrics.DataCoordCheckpointUnixSeconds.DeleteLabelValues(fmt.Sprint(paramtable.GetNodeID()), channel)
metrics.CleanupDataCoordBulkInsertVectors(collectionID)
// no compaction triggered in Drop procedure // no compaction triggered in Drop procedure
return resp, nil return resp, nil
} }

View File

@ -445,7 +445,6 @@ func (kc *Catalog) DropSegment(ctx context.Context, segment *datapb.SegmentInfo)
return err return err
} }
metrics.CleanupDataCoordSegmentMetrics(segment.CollectionID, segment.ID)
return nil return nil
} }

View File

@ -322,34 +322,38 @@ func RegisterDataCoord(registry *prometheus.Registry) {
registry.MustRegister(GarbageCollectorRunCount) registry.MustRegister(GarbageCollectorRunCount)
} }
func CleanupDataCoordSegmentMetrics(collectionID int64, segmentID int64) { func CleanupDataCoordSegmentMetrics(dbName string, collectionID int64, segmentID int64) {
DataCoordSegmentBinLogFileCount. DataCoordSegmentBinLogFileCount.
Delete( Delete(
prometheus.Labels{ prometheus.Labels{
collectionIDLabelName: fmt.Sprint(collectionID), collectionIDLabelName: fmt.Sprint(collectionID),
segmentIDLabelName: fmt.Sprint(segmentID), segmentIDLabelName: fmt.Sprint(segmentID),
}) })
DataCoordStoredBinlogSize.DeletePartialMatch(prometheus.Labels{ DataCoordStoredBinlogSize.Delete(prometheus.Labels{
databaseLabelName: dbName,
collectionIDLabelName: fmt.Sprint(collectionID), collectionIDLabelName: fmt.Sprint(collectionID),
segmentIDLabelName: fmt.Sprint(segmentID), segmentIDLabelName: fmt.Sprint(segmentID),
}) })
DataCoordStoredIndexFilesSize.DeletePartialMatch(prometheus.Labels{ DataCoordStoredIndexFilesSize.Delete(prometheus.Labels{
databaseLabelName: dbName,
collectionIDLabelName: fmt.Sprint(collectionID), collectionIDLabelName: fmt.Sprint(collectionID),
segmentIDLabelName: fmt.Sprint(segmentID), segmentIDLabelName: fmt.Sprint(segmentID),
}) })
} }
func CleanupDataCoordNumStoredRows(collectionID int64) { func CleanupDataCoordNumStoredRows(dbName string, collectionID int64) {
for _, state := range commonpb.SegmentState_name { for _, state := range commonpb.SegmentState_name {
DataCoordNumStoredRows.DeletePartialMatch(prometheus.Labels{ DataCoordNumStoredRows.Delete(prometheus.Labels{
databaseLabelName: dbName,
collectionIDLabelName: fmt.Sprint(collectionID), collectionIDLabelName: fmt.Sprint(collectionID),
segmentStateLabelName: fmt.Sprint(state), segmentStateLabelName: fmt.Sprint(state),
}) })
} }
} }
func CleanupDataCoordBulkInsertVectors(collectionID int64) { func CleanupDataCoordBulkInsertVectors(dbName string, collectionID int64) {
DataCoordBulkVectors.DeletePartialMatch(prometheus.Labels{ DataCoordBulkVectors.Delete(prometheus.Labels{
databaseLabelName: dbName,
collectionIDLabelName: fmt.Sprint(collectionID), collectionIDLabelName: fmt.Sprint(collectionID),
}) })
} }