Skip to content

fix(metrics): use client-side filtering for --filter flag, add --tag-filter#54

Merged
platinummonkey merged 1 commit into
mainfrom
fix/metrics-filter-name-matching
Feb 12, 2026
Merged

fix(metrics): use client-side filtering for --filter flag, add --tag-filter#54
platinummonkey merged 1 commit into
mainfrom
fix/metrics-filter-name-matching

Conversation

@platinummonkey
Copy link
Copy Markdown
Collaborator

Summary

Fixes #53 - pup metrics list --filter now correctly filters metrics by name patterns instead of returning empty results.

The --filter flag was incorrectly using the Datadog API's tag_filter parameter, which filters by Datadog tags (like env:prod), not metric names. This caused all metric name filters to return empty results.

Changes

  • Add matchMetricName() helper (cmd/metrics.go:637) - Implements wildcard pattern matching supporting * (match any characters) and ? (match single character)
  • Apply client-side filtering (cmd/metrics.go:748-755) - Filters metric names after fetching from API when --filter is used
  • Add --tag-filter flag (cmd/metrics.go:484) - Exposes actual tag filtering functionality for users who want to filter by Datadog tags
  • Update documentation (cmd/metrics.go:162-208) - Clarifies the difference between --filter (name patterns) and --tag-filter (Datadog tags)
  • Comprehensive tests (cmd/metrics_test.go:205-468) - 30+ test cases covering wildcard patterns, edge cases, and real-world examples

Testing

Unit tests:

go test ./cmd -run TestMatchMetricName  # 30+ pattern matching tests
go test ./cmd -run TestRunMetricsList   # Integration tests

Manual testing with real API:

# Before fix: returns empty
pup metrics list --filter="system.cpu"
# Output: {"from": "...", "metrics": []}

# After fix: returns matching metrics
pup metrics list --filter="system.cpu*"
# Output: {"from": "...", "metrics": ["system.cpu.user", "system.cpu.system", ...]}

# Wildcard patterns work as documented
pup metrics list --filter="*.cpu.*"
pup metrics list --filter="*request*"

# New --tag-filter flag for tag-based filtering
pup metrics list --tag-filter="env:prod"
pup metrics list --filter="system.*" --tag-filter="env:prod"  # Combine both

Test coverage:

  • cmd package: 24.8% (maintained)
  • pkg packages: >80% (maintained)
  • All tests pass with race detection

Examples

# Filter by metric name patterns (client-side)
pup metrics list --filter="system.*"          # All system metrics
pup metrics list --filter="*.cpu.*"           # All CPU metrics
pup metrics list --filter="*request*"         # Metrics containing "request"
pup metrics list --filter="kafka_index*"      # Kafka index metrics

# Filter by Datadog tags (server-side)
pup metrics list --tag-filter="env:prod"                    # Production metrics
pup metrics list --tag-filter="env:prod,service:api"        # Multiple tags (AND)

# Combine both filters
pup metrics list --filter="system.*" --tag-filter="env:prod"  # System metrics in prod

Breaking Changes

None. The --filter flag behavior is fixed to match its documentation. Since it was broken (always returned empty), no existing workflows should break.

Related Issues

Closes #53


🤖 Generated with Claude Code

…filter

The --filter flag was incorrectly using the API's tag_filter parameter,
which filters by Datadog tags (env:prod), not metric names. This caused
all metric name filters to return empty results.

Changes:
- Add matchMetricName() helper supporting wildcards (* and ?)
- Apply client-side filtering on metric names when --filter is used
- Add --tag-filter flag to expose actual tag filtering functionality
- Update documentation to clarify filter vs tag-filter usage
- Add comprehensive tests for wildcard pattern matching

The fix allows users to filter metrics by name patterns (system.*,
*.cpu.*, *request*) while maintaining backward compatibility. Users can
now use --tag-filter for tag-based filtering if needed.

Fixes #53

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@platinummonkey platinummonkey requested a review from a team as a code owner February 12, 2026 14:17
@github-actions
Copy link
Copy Markdown

📊 Test Coverage Report

Overall Coverage: 81.7% Coverage

Threshold: 80% ✅

Coverage by Package
## Coverage by Package

- github.com/DataDog/pup/pkg/auth/callback/server.go:40: 81.2%
- github.com/DataDog/pup/pkg/auth/dcr/client.go:28: 100.0%
- github.com/DataDog/pup/pkg/auth/dcr/types.go:24: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/client.go:22: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/pkce.go:24: 85.7%
- github.com/DataDog/pup/pkg/auth/storage/factory.go:53: 94.7%
- github.com/DataDog/pup/pkg/auth/storage/keychain.go:44: 42.9%
- github.com/DataDog/pup/pkg/auth/storage/storage.go:58: 71.4%
- github.com/DataDog/pup/pkg/auth/types/types.go:23: 100.0%
- github.com/DataDog/pup/pkg/client/client.go:32: 94.4%
- github.com/DataDog/pup/pkg/config/alias.go:26: 100.0%
- github.com/DataDog/pup/pkg/config/config.go:22: 100.0%
- github.com/DataDog/pup/pkg/formatter/formatter.go:31: 100.0%
- github.com/DataDog/pup/pkg/useragent/useragent.go:32: 100.0%
- github.com/DataDog/pup/pkg/util/time.go:28: 96.0%

## Summary

total:								(statements)		81.7%

📈 Coverage Status: ✅ PASSED - Coverage meets minimum threshold

Updated for commit 392f1c3

@platinummonkey platinummonkey merged commit 448f307 into main Feb 12, 2026
4 checks passed
@platinummonkey platinummonkey deleted the fix/metrics-filter-name-matching branch February 12, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant