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

[datadog_powerpacks] Implement support for basic widgets #2157

Merged
merged 20 commits into from
Nov 3, 2023

Conversation

dashashifrina
Copy link
Contributor

@dashashifrina dashashifrina commented Oct 23, 2023

This pull request implements the first part of the support for the powerpack resource in Terraform.

Unfortunately, we can't immediately add all widgets since we do not validate powerpacks widgets in the public API spec. As a result, we have to manually do some validation for each new widget type. I initially tried to add all widgets, but the PR got unreasonably large, so I opted to split it out into several parts. This first part is the simplest widgets, which don't have any nested configurations. Widgets with nested configurations require extra validation which I will add on in the following PRs.

Most of the changes in this PR are cassettes and I opted to create a separate test file for each new widget.

Changes

  • Add powerpack resource and support for:
    • alert_graph
    • check_status
    • free_text
    • iframe
    • image
    • note
    • servicemap
  • Add test and recorded cassettes for all the widgets listed above.
  • Add doc.

How to test:

  1. Build the provider locally.
  2. Try this powerpack resource with all the supported widgets:
resource "datadog_powerpack" "foo2" {
    name = "Sample Powerpack"
    tags = ["tag:foo1", "tag:foo2"]
    description = "Test Powerpack 2"

  template_variables {
    defaults = ["defaults"]
    name     = "datacenter"
  }
    widget {
      note_definition {
        content          = "note widget"
        background_color = "blue"
      }
      widget_layout {
        height = 12
        width = 6
        x = 5
        y = 5
      }
    }
    widget {
      free_text_definition {
        text       = "free text content"
        color      = "#d00"
        font_size  = "36"
        text_align = "left"
      }
    }
    widget {
      image_definition {
        url    = "https://google.com"
        sizing = "fit"
        margin = "small"
      }
    }
  widget {
    iframe_definition {
      url = "http://google.com"
    }
  }

  widget {
    alert_graph_definition {
      alert_id  = "895605"
      viz_type  = "timeseries"
      title     = "Widget Title"
      title_align = "center"
      title_size = "20"
    }
  }

  widget {
    servicemap_definition {
      service     = "master-db"
      filters     = ["env:prod"]
      title       = "env: prod, datacenter:dc1, service: master-db"
      title_size  = "16"
      title_align = "left"
    }
  }
  widget {
    check_status_definition {
      check     = "aws.ecs.agent_connected"
      grouping  = "cluster"
      group_by  = ["account", "cluster"]
      tags      = ["account:demo", "cluster:awseb-ruthebdog-env-8-dn3m6u3gvk"]
      title     = "Widget Title!!"
    }
  }
  widget {
    note_definition {
      content          = "note widget"
      background_color = "blue"
    }
  }
}

@dashashifrina dashashifrina requested a review from a team as a code owner October 23, 2023 21:17
@dashashifrina dashashifrina changed the title ppk tf support for basic widgets [datadog_powerpacks] Implement support for basic widgets Oct 24, 2023
@dashashifrina dashashifrina requested a review from a team as a code owner October 24, 2023 00:22
@dashashifrina dashashifrina marked this pull request as draft October 24, 2023 00:22
@dashashifrina dashashifrina marked this pull request as ready for review October 24, 2023 02:13
@drichards-87
Copy link
Contributor

Created DOCS-6533 for the Docs Team editorial review.

Copy link

@woodb woodb left a comment

Choose a reason for hiding this comment

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

First pass on the data/tests looks great! 🙌

I had one question on potentially tweaking one of the tests for consideration

woodb
woodb previously approved these changes Oct 26, 2023
Copy link

@woodb woodb left a comment

Choose a reason for hiding this comment

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

lgtm wrt @datadog/dashboards-backend side of things 🙌

datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved
datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved

Choose a reason for hiding this comment

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

I don't know how much control you have over this page, I noticed the note about the schema being generated by tfplugindocs, but some of the descriptions for the widgets don't match the UI:

  • Ln 71 Service Summary widget
  • Ln 74 Pie Chart widget
  • Ln 76 Top List widget
  • Ln 78 I'm not sure about the Trace Service widget, is this supposed to be the Profiler Flame graph widget?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@estherk15 I believe I can manually edit the values after they're autogenerated without any issues. @skarimo is that correct? I'll make the adjustments.

Ln 71 servicemap -> this matches the Service Map widget type, no? (src)
Ln 74 sunburst -> this matches Pie Chart, will fix. [src]
Ln 76 toplist -> this matches Top List, will fix. [src]
Ln 78 trace_service -> this matches Service Summary widget type. [src]

Copy link
Member

Choose a reason for hiding this comment

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

You are correct. Looks like we can use display name in the description as well to clear things up but lets do that in a separate pr as this re-uses schemas from the dashboard resource and we would be modifying that as well with these changes. The descriptions used in the docs come from its schema, for example: https://github.com/DataDog/terraform-provider-datadog/blob/master/datadog/resource_datadog_dashboard.go#L930

estherk15
estherk15 previously approved these changes Oct 30, 2023
@dashashifrina dashashifrina dismissed stale reviews from estherk15 and woodb via bc687a6 October 31, 2023 16:52
@dashashifrina dashashifrina requested a review from skarimo October 31, 2023 17:03
estherk15
estherk15 previously approved these changes Oct 31, 2023
Copy link
Member

@skarimo skarimo left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes! Left a few minor nits but otherwise this looks great!

apiInstances := providerConf.DatadogApiInstances
auth := providerConf.Auth

err := utils.Retry(2, 10, func() error {
Copy link
Member

Choose a reason for hiding this comment

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

Could we move the retry into the for loop. I fixed this up earlier this week here for the other resources: #2166

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

x := dimensions["x"].(int64)
y := dimensions["y"].(int64)
widgetLayout = datadogV2.NewPowerpackInnerWidgetLayout(height, width, x, y)
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} else {
} else if strings.HasSuffix(widgetType, "_definition") {

skarimo
skarimo previously approved these changes Nov 2, 2023
datadog/resource_datadog_powerpack.go Outdated Show resolved Hide resolved
@skarimo skarimo merged commit 77f9497 into master Nov 3, 2023
8 checks passed
@skarimo skarimo deleted the dasha.shifrina/powerpacks-pt-1 branch November 3, 2023 13:30
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.

6 participants