diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 791a258e98a..9f61392ab1f 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -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* diff --git a/metricbeat/module/prometheus/collector/collector_test.go b/metricbeat/module/prometheus/collector/collector_test.go index c6a1954d220..2651efab7e3 100644 --- a/metricbeat/module/prometheus/collector/collector_test.go +++ b/metricbeat/module/prometheus/collector/collector_test.go @@ -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 { diff --git a/metricbeat/module/prometheus/collector/data.go b/metricbeat/module/prometheus/collector/data.go index 0f39e1d0fe3..ea659d6eebc 100644 --- a/metricbeat/module/prometheus/collector/data.go +++ b/metricbeat/module/prometheus/collector/data.go @@ -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], @@ -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]) diff --git a/metricbeat/module/prometheus/stats/stats.go b/metricbeat/module/prometheus/stats/stats.go index ad6b65dd953..7864aa0f74b 100644 --- a/metricbeat/module/prometheus/stats/stats.go +++ b/metricbeat/module/prometheus/stats/stats.go @@ -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] }