Skip to content

Commit

Permalink
feat: simplify prometheus config naming style
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Nov 17, 2021
1 parent 06faa54 commit 9635dff
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions pkg/proxy/regProxy/etcd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ func (d *DataSource) watchPrometheus(path string) {
case event := <-watch.C():
switch event.Type {
case mvccpb.DELETE:
key, value := string(event.Kv.Key), string(event.Kv.Value)
key := string(event.Kv.Key)
keyArr := strings.Split(key, "/")
if len(keyArr) != 5 && len(keyArr) != 6 {
xlog.Error("watchPrometheus", xlog.String("key", key), xlog.String("value", value))
xlog.Error("watchPrometheus", xlog.String("key", key))
break
}
if value == "" {
value = keyArr[len(keyArr) -1]
}
filename := keyArr[3] + "_" + value

filename := keyArr[3] + "_" + keyArr[4]
filePath := path + "/" + filename + ".yml"
err = os.Remove(filePath)
if err != nil {
xlog.Error("remove prometheus file error",xlog.FieldErr(err))
xlog.Error("remove prometheus file error", xlog.FieldErr(err))
}
case mvccpb.PUT:
key, value := string(event.Kv.Key), string(event.Kv.Value)
Expand All @@ -49,7 +47,7 @@ func (d *DataSource) watchPrometheus(path string) {
xlog.Error("watchPrometheus", xlog.String("key", key), xlog.String("value", value))
break
}
filename := keyArr[3] + "_" + value
filename := keyArr[3] + "_" + keyArr[4]
content := `
- targets:
- "` + value + `"
Expand Down Expand Up @@ -82,7 +80,7 @@ func (d *DataSource) PrometheusConfigScanner(path string) {
xlog.Error("PrometheusConfigScanner", xlog.String("key", key), xlog.String("value", value))
continue
}
filename := keyArr[3] + "_" + value
filename := keyArr[3] + "_" + keyArr[4]

content := `
- targets:
Expand Down

0 comments on commit 9635dff

Please sign in to comment.