Skip to content

fix(datadog): billable-summary 400 (month must be YYYY-MM) + pagination SIGSEGV - #86

Open
scottt732 wants to merge 2 commits into
opencost:mainfrom
scottt732:fix/datadog-billable-summary-month-format
Open

fix(datadog): billable-summary 400 (month must be YYYY-MM) + pagination SIGSEGV#86
scottt732 wants to merge 2 commits into
opencost:mainfrom
scottt732:fix/datadog-billable-summary-month-format

Conversation

@scottt732

Copy link
Copy Markdown

What does this PR change?

  • Fixes the Datadog plugin's GET /api/v1/usage/billable-summary call, which the Datadog API now rejects with 400 Bad Request: month must be in the format YYYY-MM because the generated datadog-api-client-go serializes the month parameter as a full RFC3339 timestamp (current client master does too, so a dependency bump cannot fix this). A small http.RoundTripper rewrites the parameter to YYYY-MM in transit, scoped to the billable-summary path — version-proof against the client library, and a no-op if the client ever emits YYYY-MM itself.
  • Guards the pagination NextRecordId dereference in getDDCostsForWindow: NullableString.IsSet() returns true for an explicit JSON null at end of pagination while Get() returns nil, so once pricing succeeds the plugin crashes with SIGSEGV. Same fix as the now-stale fix(datadog): add nil check for NextRecordId in pagination logic (#68) #70.

Does this PR relate to any other PRs?

How will this PR impact users?

Does this PR address any GitHub or Zendesk issues?

How was this PR tested?

  • New unit tests for the RoundTripper (rewrite on billable-summary, passthrough for already-short YYYY-MM, other endpoints untouched).
  • Reproduced the 400 against a live Datadog org (us5) with curl — RFC3339 month rejected, YYYY-MM accepted with the same credentials.
  • Ran the plugin harness end-to-end against the live org with both fixes: pricing loads, hourly usage paginates to completion without panic, and real cost items are returned (2 windows, 42 costs). Without the transport fix every window returns the 400; without the nil guard the plugin SIGSEGVs at main.go:237 once pricing succeeds.
  • go build ./..., go vet ./..., go test ./datadogplugin/... all clean.

Does this PR require changes to documentation?

  • No.

… API requires

The Datadog API now rejects /api/v1/usage/billable-summary requests whose
month query parameter is a full RFC3339 timestamp, which is what the
generated datadog-api-client-go emits for time.Time parameters (current
client master included):

    400 Bad Request: month must be in the format YYYY-MM

Since GetDDUnitPrices has no fallback, this made every GetCustomCosts
window fail, rendering the plugin unable to retrieve any costs.

Add a small http.RoundTripper that rewrites the month parameter to
YYYY-MM in transit, scoped to the billable-summary path. Doing it at the
transport layer keeps the fix independent of the client library version
and is a no-op if the client ever starts emitting YYYY-MM itself.

Fixes opencost#85
…SEGV)

Install the MonthParamRoundTripper on the Datadog API client so the
billable-summary month parameter reaches the API as YYYY-MM (opencost#85).

Also guard the pagination NextRecordId deref: NullableString.IsSet()
returns true when the API sends an explicit JSON null at the end of
pagination, but Get() then returns nil, so the existing check crashed
with SIGSEGV once pricing succeeded. Same fix as the now-stale opencost#70.

With both changes the plugin retrieves real costs end-to-end again
(verified against a live us5 Datadog org).

Fixes opencost#68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant