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

feat: support more specific prefixes in ?collect parameter #387

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
8 changes: 5 additions & 3 deletions stackdriver_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,14 @@ func (h *handler) filterMetricTypePrefixes(filters map[string]bool) []string {
if len(filters) > 0 {
filteredPrefixes = nil
for _, prefix := range h.metricsPrefixes {
if filters[prefix] {
filteredPrefixes = append(filteredPrefixes, prefix)
for filter, _ := range filters {
if strings.HasPrefix(filter, prefix) {
filteredPrefixes = append(filteredPrefixes, filter)
}
}
}
}
return filteredPrefixes
return parseMetricTypePrefixes(filteredPrefixes)
}

func main() {
Expand Down
26 changes: 26 additions & 0 deletions stackdriver_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,29 @@ func TestParseMetricTypePrefixes(t *testing.T) {
t.Errorf("Metric type prefix sanitization did not produce expected output. Expected:\n%s\nGot:\n%s", expectedOutputPrefixes, outputPrefixes)
}
}

func TestFilterMetricTypePrefixes(t *testing.T) {
metricPrefixes := []string{
"redis.googleapis.com/stats/",
}

h := &handler{
metricsPrefixes: metricPrefixes,
}

inputFilters := map[string]bool{
"redis.googleapis.com/stats/memory/usage": true,
"redis.googleapis.com/stats/memory/usage_ratio": true,
"redis.googleapis.com": true,
}

expectedOutputPrefixes := []string{
"redis.googleapis.com/stats/memory/usage",
}

outputPrefixes := h.filterMetricTypePrefixes(inputFilters)

if !reflect.DeepEqual(outputPrefixes, expectedOutputPrefixes) {
t.Errorf("filterMetricTypePrefixes did not produce expected output. Expected:\n%s\nGot:\n%s", expectedOutputPrefixes, outputPrefixes)
}
}