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

[dashboards] Add new Dashboard resource #249

Merged
merged 14 commits into from
Jul 24, 2019

Conversation

enbashi
Copy link
Contributor

@enbashi enbashi commented Jun 26, 2019

Adds a new datadog_dashboard resource that uses the new Dashboard API https://docs.datadoghq.com/api/#dashboards

@ghost ghost added the size/XXL label Jun 26, 2019
Copy link
Contributor

@bkabrda bkabrda left a comment

Choose a reason for hiding this comment

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

Overall this is awesome work, thanks a lot for doing this. Couple comments:

  • I've left several notes inline the code that should be addressed.
  • We'll need documentation for this feature under the website directory; while writing it, you can use make website to spin up a local Docker container to see if everything is formatted/linked right.

Also thanks for writing the integration tests - they pass for me and I've also been able to play around with this without any issues at all, so great job 👍

datadog/resource_datadog_dashboard.go Outdated Show resolved Hide resolved
datadog/resource_datadog_dashboard_test.go Outdated Show resolved Hide resolved
datadog/resource_datadog_dashboard.go Show resolved Hide resolved
@enbashi
Copy link
Contributor Author

enbashi commented Jun 27, 2019

Overall this is awesome work, thanks a lot for doing this. Couple comments:

  • I've left several notes inline the code that should be addressed.
  • We'll need documentation for this feature under the website directory; while writing it, you can use make website to spin up a local Docker container to see if everything is formatted/linked right.

Also thanks for writing the integration tests - they pass for me and I've also been able to play around with this without any issues at all, so great job 👍

Thanks @bkabrda for the review and comments. I've addressed them and would love to hear your thoughts about ConflictsWith limitations.
I am also working on a separate PR to update the docs. Would you like me to include the docs in this same PR instead?

@bkabrda
Copy link
Contributor

bkabrda commented Jun 27, 2019

@enbashi as for the ConflictsWith, I've actually already marked that as resolved because you correctly pointed out that my proposal wasn't viable.

As for docs, I would like to have them in the same PR.

@ghost ghost added the documentation label Jun 28, 2019
@enbashi
Copy link
Contributor Author

enbashi commented Jun 28, 2019

@bkabrda I added the docs.

Copy link
Contributor

@bkabrda bkabrda left a comment

Choose a reason for hiding this comment

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

Nice work on the docs; I left couple comments inline that should be addressed before we can merge this.

@@ -34,15 +37,9 @@
<li<%= sidebar_current("docs-datadog-resource-monitor") %>>
<a href="/docs/providers/datadog/r/monitor.html">datadog_monitor</a>
</li>
<li<%= sidebar_current("docs-datadog-resource-screenboard") %>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not remove the links to screenboard and timeboard resources just yet. Marking them outdated is sufficient for now IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We wanted to follow the same approach we did for https://docs.datadoghq.com/api/#dashboards when we rolled out the new API to achieve two goals:

  • Push users to use the new resource while still having access to the old resources
  • Minimize confusion that might be caused by having three related resources accessible from the main page

That said, I don't have a strong opinion about that so if you still think we should keep the links I am happy add them back. let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be really confusing if the documentation just disappeared one day without the users understanding why. There's no good way in TF provider docs to go back to docs of older versions, so keeping the links there and putting the disclaimers there for screenboard and timeboard resources seems like the best solution to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since these won't be deprecated in the next immediate provider version, I also think we should keep the links. Once we start deprecation on the resources we should remove the links and log a notice. For now I think we should just leave a note at the top of each screenboard/timeboard page.

You can even use this to make it a big note !> at the top of the timeboard/screenboard pages. https://github.com/hashicorp/terraform-website#callouts (Just tested locally and confirmed it works. There is a make website command that will spin up a local copy of the site in docker)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I added the links back. Thank you both.

}
}

template_variable {
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation seems to be a bit off from this line on - let's continue using two spaces to indent as you did above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. Fixed.

}

# Create a new Datadog dashboard - Free layout
resource "datadog_dashboard" "free_dashboard" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation in this example is a little weird as well, let's keep using two spaces for each level of indentation.

- `limit` - (Required)


### Nested `widget``marker` blocks
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing a space here between widget and marker, would result in bad formatting.


Only for widgets of type "timeseries".

Nested `widget``marker` blocks have the following structure:
Copy link
Contributor

Choose a reason for hiding this comment

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

Again missing space between widget and marker.

Copy link
Contributor

@bkabrda bkabrda left a comment

Choose a reason for hiding this comment

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

LGTM now, great work 👍 . Since this is a big one, I'd also like one other approval. @nmuesch could you add your approval as well if you're ok with everything?

@stephen
Copy link

stephen commented Jul 10, 2019

hi, just wanted to say that this has been my #1 datadog feature request and i'm excited to see it happen.

@nmuesch can i provide any motivation to get this reviewed and shipped?

@nmuesch
Copy link
Contributor

nmuesch commented Jul 17, 2019

Hey. Glad to see this and that its being looked forward to! Apologies for my delay here. I'll be taking a look at this shortly and leaving a review!

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.

Thanks again for this! 💜 Tests/Docs especially. I left a few small comments, but the primary ones I think should get addressed before we merge are:

  • The clarification about two build functions per nested schema
  • Can you try to reproduce the issue with the non empty plan when updating the example provided in the docs?

}
}

# Create a new Datadog dashboard - Free layout
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would look cleaner as a separate code block with this comment maybe being an anchor title?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. This looks much better. Thanks for the suggestion. Updated.

"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/zorkian/go-datadog-api"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be aliased to datadog ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

"layout_type": {
Type: schema.TypeString,
Required: true,
Description: "The layout type of the dashboard, either 'free' or 'ordered'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about having a ValidateFunc here to ensure a user provided one of the two expected values - https://www.terraform.io/docs/extend/schemas/schema-behaviors.html#validatefunc

I don't anticipate these options changing soon :)

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 was relying on the upstream API to handle validation in some cases to simplify the resource code, but this could be a nice candidate for ValidateFunc. Updated.

terraformRequest["apm_query"] = []map[string]interface{}{terraformQuery}
} else if datadogRequest.LogQuery != nil {
terraformQuery := buildTerraformApmOrLogQuery(*datadogRequest.LogQuery)

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like something is up here. Running terraform apply on the documented dashboard example multiple times gives me a non empty diff.

For example:

      widget.10.scatterplot_definition.0.xaxis.include_zero: "true" => "1"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That one was super tricky. It seems that all params in TypeMap are stored in the local state as strings regardless of the provided param type. I had to change the type of the surrounding blocks xaxis and yaxis to TypeList to workaround around that. The docs and tests were updated accordingly. Thanks for catching this.

datadog/resource_datadog_dashboard.go Show resolved Hide resolved
}
func validateGroupWidgetLayoutType(val interface{}, key string) (warns []string, errs []error) {
value := val.(string)
switch value {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding a switch despite this being one value only because we plan to support more layout types in the future.

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.

Overall this looks good to me. Thanks for tackling this and the reviews 🙇

One final thing I notice but don't think should block a merge. There is a (likely expected) behavior that when a group of widgets is moved via the UI, the next terraform apply will show a very large diff. Though I don't see a way around this.

@bkabrda
Copy link
Contributor

bkabrda commented Jul 24, 2019

@nmuesch yeah, I don't think we can't help that, but nice catch :)

All right, everything seems to be in line here. I'm merging!

@bkabrda bkabrda merged commit 236dded into DataDog:master Jul 24, 2019
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.

4 participants