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 246 forks source link

BUG: Unable to filter multi-page dashboard #1200

Closed rdhar closed 3 years ago

rdhar commented 3 years ago

Summary

I'm unable to apply any filters on a multi-page newrelic_one_dashboard. This is distinct from #1193 since the suggested workaround is incompatible when dealing with multiple pages.

I believe this to be a significant oversight given that a major component of NR1 dashboards is their innate interactivity: the lack of which is a major gap in reactive monitoring.

Expected Result

Given an NR1 dashboard with multiple pages, each one should be able to FACET filter on their respective page. Since there isn't a way to self-reference resources—addressed in #1193—I can import the dashboard's GUID via newrelic_entity before passing it into the widget's linked_entity_guids = […].

Actual Behaviour

Passing the imported GUID into linked_entity_guids = […] has no effect in filtering any of the dashboard's pages. Even after removing all but one page, there's no recovering it.

(Uninformed) Investigation

Based on NR CLI's newrelic decode output, a regular 1-paged NR1 dashboard's GUID is in the format of <account_id>|VIZ|DASHBOARD|<insights_dashboard_id>.

As soon as another page is added, this format changes to <account_id>|VIZ|DASHBOARD|da:<?>, where I don't know what da: means or what <?>'s source is.

Provider Configuration

terraform {
  required_version = "0.14.6"
  required_providers {
    newrelic = {
      source  = "newrelic/newrelic"
      version = "2.18.0"
    }
  }
}

provider "newrelic" {
  account_id = 123456
  api_key    = "NRAK-OBFUSCATED"
}

Replication Steps

  1. Initialise the above provider configuration.
  2. Copy/paste the code snippet attached below.
  3. To workaround existing boot-strap issue, comment out the data import and both of the lines starting with linked_entity_guids before terraform apply.
  4. Once the (uniquely named) dashboard is created, un-comment the aforementioned lines and run terraform apply again in order to pass the dashboard's GUID into the widgets' linked_entity_guids = […].
  5. On the dashboard, observe that the FACETs are unable to filter.
Toggle view of code snippet… ```tf data "newrelic_entity" "dashboard_example" { name = "Example Dashboard" type = "DASHBOARD" } resource "newrelic_one_dashboard" "dashboard_example" { name = "Example Dashboard" page { name = "Page 1" widget_pie { title = "This is on the first page" row = 1 column = 1 nrql_query { account_id = 123456 query = "FROM Transaction SELECT count(*) FACET appName" } linked_entity_guids = [data.newrelic_entity.dashboard_example.guid] } } page { name = "Page 2" widget_pie { title = "This is on the second page" row = 1 column = 1 nrql_query { account_id = 123456 query = "FROM Transaction SELECT count(*) FACET appName" } linked_entity_guids = [data.newrelic_entity.dashboard_example.guid] } } } ```

Thank you.

rdhar commented 3 years ago

Per the community forum, it appears that each page of a dashboard can be queried individually with the following GraphQL:

{
  actor {
    entity(guid: "<dashboard_guid>") {
      ... on DashboardEntity {
        pages {
          guid
          name
        }
      }
      name
    }
  }
}

As such, it should be possible to source the same value via the provider's newrelic_entity data.

Although this doesn’t address the underlying bootstrap issue—i.e., in order to build the dashboard, I need the dashboard to already exist—it might still offer a feasible workaround in the interim, until a more permanent resolution is found in #1193.

Will update this upon building a successful prototype.

jthurman42 commented 3 years ago

Thank you for your detailed instructions. I was able to reproduce this, and found a few compounding issues, and a more detailed work-around.

Using the following GraphQL to search for a two page dashboard created per the initial snippet:

{
  actor {
    entitySearch(queryBuilder: {name: "jt-test-multi-page-1200", type: DASHBOARD}) {
      results {
        entities {
          guid
          name
        }
      }
    }
  }
}

Returns:

{
  "data": {
    "actor": {
      "entitySearch": {
        "results": {
          "entities": [
            {
              "guid": "MjUyMDUyOHxWSVp8REFTSEJPQVJEfGRhOjExMjU2Mg",
              "name": "jt-test-multi-page-1200"
            },
            {
              "guid": "MjUyMDUyOHxWSVp8REFTSEJPQVJEfDE3MDUxMzU",
              "name": "jt-test-multi-page-1200 / Page 1"
            },
            {
              "guid": "MjUyMDUyOHxWSVp8REFTSEJPQVJEfDE3MDUxMzY",
              "name": "jt-test-multi-page-1200 / Page 2"
            }
          ]
        }
      }
    }
  }
}

So, based on this I tested with the following HCL to search for the entity.

data "newrelic_entity" "dashboard_example" {
  name = "jt-test-multi-page-1200 / Page 1"
  type = "DASHBOARD"
}

The name format was ${dashboard name} / ${page name}, then using linked_entity_guids = [ data.newrelic_entity.dashboard_example.guid ] worked as expected.

@rdhar if you can verify this works for you as well, then I'll update the work-around in #1193 with another example, and we can close this out.

rdhar commented 3 years ago

This is terrific! And co-incidentally, I came across the same resolution albeit in a much dumber way:

image

Seeing this pattern—as you described ${dashboard_name} / ${page_name}—I gave it a shot and was surprised it worked just as expected via data.newrelic_entity. Absolute madness.

Huge thanks for taking the time to address, really appreciate it. More than happy to see it closed, as #1193 supersedes this in terms of figuring out a way to self-reference dashboard pages during generation.

Thank you.