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

[CONTROLLER/PROMETHEUS] fixes metric label synced_at bug #5297

Merged
merged 1 commit into from
Jan 17, 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
2 changes: 1 addition & 1 deletion cli/ctl/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func RegisterPrometheusCommand() *cobra.Command {
clearCmd := &cobra.Command{
Use: "clear",
Short: "clear prometheus data in MySQL by deepflow-server, use with caution and not frequently!",
Example: "deepflow-ctl prometheus clear \"2006-01-02 15:04:05\"",
Example: "deepflow-ctl prometheus clear -e \"2006-01-02 15:04:05\"",
Run: func(cmd *cobra.Command, args []string) {
prometheusClear(cmd, expiredAt)
},
Expand Down
6 changes: 0 additions & 6 deletions server/controller/http/router/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ func (p *Prometheus) RegisterTo(e *gin.Engine) {
func createPrometheusCleanTask(c *gin.Context) {
body := make(map[string]interface{})
err := c.ShouldBindBodyWith(&body, binding.JSON)
log.Errorf("body: %v", body)
if err != nil {
log.Errorf("body: %v", err)
routercommon.JsonResponse(c, body, err)
return
}

isMaster, masterCtrlIP, httpPort, _, err := common.CheckSelfAndGetMasterControllerHostPort()
if err != nil {
log.Errorf("body: %v", err)
routercommon.JsonResponse(c, body, err)
return
}
Expand All @@ -60,16 +57,13 @@ func createPrometheusCleanTask(c *gin.Context) {
if e, ok := body["EXPIRED_AT"]; ok {
expiredAt, err = time.Parse(common.GO_BIRTHDAY, e.(string))
if err != nil {
log.Errorf("body: %v", err)
routercommon.JsonResponse(c, body, err)
return
}
}
log.Errorf("body: %v", body)
err = prometheus.GetCleaner().Clear(expiredAt)
} else {
_, err = common.CURLPerform(http.MethodPost, fmt.Sprintf("http://%s:%d/v1/prometheus-cleaner-tasks/", masterCtrlIP, httpPort), body)
log.Errorf("body: %v", err)
}
routercommon.JsonResponse(c, body, err)
}
14 changes: 12 additions & 2 deletions server/controller/prometheus/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,17 @@ func GetDebugCache(t controller.PrometheusCacheType) []byte {
getMetricAndAppLabelLayout := func() {
temp := map[string]interface{}{
"layout_key_to_index": make(map[string]interface{}),
"layout_key_to_id": make(map[string]int),
}
tempCache.MetricAndAPPLabelLayout.layoutKeyToIndex.Range(func(key, value any) bool {
temp["layout_key_to_index"].(map[string]interface{})[marshal(key)] = value
return true
})
if len(temp["layout_key_to_index"].(map[string]interface{})) > 0 {
for iter := range tempCache.MetricAndAPPLabelLayout.layoutKeyToID.Iter() {
temp["layout_key_to_id"].(map[string]int)[iter.Key.String()] = iter.Val
}
if len(temp["layout_key_to_index"].(map[string]interface{})) > 0 ||
len(temp["layout_key_to_id"].(map[string]int)) > 0 {
content["metric_and_app_label_layout"] = temp
}
}
Expand Down Expand Up @@ -237,14 +242,19 @@ func GetDebugCache(t controller.PrometheusCacheType) []byte {
getMetricLabel := func() {
temp := map[string]interface{}{
"metric_name_id_to_label_ids": make(map[int][]int),
"metric_label_key_to_id": make(map[string]int),
}

tempCache.MetricLabel.metricNameIDToLabelIDs.Range(func(i int, s mapset.Set[int]) bool {
temp["metric_name_id_to_label_ids"].(map[int][]int)[i] = s.ToSlice()
return true
})
for iter := range tempCache.MetricLabel.keyToID.Iter() {
temp["metric_label_key_to_id"].(map[string]int)[iter.Key.String()] = iter.Val
}

if len(temp["metric_name_id_to_label_ids"].(map[int][]int)) > 0 {
if len(temp["metric_name_id_to_label_ids"].(map[int][]int)) > 0 ||
len(temp["metric_label_key_to_id"].(map[string]int)) > 0 {
content["metric_label"] = temp
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/controller/prometheus/cache/metric_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ func (ml *metricLabel) refresh(args ...interface{}) error {

func (ml *metricLabel) load() ([]*mysql.PrometheusMetricLabel, error) {
var metricLabels []*mysql.PrometheusMetricLabel
err := mysql.Db.Select("metric_name", "label_id").Find(&metricLabels).Error
err := mysql.Db.Select("metric_name", "label_id", "id").Find(&metricLabels).Error
return metricLabels, err
}
2 changes: 1 addition & 1 deletion server/controller/prometheus/cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (c *Cleaner) Stop() {
}

func (c *Cleaner) Clear(expiredAt time.Time) error {
log.Infof("prometheus data cleaner clear by hand started")
log.Infof("prometheus data cleaner clear by hand")
return c.clear(expiredAt)
}

Expand Down
2 changes: 1 addition & 1 deletion server/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ controller:
# encoder cache refresh interval, unit: second
encoder_cache_refresh_interval: 3600
# time interval for regularly clearing prometheus expired data, unit: hour
# time interval should be less than or equal to ingester: prometheus-label-cache-expiration configuration
# time interval should be greater than or equal to ingester: prometheus-label-cache-expiration configuration
data_clean_interval: 24

querier:
Expand Down
Loading