Skip to content

Update viz objects validation #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

klisiecka-splunk
Copy link
Contributor

Update validation for dashboards and dashboard groups in order to pass validation mode.

@klisiecka-splunk klisiecka-splunk requested review from a team as code owners May 20, 2025 07:52
Copy link
Collaborator

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't expect that it will always be run in terraform, or have a leaky implementation.

Comment on lines 8 to 9
FULL ValidationMode = "FULL"
TERRAFORM ValidationMode = "TERRAFORM"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to expand on what the differences are here?

Copy link
Contributor Author

@klisiecka-splunk klisiecka-splunk Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to define a resource that references the ID of another resource. For example, a dashboard might reference chart ID, like:

resource "signalfx_time_chart" "test_chart" {
  name = "test chart"
  # ...
}

resource "signalfx_dashboard" "test_dashboard" {
  name = "test dashboard"

  chart {
    chart_id = signalfx_time_chart.test_chart.id
  }
  # ...
}

However, during the plan phase, the referenced chart has not yet been created, and Terraform replaces the chart_id with a placeholder string. This string cannot be parsed by the backend, as it expects a valid ID.

To address this, the TERRAFORM mode allows a dashboard request to omit chart_id, enabling validation of the other dashboard fields without causing errors.

Comment on lines 12 to 19
func ValidateValidationMode(validationMode ValidationMode) error {
switch validationMode {
case FULL, TERRAFORM:
return nil
default:
return errors.New("invalid validation mode: " + string(validationMode))
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest making this a method on ValidationMode instead of a seperate function. Comparing the two options, it makes it simpiler to understand when reviewing ValidationMode.Validate() when compared to util.ValidateValidationMode(Full).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

util is the wrong package for this, I am not strictly sure what would be the best option here but for now I'd probably move this to be in the top level directly next to dashboards since they are currently coupled together in their implementation details.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please don't forget to add test cases and validate that the validate method works :)

defer teardown()

params := url.Values{"validationMode": []string{"TERRAFORM"}}
mux.HandleFunc("/v2/dashboardgroup/validate", verifyRequest(t, "POST", true, http.StatusNoContent, params, ""))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use http.MethodPost instead of a magic string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All methods in dashbaord_test.go and dashboardgroup_test.go used strings, so I changed them also for consistency.


err := client.ValidateDashboardWithMode(context.Background(), &dashboard.CreateUpdateDashboardRequest{
Name: "string",
}, "IVALID MODE")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a typo :)

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.

3 participants