terraform-provider-statuspage icon indicating copy to clipboard operation
terraform-provider-statuspage copied to clipboard

Metric creation failing

Open mielmat opened this issue 3 years ago • 4 comments

Hello, I wanted to use this provider to create metrics in my StatusPage. In current state (I believe after this merge) there is a problem - as omitempty doesn't work properly when using pointers and all fields receive some default value. The issue occurs when I don't want to set up y_axis_min and y_axis_max properties - both of them are set up to 0 as a default value, and when trying to do the POST request I receive 422 status code with message:

{"error":["Y-axis min must be less than Y-axis max."]}

The workaround for that is to set up property y_axis_hidden to true - in that case POST request works as expected. In that case, StatusPage API returns metric with below definition:

{"name":"test from terraform","metric_identifier":"test_tf_id","created_at":"2022-06-03T09:48:34.867Z","updated_at":"2022-06-03T09:48:34.867Z","id":"<some_id>","metrics_provider_id":"<id>","display":true,"y_axis_min":-0.01,"y_axis_max":1.01,"y_axis_hidden":true,"suffix":"","decimal_places":0,"tooltip_description":"","most_recent_data_at":null,"backfilled":false}

where y_axis_min and y_axis_max have some defaults.

I'm wondering if additional validation before metric creation makes sense. Or maybe that is not the place for doing that, and instead it should be done in go-sdk?

mielmat avatar Jun 03 '22 10:06 mielmat

Hi @mielmat , interesting, I would need to see what request the providers performs when y-axis is missing. If it does give values instead of ommitting it - that would be the opposite of why I was using pointers here for :grimacing: Thanks for the report!

yannh avatar Jun 03 '22 11:06 yannh

Frankly speaking, I spent some time on debugging the problem, with touching code of terraform provider and go-sdk and running everything locally. I could not find a reason of problem using provider logs, so I made the same request with the same payload with curl and it turned out why the 422 was returned, and the reason was the axis range validation.

It seems if y_axis is hidden, then validation is not done on StatusPage side, and it took some default values from their side. Of course there is nothing about it in StatusPage API docs.

mielmat avatar Jun 03 '22 11:06 mielmat

Could you share maybe the curl you did with the 422 result? that would be helpful! Thanks! Ideally those values would not be sent as part of the request if not present in Terraform.

yannh avatar Jun 03 '22 11:06 yannh

curl https://api.statuspage.io/v1/pages/<pageid>/metrics_providers/<metric_provider_id>/metrics \
  -H "Authorization: OAuth <token>" -H "Content-Type:application/json" \
  -X POST -d '{"metric": {"name":"test from terraform","metric_identifier":"test_tf_id","transform":"","suffix":"","y_axis_min":0,"y_axis_max":0,"y_axis_hidden":false,"display":false,"decimal_places":0,"tooltip_description":""}}'

and this is the reponse message:

{"error":["Y-axis min must be less than Y-axis max."]}

mielmat avatar Jun 03 '22 12:06 mielmat