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 nine more widgets #2161

Closed
wants to merge 60 commits into from

Conversation

dashashifrina
Copy link
Contributor

@dashashifrina dashashifrina commented Oct 26, 2023

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

Previous PR:

Changes

  • Add support for:
    • distribution
    • hostmap
    • topology map
    • heatmap
    • log stream
    • slo
    • run workflow
    • list stream
    • scatterplot
  • 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" "test_powerpack" {
  name        = "Sample Powerpack"
  tags        = ["tag:foo1", "tag:foo2"]
  description = "Test Powerpack 2"

  template_variables {
    defaults = ["defaults"]
    name     = "datacenter"
  }
  widget {
    topology_map_definition {
      request {
        request_type = "topology"
        query {
          filters     = ["env:prod", "datacenter:*"]
          service     = "adb-1239307641635657.17.azuredatabricks.net"
          data_source = "service_map"
        }
      }
      title       = "Widget Title"
      title_size  = "12"
      title_align = "center"
      custom_link {
        link           = "https://app.datadoghq.com/dashboard/lists"
        is_hidden      = true
        override_label = "logs"
      }
    }
  }
  widget {
    distribution_definition {
      title       = "Avg of system.cpu.user over account:prod by service,account"
      title_align = "left"
      title_size  = "16"
      show_legend = "true"
      legend_size = "2"
      request {
        q = "avg:system.cpu.user{account:prod} by {service,account}"
        style {
          palette = "purple"
        }
      }
    }
  }
  widget {
    distribution_definition {
      title       = "Avg of system.cpu.user over account:prod by service,account"
      title_align = "left"
      title_size  = "16"
      show_legend = "true"
      legend_size = "2"
      request {
        apm_stats_query {
          service     = "service"
          env         = "env"
          primary_tag = "tag:*"
          name        = "name"
          row_type    = "resource"
        }
      }
    }
  }
  widget {
    hostmap_definition {
      request {
        fill {
          q = "avg:system.load.1{*} by {host}"
        }
        size {
          q = "avg:memcache.uptime{*} by {host}"
        }
      }
      node_type       = "container"
      group           = ["host", "region"]
      no_group_hosts  = true
      no_metric_hosts = true
      scope           = ["region:us-east-1", "aws_account:727006795293"]
      style {
        palette      = "yellow_to_green"
        palette_flip = true
        fill_min     = "10"
        fill_max     = "20"
      }
      title = "Widget Title"
    }
  }
  widget {
    scatterplot_definition {
      request {
        x {
          q          = "avg:system.cpu.user{*} by {service, account}"
          aggregator = "max"
        }
        y {
          q          = "avg:system.mem.used{*} by {service, account}"
          aggregator = "min"
        }
      }
      color_by_groups = ["account", "apm-role-group"]
      xaxis {
        include_zero = true
        label        = "x"
        min          = "1"
        max          = "2000"
        scale        = "pow"
      }
      yaxis {
        include_zero = false
        label        = "y"
        min          = "5"
        max          = "2222"
        scale        = "log"
      }
      title = "Widget Title"
    }
  }
  widget {
    heatmap_definition {
      request {
        q = "avg:system.load.1{env:staging} by {account}"
        style {
          palette = "warm"
        }
      }
      event {
        q              = "env:staging"
        tags_execution = "and"
      }
      yaxis {
        min          = 1
        max          = 2
        include_zero = true
        scale        = "sqrt"
      }
      title = "Widget Title"
    }
  }
  widget {
    log_stream_definition {
      title = "Log Stream"
      title_align = "right"
      title_size = "16"
      show_message_column = "true"
      message_display = "expanded-md"
      query = "status:error env:prod"
      show_date_column = "true"
      indexes = ["main"]
      columns = ["core_host", "core_service"]
      sort {
        column = "time"
        order = "desc"
      }
    }
    widget_layout {
      height = 5
      width = 5
      x = 5
      y = 5
    }
  }
  widget {
    run_workflow_definition {
      title       = "My workflow widget"
      title_size  = "13"
      title_align = "left"
      workflow_id = "2e055f16-8b6a-4cdd-b452-17a34c44b160"
      input {
        name  = "env"
        value = "$Env.value"
      }
      input {
        name  = "Foo"
        value = "$Env"
      }
    }
  }
  widget {
    service_level_objective_definition {
      time_windows = ["90d","previous_week","global_time"]
      title_size = "16"
      show_error_budget = true
      title = ""
      title_align = "center"
      slo_id = "b4c7739b2af25f9d947f828730357832"
      view_mode = "both"
      view_type = "detail"
      global_time_target = "99.0"
      additional_query_filters = "!host:excluded_host"
    }
  }
  widget {
    list_stream_definition {
      title = "List Stream 1"
      title_align = "right"
      title_size = "16"
      request {
        response_format = "event_list"
        query {
          data_source = "rum_issue_stream"
        }
        columns {
          field = "details"
          width = "auto"
        }
      }
      request {
        response_format = "event_list"
        query {
          data_source = "apm_issue_stream"
          query_string = "env: prod"
          indexes = ["timestamp", "message"]
        }
        columns {
          field = "details"
          width = "auto"
        }
      }
    }
    widget_layout {
      height = 5
      width = 5
      x = 5
      y = 5
    }
  }
  widget {
    scatterplot_definition {
      title_size = "16"
      yaxis {
        scale = "log"
        include_zero = false
        min = "1"
        label = "mem (Gib)"
      }
      title_align = "right"
      color_by_groups = ["app"]
      xaxis {
        scale = "log"
        max = "100"
        min = "0"
        label = "cpu (%)"
        include_zero = false
      }
      title = "system.mem.used and system.cpu.user by service,team,app colored by app"
      request {
        y {
          q = "avg:system.mem.used{env:prod} by {service, team, app}"
          aggregator = "avg"
        }
        x {
          q = "avg:system.cpu.user{account:prod} by {service, team, app}"
          aggregator = "avg"
        }
      }
      custom_link {
        link = "https://app.datadoghq.com/dashboard/lists"
        label = "Test Custom Link label"
      }
      custom_link {
        link = "https://app.datadoghq.com/dashboard/lists"
        is_hidden = true
        override_label = "logs"
      }
    }
  }
}

