Skip to content

Commit

Permalink
some changes after review
Browse files Browse the repository at this point in the history
   * add generator test
   * reformat

Signed-off-by: Frederic Van Espen <[email protected]>
  • Loading branch information
Frederic Van Espen committed Aug 31, 2020
1 parent a93b52d commit 545219d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
1 change: 0 additions & 1 deletion collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 51 additions & 0 deletions generator/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 545219d

Please sign in to comment.