Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid empty tags on docker and prometheus inputs #2396

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ func (d *Docker) gatherContainer(

// Add labels to tags
for k, label := range container.Labels {
tags[k] = label
if label != "" {
tags[k] = label
}
}

gatherContainerStats(v, acc, tags, container.ID, d.PerDevice, d.Total)
Expand Down
4 changes: 3 additions & 1 deletion plugins/inputs/prometheus/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ func makeBuckets(m *dto.Metric) map[string]interface{} {
func makeLabels(m *dto.Metric) map[string]string {
result := map[string]string{}
for _, lp := range m.Label {
result[lp.GetName()] = lp.GetValue()
if lp.GetValue() != "" {
result[lp.GetName()] = lp.GetValue()
}
}
return result
}
Expand Down
8 changes: 3 additions & 5 deletions plugins/inputs/prometheus/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ func TestParseValidPrometheus(t *testing.T) {
"gauge": float64(1),
}, metrics[0].Fields())
assert.Equal(t, map[string]string{
"osVersion": "CentOS Linux 7 (Core)",
"dockerVersion": "1.8.2",
"kernelVersion": "3.10.0-229.20.1.el7.x86_64",
"cadvisorRevision": "",
"cadvisorVersion": "",
"osVersion": "CentOS Linux 7 (Core)",
"dockerVersion": "1.8.2",
"kernelVersion": "3.10.0-229.20.1.el7.x86_64",
}, metrics[0].Tags())

// Counter value
Expand Down