@dashashifrina dashashifrina marked this pull request as ready for review November 2, 2023 17:03
@dashashifrina dashashifrina requested a review from a team as a code owner November 2, 2023 17:03
@dashashifrina dashashifrina requested a review from a team as a code owner November 6, 2023 16:22
@maycmlee
Copy link
Contributor

maycmlee commented Nov 6, 2023

Created DOCS-6650 for review.

estherk15
estherk15 previously approved these changes Nov 7, 2023
Copy link

@estherk15 estherk15 left a comment

Choose a reason for hiding this comment

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

Confirmed with Dashboard team that Event Stream and Log Stream are now supported under the List widget, Event Timeline is supported under Timeseries widget. And Scatterplot should be Scatter Plot if matching to the UI.

Base automatically changed from dasha.shifrina/powerpacks-pt-2 to master November 14, 2023 16:08
@nkzou nkzou dismissed estherk15’s stale review November 14, 2023 16:08

The base branch was changed.

@dashashifrina dashashifrina force-pushed the dasha.shifrina/powerpacks-pt-3 branch from ed71ceb to cdb0fa4 Compare November 14, 2023 16:29
@dashashifrina dashashifrina force-pushed the dasha.shifrina/powerpacks-pt-3 branch from cdb0fa4 to f529fff Compare November 14, 2023 17:19
@dashashifrina dashashifrina requested review from a team and woodb and removed request for a team November 14, 2023 17:42
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "The definition for an Log Stream widget.",
Copy link

Choose a reason for hiding this comment

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

nitpick(typo):

Suggested change
Description: "The definition for an Log Stream widget.",
Description: "The definition for a Log Stream widget.",

Comment on lines +706 to +712
for _, v := range []string{"formula"} {
// Properties listed above are defined as single, but API Spec expects a plural name
if widgetDefRequest[v] != nil {
widgetDefRequest[v+"s"] = widgetDefRequest[v]
delete(widgetDefRequest, v)
}
}
Copy link

Choose a reason for hiding this comment

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

suggestion: I think the intent is that we'll have more than just one value here to pluralize in the future, but it might be safer for future developers to be more explicit here (example below), so that something like query->querys doesn't happen (i.e. we'll likely need some kinda lookup of singular->plural here at some point)

Suggested change
for _, v := range []string{"formula"} {
// Properties listed above are defined as single, but API Spec expects a plural name
if widgetDefRequest[v] != nil {
widgetDefRequest[v+"s"] = widgetDefRequest[v]
delete(widgetDefRequest, v)
}
}
// "formulas" is the expected form per the spec
if widgetDefRequest["formula"] != nil {
widgetDefRequest["formulas"] = widgetDefRequest[v]
delete(widgetDefRequest, "formula")
}

delete(widgetDefRequest, v)
}
}
if widgetType != "topology_map" && widgetDefRequest["query"] != nil {
Copy link

Choose a reason for hiding this comment

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

question: Why is topology_map specifically excluded here?

The following types have a query option in their requests:

[
  "distribution",
  "funnel",
  "geomap",
  "list_stream",
  "slo_list",
  "topology_map"
]

I think I might have asked this before in a previous review but can't seem to remember the reason

return nil, diags
}
// Distribution/change/heatmap widgets have a "requests" field, while API Spec has a "request" field
// Here we set the "requests" field and remove "request"
Copy link

Choose a reason for hiding this comment

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

suggestion(minor):

Suggested change
// Here we set the "requests" field and remove "request"

Comment on lines +776 to +782
for _, v := range []string{"event", "custom_link", "input"} {
// Properties listed above are defined as single, but API Spec expects a plural name
if widgetDef[v] != nil {
widgetDef[v+"s"] = widgetDef[v]
delete(widgetDef, v)
}
}
Copy link

Choose a reason for hiding this comment

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

suggestion(non-blocking): Similar to a suggestion above, we may want to consider remapping properties w/ some kinda map here, rather than relying the on the "s"-suffix relation

Comment on lines +833 to +839
for _, v := range []string{"custom_links", "inputs", "events"} {
// Properties listed above are defined as plural for the API Spec and need to be converted back to single values for TF
if widgetDef[v] != nil {
widgetDef[v[:len(v)-1]] = widgetDef[v]
delete(widgetDef, v)
}
}
Copy link

Choose a reason for hiding this comment

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

suggestion(non-blocking): Similar to a suggestion above, we may want to consider remapping properties w/ some kinda map here, rather than relying the on the "s"-suffix relation

@nkzou nkzou closed this Dec 11, 2023
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.

5 participants