Skip to content

Commit

Permalink
The problem with different cardinality of labels on prometheus nodes …
Browse files Browse the repository at this point in the history
…should now be solved
  • Loading branch information
dereulenspiegel committed Dec 24, 2015
1 parent 8f7d9d8 commit be09698
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func getLabels(nodeinfo data.NodeInfo, defaultLabels ...string) []string {
if prometheusCfg.UBool("sitecodelabel", false) {
labels = append(labels, nodeinfo.System.SiteCode)
}
return labels
return append(labels, defaultLabels...)
}

func (n *NodeMetricCollector) Process(in chan data.ParsedResponse) chan data.ParsedResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package prometheus

import (
"testing"

"github.com/dereulenspiegel/node-informant/gluon-collector/config"
"github.com/dereulenspiegel/node-informant/gluon-collector/data"
cfg "github.com/olebedev/config"
"github.com/stretchr/testify/assert"
)

var (
testConfig = `
prometheus:
namelabel: true
sitecodelabel: true
`
)

func TestCreationOfPrometheusLabels(t *testing.T) {
assert := assert.New(t)
nodeinfo := data.NodeInfo{
Hostname: "Testnode",
System: data.SystemStruct{
SiteCode: "fftest",
},
NodeId: "1122",
}
var err error
config.Global, err = cfg.ParseYaml(testConfig)
assert.Nil(err)

prmcfg, err := config.Global.Get("prometheus")
assert.Nil(err)
assert.NotNil(prmcfg)

nodeLabels := getLabels(nodeinfo, "metric")
assert.Equal(4, len(nodeLabels))
assert.Equal("1122", nodeLabels[0])
assert.Equal("Testnode", nodeLabels[1])
assert.Equal("fftest", nodeLabels[2])
assert.Equal("metric", nodeLabels[3])
}

0 comments on commit be09698

Please sign in to comment.