Skip to content

pup metrics list --filter always returns empty results (uses tag_filter instead of metric name filter) #53

@dasch

Description

@dasch

Summary

pup metrics list --filter always returns empty results regardless of the filter value. The --filter flag is documented as filtering by metric name pattern, but the implementation passes the value to the Datadog API's tag_filter parameter, which filters by Datadog tags (e.g., env:prod) — not metric names.

Steps to Reproduce

# List all metrics — works, returns 221k+ metrics
pup metrics list | python3 -c "import sys,json; d=json.load(sys.stdin); print(len(d['metrics']))"
# Output: 221561

# Filter by metric name — returns empty
pup metrics list --filter="system.cpu"
# Output: {"from": "...", "metrics": []}

# Even an exact metric name returns empty
pup metrics list --filter="system.cpu.user"
# Output: {"from": "...", "metrics": []}

# But these metrics exist in the unfiltered list
pup metrics list | python3 -c "
import sys, json
d = json.load(sys.stdin)
matches = [m for m in d['metrics'] if 'system.cpu' in m]
print(f'system.cpu matches: {len(matches)}')
"
# Output: system.cpu matches: 241

Every filter value produces empty results: kafka_index, system.*, *cpu*, bare strings, wildcards — all return {"metrics": []}.

Root Cause

In cmd/metrics.go, the runMetricsList function passes the --filter value as WithTagFilter():

opts := datadogV1.NewListActiveMetricsOptionalParameters()
if filterPattern != "" {
    opts = opts.WithTagFilter(filterPattern)
}

The Datadog v1 ListActiveMetrics API's tag_filter parameter filters by Datadog tags (comma-separated, e.g., env:prod,service:api) — not by metric name patterns. Since kafka_index, system.cpu, etc. are not valid tags, the API returns no matching metrics.

Expected Behavior

pup metrics list --filter="kafka_index" should return metrics whose names contain or match kafka_index, consistent with the help text:

FILTERING:
  Use the --filter flag to search for metrics matching a pattern:
  • system.* - All system metrics
  • *.cpu.* - All CPU-related metrics
  • custom.* - All custom metrics

Suggested Fix

The v1 ListActiveMetrics API doesn't support metric name filtering server-side. Options:

  1. Client-side name filtering: Fetch all metrics and filter names locally (simplest, matches documented behavior)
  2. Add --tag-filter flag: Expose the actual tag_filter API parameter under its correct name, and use --filter for client-side name matching
  3. Use v2 API: The v2 ListMetricAssets or metric search APIs may support name-based filtering

Environment

  • pup version: dev (unknown)
  • Installed via: go install github.com/DataDog/pup@latest
  • OS: macOS (Darwin 24.6.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions