infra: bake jq fixes into NR JSON source (apply.sh + Terraform read same clean files)#51
Merged
Merged
Conversation
F's apply.sh in the infra repo patched 3 schema gaps at apply time via jq.
Terraform reads the same JSON but wouldn't run the adapter — the source
JSON drifted from one applier to the other. Bake the fixes into the source
so apply.sh + Terraform consume identical clean structures.
Fixes baked:
1. Dashboards: accountIds:[0] → accountIds:["${NEW_RELIC_ACCOUNT_ID}"]
substitution token across all 4 dashboards (28 total occurrences).
2. Alerts: drop "type": "NRQL" — NerdGraph rejects it on
NrqlConditionStaticInput; the mutation name encodes the type.
3. Alert policy: add policies/instant-api.json describing the umbrella
policy + add policyName="instant-api alerts" linking field to each
alert JSON, replacing apply.sh's inline find-or-create logic.
apply.sh already handles this defensively — its jq walk() rewrites
.accountIds regardless of the previous value, and del(.type) is a no-op
when the field is absent. No companion infra PR needed.
Tests (infra/newrelic/tests/bake_test.sh): 31 assertions covering JSON
parse, accountIds token presence + count per dashboard, absence of
"type" on alerts, policyName cross-ref between alerts and policy file,
and policy file shape. All pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
F's apply.sh in the infra repo patched 3 schema gaps at apply time via
jq. Terraform reads the same JSON but wouldn't run the adapter, so the source JSON drifted from one applier to the other. This bakes the fixes into the source so apply.sh + Terraform consume identical clean structures.Fixes baked:
infra/newrelic/dashboards/*.json):"accountIds": [0]→"accountIds": ["${NEW_RELIC_ACCOUNT_ID}"]across all 4 dashboards (28 total occurrences). Both apply.sh and Terraform substitute the real account ID before the API call.infra/newrelic/alerts/*.json): drop"type": "NRQL"— NerdGraph rejects it onNrqlConditionStaticInput; the mutation name encodes the type.infra/newrelic/policies/instant-api.json): describes the umbrella policy (name: "instant-api alerts",incidentPreference: "PER_CONDITION_AND_TARGET"). Each alert inalerts/gains"policyName": "instant-api alerts"linking back.Coordination
apply.sh already handles the new shape defensively — no companion infra PR needed:
prepare_dashboarduseswalk(... has("accountIds") then .accountIds = [$account] ...)— rewrites.accountIdsregardless of previous value (was[0], now["${...}"], end result[number]either way).apply_alertalready doesdel(.type)— a no-op when the field is absent.ensure_policyfind-or-creates inline byPOLICY_NAMEenv (default"instant-api alerts"— matches our policy file). Note: apply.sh hardcodesincidentPreference: "PER_CONDITION"in the create-branch while the policy file specifiesPER_CONDITION_AND_TARGET. On existing accounts the find-branch wins so no drift; brand-new accounts will get the apply.sh value. Worth aligning in a follow-up infra PR but not blocking.Tests
New:
infra/newrelic/tests/bake_test.sh— 31 assertions:accountIds: [0]residue, token count matchesnrqlQueriescount per filetypefield,policyNameset to"instant-api alerts"policies/instant-api.jsonparses + has correctname+incidentPreferencepolicyNamematches the policy file'snameRun:
bash infra/newrelic/tests/bake_test.sh→31 passed, 0 failed.Test plan
bash infra/newrelic/tests/bake_test.shexits 0find infra/newrelic -name '*.json' -exec jq empty {} \;passesapply.sh's hardcodedincidentPreference: "PER_CONDITION"with the policy file'sPER_CONDITION_AND_TARGETNo Go code, k8s, or dashboard changes. JSON + README + test script only.
Generated with Claude Code