fix(terraform): handle missing thresholds in line widget conversion#1750
Open
TechIsCool wants to merge 1 commit intonewrelic:mainfrom
Open
fix(terraform): handle missing thresholds in line widget conversion#1750TechIsCool wants to merge 1 commit intonewrelic:mainfrom
TechIsCool wants to merge 1 commit intonewrelic:mainfrom
Conversation
Fixes issue where `utils terraform dashboard` command would fail with "Error unmarshalling widgetLineThreshold: unexpected end of JSON input" when processing line widgets without threshold configuration. The code now checks if the threshold field exists and has content before attempting to unmarshal it.
|
|
1 similar comment
|
|
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.
Description
The
newrelic utils terraform dashboardcommand fails with a fatal error when processing dashboards that contain line widgets (viz.line) without threshold configuration. This prevents legitimate dashboard JSON exports from New Relic from being converted to Terraform HCL format.Go Version
Current behavior
When attempting to convert a New Relic dashboard JSON to Terraform HCL format, the CLI immediately crashes with a fatal error if any line widget in the dashboard doesn't have thresholds configured:
The command terminates without producing any output.
Expected behavior
The command should successfully convert the dashboard JSON to Terraform HCL format. Line widgets without thresholds are valid in New Relic dashboards (thresholds are optional), so the conversion should handle their absence gracefully and generate valid Terraform configuration.
Steps To Reproduce
example_mvp.jsonwith the following content:{ "name": "MVP Dashboard", "description": "Minimal dashboard to reproduce line widget threshold issue", "permissions": "PUBLIC_READ_ONLY", "pages": [ { "name": "Test Page", "description": "Page with line widget without thresholds", "widgets": [ { "id": "1", "title": "Line Widget Without Thresholds", "layout": { "column": 1, "row": 1, "width": 4, "height": 3 }, "linkedEntityGuids": null, "visualization": { "id": "viz.line" }, "rawConfiguration": { "facet": {}, "legend": { "enabled": true }, "nrqlQueries": [ { "accountId": 12345, "query": "SELECT count(*) FROM Transaction TIMESERIES" } ], "platformOptions": {}, "yAxisLeft": { "zero": false } } } ] } ] }Debug Output (if applicable)
The error originates from
internal/utils/terraform/dashboard.go:293in thewriteLineWidgetAttributes()function, which unconditionally attempts to unmarshal theconfig.Thresholdfield even when it's empty or null.Additional Context
thresholdsfield is optional in New Relic's dashboard API specificationexample_mvp.jsonfile triggers this issue as it contains multiple line widgets without thresholdswriteLineWidgetAttributes()function which doesn't validate that threshold data exists before attempting to unmarshal itReferences or Related Issues
internal/utils/terraform/dashboard.gowriteLineWidgetAttributes()newrelic utils terraform dashboard