Skip to content
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

Merged
merged 9 commits into from
Aug 27, 2020
Merged

Validate monitor in pre-flight #639

merged 9 commits into from
Aug 27, 2020

Conversation

therve
Copy link
Contributor

@therve therve commented Aug 18, 2020

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

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
@therve therve requested review from a team as code owners August 18, 2020 07:55
@therve therve changed the title Pull request for therve/validate-monitor Validate monitor in pre-flight Aug 18, 2020
@therve therve force-pushed the therve/validate-monitor branch from e7e72be to 94b9b03 Compare August 18, 2020 08:06
@therve therve force-pushed the therve/validate-monitor branch from 94b9b03 to e6ad977 Compare August 18, 2020 08:17
@therve
Copy link
Contributor Author

therve commented Aug 18, 2020

/azp run

@azure-pipelines
Copy link

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 {
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

nmuesch
nmuesch previously approved these changes Aug 18, 2020
Copy link
Contributor

@nmuesch nmuesch left a 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!

@therve therve requested a review from phillip-dd August 21, 2020 10:18
@therve
Copy link
Contributor Author

therve commented Aug 21, 2020

/azp run

@azure-pipelines
Copy link

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")
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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": {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

phillip-dd
phillip-dd previously approved these changes Aug 24, 2020
Copy link
Contributor

@phillip-dd phillip-dd left a comment

Choose a reason for hiding this comment

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

thanks!

@therve
Copy link
Contributor Author

therve commented Aug 27, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@zippolyte zippolyte left a comment

Choose a reason for hiding this comment

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

LGTM

@therve therve merged commit 070f8b2 into master Aug 27, 2020
@therve therve deleted the therve/validate-monitor branch August 27, 2020 13:00
@ktham
Copy link

ktham commented Sep 9, 2020

Awesome 🎉 . Just wondering @therve , are you planning to cut a release soon so we can leverage plan-time validation? Looking forward trying this out! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(feature request) Validate monitor during plan with datadog api
5 participants