feat(processors.enum): Add multiple tag mapping (#16701)
This commit is contained in:
parent
5bb0002948
commit
05879b220e
|
|
@ -27,8 +27,8 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
## Names of the fields to map. Globs accepted.
|
## Names of the fields to map. Globs accepted.
|
||||||
fields = ["status"]
|
fields = ["status"]
|
||||||
|
|
||||||
## Name of the tag to map. Globs accepted.
|
## Name of the tags to map. Globs accepted.
|
||||||
# tag = "status"
|
# tags = ["status"]
|
||||||
|
|
||||||
## Destination tag or field to be used for the mapped value. By default the
|
## Destination tag or field to be used for the mapped value. By default the
|
||||||
## source tag or field is used, overwriting the original value.
|
## source tag or field is used, overwriting the original value.
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ type EnumMapper struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mapping struct {
|
type Mapping struct {
|
||||||
Tag string `toml:"tag"`
|
Tag string `toml:"tag" deprecated:"1.35.0;1.40.0;use 'tags' instead"`
|
||||||
Field string `toml:"field" deprecated:"1.35.0;1.40.0;use 'fields' instead"`
|
Field string `toml:"field" deprecated:"1.35.0;1.40.0;use 'fields' instead"`
|
||||||
|
Tags []string `toml:"tags"`
|
||||||
Fields []string `toml:"fields"`
|
Fields []string `toml:"fields"`
|
||||||
Dest string `toml:"dest"`
|
Dest string `toml:"dest"`
|
||||||
Default interface{} `toml:"default"`
|
Default interface{} `toml:"default"`
|
||||||
|
|
@ -48,14 +49,17 @@ func (mapper *EnumMapper) Init() error {
|
||||||
}
|
}
|
||||||
mapping.fieldFilter = fieldFilter
|
mapping.fieldFilter = fieldFilter
|
||||||
|
|
||||||
|
// Handle deprecated tag option
|
||||||
if mapping.Tag != "" {
|
if mapping.Tag != "" {
|
||||||
tagFilter, err := filter.Compile([]string{mapping.Tag})
|
mapping.Tags = append(mapping.Tags, mapping.Tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
tagFilter, err := filter.Compile(mapping.Tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create new tag filter: %w", err)
|
return fmt.Errorf("failed to create new tag filter: %w", err)
|
||||||
}
|
}
|
||||||
mapping.tagFilter = tagFilter
|
mapping.tagFilter = tagFilter
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ func TestRetainsMetric(t *testing.T) {
|
||||||
|
|
||||||
func TestMapsSingleStringValueTag(t *testing.T) {
|
func TestMapsSingleStringValueTag(t *testing.T) {
|
||||||
mapper := EnumMapper{Mappings: []*Mapping{{
|
mapper := EnumMapper{Mappings: []*Mapping{{
|
||||||
Tag: "tag",
|
Tags: []string{"tag"},
|
||||||
ValueMappings: map[string]interface{}{"tag_value": "valuable"},
|
ValueMappings: map[string]interface{}{"tag_value": "valuable"},
|
||||||
}}}
|
}}}
|
||||||
err := mapper.Init()
|
err := mapper.Init()
|
||||||
|
|
@ -232,7 +232,7 @@ func TestFieldGlobMatching(t *testing.T) {
|
||||||
|
|
||||||
func TestTagGlobMatching(t *testing.T) {
|
func TestTagGlobMatching(t *testing.T) {
|
||||||
mapper := EnumMapper{Mappings: []*Mapping{{
|
mapper := EnumMapper{Mappings: []*Mapping{{
|
||||||
Tag: "*",
|
Tags: []string{"*"},
|
||||||
ValueMappings: map[string]interface{}{"tag_value": "glob"},
|
ValueMappings: map[string]interface{}{"tag_value": "glob"},
|
||||||
}}}
|
}}}
|
||||||
err := mapper.Init()
|
err := mapper.Init()
|
||||||
|
|
@ -281,7 +281,7 @@ func TestTracking(t *testing.T) {
|
||||||
m, _ = metric.WithTracking(m, notify)
|
m, _ = metric.WithTracking(m, notify)
|
||||||
|
|
||||||
mapper := EnumMapper{Mappings: []*Mapping{{
|
mapper := EnumMapper{Mappings: []*Mapping{{
|
||||||
Tag: "*",
|
Tags: []string{"*"},
|
||||||
ValueMappings: map[string]interface{}{"tag_value": "glob"},
|
ValueMappings: map[string]interface{}{"tag_value": "glob"},
|
||||||
}}}
|
}}}
|
||||||
err := mapper.Init()
|
err := mapper.Init()
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
## Names of the fields to map. Globs accepted.
|
## Names of the fields to map. Globs accepted.
|
||||||
fields = ["status"]
|
fields = ["status"]
|
||||||
|
|
||||||
## Name of the tag to map. Globs accepted.
|
## Name of the tags to map. Globs accepted.
|
||||||
# tag = "status"
|
# tags = ["status"]
|
||||||
|
|
||||||
## Destination tag or field to be used for the mapped value. By default the
|
## Destination tag or field to be used for the mapped value. By default the
|
||||||
## source tag or field is used, overwriting the original value.
|
## source tag or field is used, overwriting the original value.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue