newrelic / terraform-provider-newrelic

Terraform provider for New Relic
https://registry.terraform.io/providers/newrelic/newrelic/latest/docs
Mozilla Public License 2.0
200 stars 244 forks source link

feat(dashboards): add support for thresholds in line, table and yAxisRight in line widgets #2672

Closed pranav-new-relic closed 1 month ago

pranav-new-relic commented 1 month ago

This PR adds support for the following attributes to the resource newrelic_one_dashboard

Addresses #2647 and similar other Work Requests received by the team in this regard.

Dependency: newrelic-client-go

Requires changes in https://github.com/newrelic/newrelic-client-go/pull/1144

Manual Testing (Adding this sample piece of code for my reference)

Rigorously tested a multitude of scenarios (by modifying a lot of attributes and their values) using the following configuration

resource "newrelic_one_dashboard" "exampledash" {
  name        = "THRESHOLD TEST DASHBOARD"
  permissions = "public_read_only"

  page {
    name = "New Relic Terraform Example"

    widget_table {
      title  = "Table Widget 1"
      row    = 1
      column = 5
      width  = 4
      height = 4

      nrql_query {
        query = "FROM Transaction SELECT *"
      }

      threshold {
        from        = 1000
        to          = 2000
        column_name = "Table Column 11"
        severity    = "severe"
      }

      threshold {
        from        = 2500
        to          = 3600
        column_name = "Table Column 12"
        severity    = "critical"
      }
    }

    widget_table {
      title  = "Table Widget 2"
      row    = 5
      column = 5
      width  = 4
      height = 3

      nrql_query {
        query = "FROM Transaction SELECT *"
      }

      threshold {
        from        = 5000
        to          = 10000
        column_name = "Table Column 21"
        #         severity    = "critical"
      }

      threshold {
        #         from        = 15000
        to          = 30000
        column_name = "Table Threshold 22"
        severity    = "unavailable"
      }
    }

    widget_line {
      title  = "Line Widget 1"
      row    = 1
      column = 9
      width  = 4
      height = 4

      nrql_query {
        query = "FROM Transaction SELECT average(duration) FACET appName"
      }

      nrql_query {
        query = "FROM Transaction SELECT rate(count(*), 1 minute)"
      }

      is_label_visible = true

      y_axis_right {
        y_axis_right_zero   = true
        y_axis_right_series = ["US", "IN"]
        y_axis_right_min    = 500
        y_axis_right_max    = 100
      }

      threshold {
        from     = 300
        to       = 1800
        name     = "Line Threshold 11"
        severity = "critical"
      }

      threshold {
        from     = 2600
        to       = 3900
        name     = "Line Threshold 12"
        severity = "unavailable"
      }
    }

    widget_line {
      title  = "Line Widget 2"
      row    = 5
      column = 9
      width  = 4
      height = 3

      nrql_query {
        query = "FROM Transaction SELECT average(duration) FACET appName"
      }

      nrql_query {
        query = "FROM Transaction SELECT rate(count(*), 1 minute)"
      }

      #       is_label_visible = true

      y_axis_right {
        y_axis_right_zero   = false
        y_axis_right_series = ["A", "B"]
        #         y_axis_right_min    = 500
        #         y_axis_right_max    = 100
      }

      threshold {
#         from     = 300
#         to       = 1800
        name     = "Line Threshold 21"
        severity = "critical"
      }

      threshold {
        from     = 2600
#         to       = 3900
        name     = "Line Threshold 22"
#         severity = "unavailable"
      }
    }

    widget_billboard {
      title  = "Billboard Widget 1"
      row    = 1
      column = 1
      width  = 4
      height = 4

      nrql_query {
        query = "FROM Transaction SELECT rate(count(*), 1 minute)"
      }

      critical = "10"
      warning  = "20"
    }

    widget_billboard {
      title  = "Billboard Widget 2"
      row    = 5
      column = 1
      width  = 4
      height = 3

      nrql_query {
        query = "FROM Transaction SELECT rate(count(*), 1 minute)"
      }

#       critical = "300"
      warning  = "500"
    }
  }
}
pranav-new-relic commented 1 month ago
image image

intermittent failures of relevant tests (work with the same creds locally), trying again