未验证 提交 c5bb8a4a 编写于 作者: A Allen Zhou 提交者: GitHub

target tags can rewrite labels deined in categraf config file (#1321)

Co-authored-by: Nallenz <godloveallen@foxmail.com>
上级 06c16645
......@@ -16,6 +16,9 @@ DisableUsageReport = true
# config | database
ReaderFrom = "config"
# if true, target tags can rewrite labels defined in categraf config file
LabelRewrite = false
[Log]
# log write dir
Dir = "logs"
......
......@@ -12,13 +12,17 @@ func AppendLabels(pt *prompb.TimeSeries, target *models.Target) {
return
}
labelKeys := make(map[string]struct{})
labelKeys := make(map[string]int)
for j := 0; j < len(pt.Labels); j++ {
labelKeys[pt.Labels[j].Name] = struct{}{}
labelKeys[pt.Labels[j].Name] = j
}
for key, value := range target.TagsMap {
if _, has := labelKeys[key]; has {
if index, has := labelKeys[key]; has {
// overwrite labels
if config.C.LabelRewrite {
pt.Labels[index].Value = value
}
continue
}
......@@ -32,7 +36,7 @@ func AppendLabels(pt *prompb.TimeSeries, target *models.Target) {
if _, has := labelKeys[config.C.BusiGroupLabelKey]; has {
return
}
// 将业务组名称作为tag附加到数据上
if target.GroupId > 0 && len(config.C.BusiGroupLabelKey) > 0 {
bg := memsto.BusiGroupCache.GetByBusiGroupId(target.GroupId)
if bg == nil {
......
......@@ -267,6 +267,7 @@ type Config struct {
EngineDelay int64
DisableUsageReport bool
ReaderFrom string
LabelRewrite bool
ForceUseServerTS bool
Log logx.Config
HTTP httpx.Config
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册