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

Fixing panic on prometheus collector when label has , #3947

Merged
merged 1 commit into from
Apr 7, 2017
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
- Add labels to the Docker healthcheck metricset output. {pull}3707[3707]
- Make system process metricset honor the cpu_ticks config option. {issue}3590[3590]
- Support common.Time in mapstriface.toTime() {pull}3812[3812]

- Fixing panic on prometheus collector when label has , {pull}3947[3947]
*Packetbeat*

*Winlogbeat*
Expand Down
15 changes: 15 additions & 0 deletions metricbeat/module/prometheus/collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ func TestDecodeLine(t *testing.T) {
},
},
},
{
Line: `apiserver_request_count{client="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",code="200",contentType="",resource="elasticsearchclusters",verb="LIST"} 1`,
Event: PromEvent{
key: "apiserver_request_count",
value: int64(1),
labelHash: `client="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",code="200",contentType="",resource="elasticsearchclusters",verb="LIST"`,
labels: common.MapStr{
"client": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
"code": int64(200),
"contentType": "",
"resource": "elasticsearchclusters",
"verb": "LIST",
},
},
},
}

for _, test := range tests {
Expand Down
7 changes: 4 additions & 3 deletions metricbeat/module/prometheus/collector/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type PromEvent struct {
// NewPromEvent creates a prometheus event based on the given string
func NewPromEvent(line string) PromEvent {
// Separate key and value
split := strings.Split(line, " ")
splitPos := strings.LastIndex(line, " ")
split := []string{line[:splitPos], line[splitPos+1:]}

promEvent := PromEvent{
key: split[0],
Expand Down Expand Up @@ -54,11 +55,11 @@ func extractLabels(labelsString string) common.MapStr {
keyValuePairs := common.MapStr{}

// Extract labels
labels := strings.Split(labelsString, ",")
labels := strings.Split(labelsString, "\",")
for _, label := range labels {
keyValue := strings.Split(label, "=")
// Remove " from value
keyValue[1] = keyValue[1][1 : len(keyValue[1])-1]
keyValue[1] = strings.Trim(keyValue[1], "\"")

// Converts value to int or float if needed
keyValuePairs[keyValue[0]] = convertValue(keyValue[1])
Expand Down
5 changes: 4 additions & 1 deletion metricbeat/module/prometheus/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func (m *MetricSet) Fetch() (common.MapStr, error) {
if line[0] == '#' || strings.Contains(line, "quantile=") {
continue
}
split := strings.Split(line, " ")

splitPos := strings.LastIndex(line, " ")
split := []string{line[:splitPos], line[splitPos+1:]}

entries[split[0]] = split[1]
}

Expand Down