feat(metrics): add v1 metrics search and fix v2 query request body#32
Merged
platinummonkey merged 2 commits intoFeb 11, 2026
Merged
Conversation
The v2 QueryTimeseriesData request was missing the required Formulas array and Name field, causing 400 Bad Request for all queries. Fix the request body to match the official SDK example and add a v1 metrics search subcommand using QueryMetrics (same convention as logs search/query). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove duplicate test case in TestRunMetricsSearch - Add wantErrContains assertions to verify error message content - Replace brittle string-literal checks in TestMetricsSearchCmd with behavioral assertions (subcommand registration, flag existence) - Add TestMetricsCmd_Subcommands verifying all 6 subcommands registered Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Hey 👋 , got a little carried away - not sure if v1 support is wanted but I saw it was there for some other APIs so I followed suit. Can adjust to decrease the scope if you want. |
platinummonkey
approved these changes
Feb 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes the v2
metrics queryrequest body (which was causing 400 Bad Request forall queries) and adds a new
metrics searchsubcommand backed by the v1QueryMetricsAPI, following the same convention aslogs search(v1) /logs query(v2).After this PR:
Motivation
pup metrics queryreturns 400 Bad Request for every query. The v2TimeseriesFormulaQueryRequestbody was missing two required fields:Nameon the query: eachMetricsTimeseriesQuerymust have a name(e.g.
"a") so formulas can reference it.Formulasarray: the request must include at least one formulareferencing the named query (e.g.
{Formula: "a"}).Repro:
The existing code (
cmd/metrics.go) was:This sets
DataSourceandQuerybut leavesNamenil and never populatesFormulas. The fix matches the official SDK example atexamples/v2/metrics/QueryTimeseriesData.go.Additional Changes
Test improvements (
cmd/metrics_test.go): Removed duplicate test case,added
wantErrContainsassertions to verify error message content, replacedbrittle string-literal checks in
TestMetricsSearchCmdwith behavioralassertions (subcommand registration, flag existence), added
TestMetricsCmd_Subcommands.Additional Notes
Tested manually against a live Datadog account after building from this branch:
v1 search (new command):
v2 query (fixed, previously 400'd):
Help output confirms both subcommands with API version labels:
Unit tests: 13 test functions, 28 sub-tests, 0 failures.
Checklist
Related Issues