-
Notifications
You must be signed in to change notification settings - Fork 389
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
Validate monitor in pre-flight #639
Conversation
Using CustomizeDiff, we can call the validation API to provide more validation for monitor creation. This allows returning an error during the `plan` phase, instead of waiting for `apply`. Closes #414
e7e72be
to
94b9b03
Compare
94b9b03
to
e6ad977
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@@ -342,6 +349,22 @@ func resourceDatadogMonitorExists(d *schema.ResourceData, meta interface{}) (b b | |||
return true, nil | |||
} | |||
|
|||
func resourceDatadogMonitorCustomizeDiff(diff *schema.ResourceDiff, meta interface{}) error { | |||
if _, ok := diff.GetOk("query"); !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we only validate the monitor if the query changed?
Will we have access to all the other non changed fields like thresholds?
(Can we debug log something here about not validating)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it means we only validate if we have a value, in particular when the query depends on another resource that's not resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. My main concern was that this diff
object wouldn't contain the entire monitor object and only include what changed. But we discussed offline and that shouldn't be the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a minor suggestion about the inline comment, but nothing blocking.
The CI failure looks unrelated to the monitors resource
LGTM, thanks!
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
datadogClientV1 := providerConf.DatadogClientV1 | ||
authV1 := providerConf.AuthV1 | ||
if _, _, err := datadogClientV1.MonitorsApi.ValidateMonitor(authV1).Body(*m).Execute(); err != nil { | ||
return translateClientError(err, "error validating monitor") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the error is a http400, we probably want to return a more specific error message with the invalid parts of the monitor indicated. The reasons be returned in the errors
key of the response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's what translateClientError
is supposed to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good!
@@ -195,11 +202,15 @@ func resourceDatadogMonitor() *schema.Resource { | |||
Type: schema.TypeBool, | |||
Optional: true, | |||
}, | |||
"validate": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the only change is to flip this from default true to false? If there aren't any changes to send to the API, I'm not sure if the endpoint accepts PUT /monitor/<id> {}
, would be good to verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean if the monitor object is already created, and we change the flag? I'll test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, removed it from the diff explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Awesome 🎉 . Just wondering @therve , are you planning to cut a release soon so we can leverage plan-time validation? Looking forward trying this out! 🙏 |
Using CustomizeDiff, we can call the validation API to provide more validation for monitor creation. This allows returning an error during the
plan
phase, instead of waiting forapply
.Closes #414