Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ If you are using `histogram`, its always going to use the `request_time` to obse
`buckets` type is an array of float64 and its default value is `[1, 2, 5, 7, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 1000, 2000, 5000, 10000, 30000, 60000]`.

The `labels` configuration determines the label name and value extracted from the analytic record.
The available values are: `["host","method", "path", "response_code", "api_key", "time_stamp", "api_version", "api_name", "api_id", "org_id", "oauth_id", "request_time", "ip_address", "alias"]`
The available values are: `["host","method", "path", "response_code", "api_key", "time_stamp", "api_version", "api_name", "api_id", "org_id", "oauth_id", "request_time", "ip_address", "alias", "tag_<tag-name>"]`

###### JSON / Conf File

Expand Down
12 changes: 11 additions & 1 deletion pumps/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,17 @@ func (pm *PrometheusMetric) GetLabelsValues(decoded analytics.AnalyticsRecord) [
}

for _, label := range pm.Labels {
if val, ok := mapping[label]; ok {
if strings.HasPrefix(label, "tag_") {
tagPrefix := strings.TrimPrefix(label, "tag_") + "-"
value := "" // Default value when no tag matches
for _, t := range decoded.Tags {
if strings.HasPrefix(t, tagPrefix) {
value = strings.TrimPrefix(t, tagPrefix)
break
}
}
values = append(values, value)
} else if val, ok := mapping[label]; ok {
values = append(values, fmt.Sprint(val))
}
}
Expand Down
30 changes: 30 additions & 0 deletions pumps/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,36 @@ func TestPrometheusGetLabelsValues(t *testing.T) {
},
expectedLabels: []string{"200", "api_1", "abc"},
},
{
testName: "valid custom tag",
customMetric: PrometheusMetric{
Name: "testCounterMetric",
MetricType: counterType,
Labels: []string{"tag_custom"},
},
record: analytics.AnalyticsRecord{
APIID: "api_1",
ResponseCode: 200,
APIKey: "apikey",
Tags: []string{"custom-value"},
},
expectedLabels: []string{"value"},
},
{
testName: "two valid tag labels - one without value",
customMetric: PrometheusMetric{
Name: "testCounterMetric",
MetricType: counterType,
Labels: []string{"tag_custom", "tag_noexists"},
},
record: analytics.AnalyticsRecord{
APIID: "api_1",
ResponseCode: 200,
APIKey: "apikey",
Tags: []string{"custom-value"},
},
expectedLabels: []string{"value", ""},
},
}

for _, tc := range tcs {
Expand Down