Skip to content

Commit

Permalink
[CONTROLLER/PROMETHEUS] fixes updating label type bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengya committed Oct 11, 2023
1 parent 2f68ce2 commit 5f9a895
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions server/controller/prometheus/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@ func GetDebugCache(t controller.PrometheusCacheType) []byte {
getLabel := func() {
temp := map[string]interface{}{
"key_to_id": make(map[string]interface{}),
"id_to_key": make(map[int]string),
"id_to_key": make(map[int]interface{}),
}
tempCache.Label.idToKey.Range(func(key, value any) bool {
tempCache.Label.keyToID.Range(func(key, value any) bool {
temp["key_to_id"].(map[string]interface{})[marshal(key)] = value
return true
})
tempCache.Label.idToKey.Range(func(key, value any) bool {
temp["id_to_key"].(map[int]string)[key.(int)] = marshal(value)
temp["id_to_key"].(map[int]interface{})[key.(int)] = value
return true
})

if len(temp["key_to_id"].(map[string]interface{})) > 0 ||
len(temp["id_to_key"].(map[int]string)) > 0 {
len(temp["id_to_key"].(map[int]interface{})) > 0 {
content["label"] = temp
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func GetDebugCache(t controller.PrometheusCacheType) []byte {
for item := range value.Iterator().C {
keys[marshal(item)] = struct{}{}
}
temp["target_id_to_label_names"].(map[string]interface{})[key] = keys
temp["metric_name_to_target_ids"].(map[string]interface{})[key] = keys
}
if len(temp["metric_target_keys"].(map[string]interface{})) > 0 ||
len(temp["metric_name_to_target_ids"].(map[string]interface{})) > 0 ||
Expand Down
10 changes: 8 additions & 2 deletions server/controller/prometheus/cache/metric_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func (mi *metricLabel) GetMetricNameIDToLabelIDs() *hashmap.Map[int, mapset.Set[
func (ml *metricLabel) Add(batch []*controller.PrometheusMetricLabel) {
for _, item := range batch {
for _, li := range item.GetLabelIds() {
ml.metricNameIDToLabelIDs.GetOrInsert(int(item.GetMetricNameId()), mapset.NewSet(int(li)))
ml.metricNameIDToLabelIDs.GetOrInsert(int(item.GetMetricNameId()), mapset.NewSet[int]())
if lids, ok := ml.metricNameIDToLabelIDs.Get(int(item.GetMetricNameId())); ok {
lids.Add(int(li))
}
}
}
}
Expand All @@ -79,7 +82,10 @@ func (ml *metricLabel) refresh(args ...interface{}) error {
}
for _, item := range metricLabels {
if mni, ok := ml.metricNameCache.GetIDByName(item.MetricName); ok {
ml.metricNameIDToLabelIDs.GetOrInsert(mni, mapset.NewSet(item.LabelID))
ml.metricNameIDToLabelIDs.GetOrInsert(mni, mapset.NewSet[int]())
if lids, ok := ml.metricNameIDToLabelIDs.Get(mni); ok {
lids.Add(item.LabelID)
}
}
}
return nil
Expand Down
1 change: 0 additions & 1 deletion server/controller/prometheus/cache/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func (t *targetIDToLabelNames) Load(id int) []string {
type target struct {
keyToTargetID *keyToTargetID
targetIDToLabelNames *targetIDToLabelNames
idToLabels sync.Map
}

func newTarget() *target {
Expand Down
1 change: 1 addition & 0 deletions server/controller/prometheus/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (au *APPLabelLayoutUpdater) refresh() error {
}

for mn, lns := range td.metricNameToLabelNames {
log.Infof("debug metric: %s labels: %v", mn, lns.ToSlice())
newAPPLabelNames := lns.Difference(mapset.NewSet([]string{common.TargetLabelInstance, common.TargetLabelJob}...))
if targetLNs, ok := td.metricNameToTargetLabelNames[mn]; ok {
newAPPLabelNames = newAPPLabelNames.Difference(targetLNs)
Expand Down

0 comments on commit 5f9a895

Please sign in to comment.