From 545219dfa0c7b4fabd536addf0b859431af05fef Mon Sep 17 00:00:00 2001 From: Frederic Van Espen Date: Mon, 31 Aug 2020 10:35:20 +0200 Subject: [PATCH] some changes after review * add generator test * reformat Signed-off-by: Frederic Van Espen --- collector.go | 1 - config/config.go | 2 +- generator/tree_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/collector.go b/collector.go index 9b621ab9..931bcbb4 100644 --- a/collector.go +++ b/collector.go @@ -672,7 +672,6 @@ func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool, case "EnumAsInfo": subOid, indexOids := splitOid(indexOids, 1) return enumValues[subOid[0]], subOid, indexOids - default: panic(fmt.Sprintf("Unknown index type %s", typ)) return "", nil, nil diff --git a/config/config.go b/config/config.go index a97f32f8..9d7379fd 100644 --- a/config/config.go +++ b/config/config.go @@ -185,7 +185,7 @@ type Index struct { Type string `yaml:"type"` FixedSize int `yaml:"fixed_size,omitempty"` Implied bool `yaml:"implied,omitempty"` - EnumValues map[int]string `yaml:"enum_values,omitempty"` + EnumValues map[int]string `yaml:"enum_values,omitempty"` } type Lookup struct { diff --git a/generator/tree_test.go b/generator/tree_test.go index 13fdeae7..feef7459 100644 --- a/generator/tree_test.go +++ b/generator/tree_test.go @@ -981,6 +981,57 @@ func TestGenerateConfigModule(t *testing.T) { }, }, }, + // Basic table with integer index and enum_values, overridden as EnumAsInfo. + { + node: &Node{Oid: "1", Label: "root", + Children: []*Node{ + {Oid: "1.1", Label: "table", + Children: []*Node{ + {Oid: "1.1.1", Label: "tableEntry", Indexes: []string{"tableIndex"}, + Children: []*Node{ + {Oid: "1.1.1.1", Access: "ACCESS_READONLY", Label: "tableIndex", Type: "INTEGER", EnumValues: map[int]string{0: "a"}}, + {Oid: "1.1.1.2", Access: "ACCESS_READONLY", Label: "tableFoo", Type: "INTEGER"}, + }}}}}}, + cfg: &ModuleConfig{ + Walk: []string{"1"}, + Overrides: map[string]MetricOverrides{ + "tableIndex": MetricOverrides{Type: "EnumAsInfo"}, + }, + }, + out: &config.Module{ + Walk: []string{"1"}, + Metrics: []*config.Metric{ + { + Name: "tableIndex", + Oid: "1.1.1.1", + Type: "EnumAsInfo", + Help: " - 1.1.1.1", + Indexes: []*config.Index{ + { + Labelname: "tableIndex", + Type: "EnumAsInfo", + EnumValues: map[int]string{0: "a"}, + }, + }, + EnumValues: map[int]string{0: "a"}, + }, + { + Name: "tableFoo", + Oid: "1.1.1.2", + Type: "gauge", + Help: " - 1.1.1.2", + Indexes: []*config.Index{ + { + Labelname: "tableIndex", + Type: "EnumAsInfo", + EnumValues: map[int]string{0: "a"}, + }, + }, + }, + }, + }, + }, + // One table lookup, lookup not walked, labels kept. { node: &Node{Oid: "1", Label: "root",