Skip to content

Commit

Permalink
feat: support more specific prefixes in ?collect parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Deschênes <[email protected]>
  • Loading branch information
antoinedeschenes committed Nov 14, 2024
1 parent 15981bb commit 594fcb3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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) {
inputFilters := map[string]bool{
"redis.googleapis.com/stats/memory/usage": true,
"redis.googleapis.com/stats/memory/usage_ratio": true,
"redis.googleapis.com": true,
}

inputPrefixes := []string{
"redis.googleapis.com/stats/",
}

h := &handler{
metricsPrefixes: inputPrefixes,
}

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)
}
}

0 comments on commit 594fcb3

Please sign in to comment.