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

[newrelic_one_dashboard_raw] messes up widget order during insertion/deletion #1452

Closed
tommyongsf opened this issue Oct 1, 2021 · 7 comments

Comments

@tommyongsf
Copy link

Terraform Version

Terraform v1.0.0 . Also tested with the latest v1.0.8.

Affected Resource(s)

  • newrelic_one_dashboard_raw

Terraform Configuration

Terraform NewRelic Provider: 2.26.0 (latest)

resource "newrelic_one_dashboard_raw" "one_dashboard_raw_test" {
  name  = "One Dashboard Raw Test"
  count = 1

  page {
    name = "Page Test"

    widget {
      visualization_id = "viz.table"
      title            = "Table"
      row              = 101
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "nrqlQueries":[
          {
            "accountId": ${var.newrelic_query_account_id},
            "query": "SELECT COUNT(*) FROM Transaction"
          }
        ]
      }
      EOT
    }

    widget {
      visualization_id = "viz.line"
      title            = "Line"
      row              = 201
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "nrqlQueries":[
          {
            "accountId": ${var.newrelic_query_account_id},
            "query": "SELECT COUNT(*) FROM Transaction"
          }
        ]
      }
      EOT
    }

    widget {
      visualization_id = "viz.markdown"
      title            = "Markdown"
      row              = 301
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "text": "helloworld"
      }
      EOT
    }

    widget {
      visualization_id = "viz.table"
      title            = "Table"
      row              = 401
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "nrqlQueries":[
          {
            "accountId": ${var.newrelic_query_account_id},
            "query": "SELECT COUNT(*) FROM Transaction"
          }
        ]
      }
      EOT
    }

    widget {
      visualization_id = "viz.line"
      title            = "Line"
      row              = 501
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "nrqlQueries":[
          {
            "accountId": ${var.newrelic_query_account_id},
            "query": "SELECT COUNT(*) FROM Transaction"
          }
        ]
      }
      EOT
    }

    widget {
      visualization_id = "viz.markdown"
      title            = "Markdown"
      row              = 601
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "text": "helloworld"
      }
      EOT
    }

    widget {
      visualization_id = "viz.table"
      title            = "Table"
      row              = 701
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "nrqlQueries":[
          {
            "accountId": ${var.newrelic_query_account_id},
            "query": "SELECT COUNT(*) FROM Transaction"
          }
        ]
      }
      EOT
    }

    widget {
      visualization_id = "viz.line"
      title            = "Line"
      row              = 801
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "nrqlQueries":[
          {
            "accountId": ${var.newrelic_query_account_id},
            "query": "SELECT COUNT(*) FROM Transaction"
          }
        ]
      }
      EOT
    }

    widget {
      visualization_id = "viz.markdown"
      title            = "Markdown"
      row              = 901
      column           = 1
      width            = 12
      height           = 6

      configuration = <<EOT
      {
        "text": "helloworld"
      }
      EOT
    }
  }
}

Actual Behavior

  • Errors shown when a widget is deleted/created among a list of widgets of different types.

Expected Behavior

  • Only the widget to be deleted/created shows changes, the rest should stay the same.

Steps to Reproduce

  • run terraform apply on the tf code above (in Terraform Configuration section) -> create 9 widgets of different types (viz.table, viz.line, viz.markdown) on the same page.
  • delete the first widget.
  • run terraform plan -> observe that the order of the widgets has been shifted:
~ resource "newrelic_one_dashboard_raw" "one_dashboard_raw_test" {
        id          = "MTM5Njk5OXxWSVp8REFTSEJPQVJEfGRhOjM4NjgzNA"
        name        = "One Dashboard Raw Test"
        # (4 unchanged attributes hidden)

      ~ page {
            name = "Page Test"
            # (1 unchanged attribute hidden)

          ~ widget {
                id               = "54775248"
              ~ row              = 101 -> 201
              ~ title            = "Table" -> "Line"
              ~ visualization_id = "viz.table" -> "viz.line"
                # (4 unchanged attributes hidden)
            }
          ~ widget {
              ~ configuration    = jsonencode(
                  ~ {
                      - nrqlQueries = [
                          - {
                              - accountId = 1226690
                              - query     = "SELECT COUNT(*) FROM Transaction"
                            },
                        ] -> null
                      + text        = "helloworld"
                    }
                )
                id               = "54775249"
              ~ row              = 201 -> 301
              ~ title            = "Line" -> "Markdown"
              ~ visualization_id = "viz.line" -> "viz.markdown"
                # (3 unchanged attributes hidden)
            }
  • run terrafrom apply
╷
│ Error: maximum retries reached: Operation on dashboard entity failed with guid:MTM5Njk5OXxWSVp8REFTSEJPQVJEfGRhOjM4NjgzNA with cause: Error 500 calling Insights with url https://insights-api.service.nr-ops.net/rpm_api/1/accounts/1396999/collections: {"status":"500","error":"Internal Server Error"}
│
│   with newrelic_one_dashboard_raw.one_dashboard_raw_test[0],
│   on dashboard_raw_test.tf line 1, in resource "newrelic_one_dashboard_raw" "one_dashboard_raw_test":
│    1: resource "newrelic_one_dashboard_raw" "one_dashboard_raw_test" {
│
╵

Important factors

  • It happens only when there are a lot of widgets of different types on the same page. Able to reproduce at 9 widgets of different types (viz.table, viz.line, viz.markdown).
  • The theory is that the current newrelic_one_dashboard_raw does not manage the widget order correctly. Hence an insertion/deletion would result in the order being messed up. When the API is sent, NewRelic doesn't know how to handle / doesn't allow a big change in widget types, then it throws out error.
  • A possible fix is to have Page and Widget to be separated resources. So that the resource coordinates are managed accurately. This was suggested in [One Dashboard] Page, Widget to be a resource, instead of being nested in newrelic_one_dashboard / newrelic_one_dashboard_raw #1391. Please kindly prioritize this issue.
@kidk kidk added the pinned label Oct 3, 2021
@kidk
Copy link
Contributor

kidk commented Oct 5, 2021

Thanks for the detailed report @tommyforlini

We'll keep this in mind when redesigning the dashboard resource. We'll explore if there's something we can do in the meantime.

@kidk kidk added this to the New dashboard resource milestone Mar 3, 2022
@kidk kidk added the bug Something isn't working label Mar 9, 2022
@guhcampos
Copy link

I'm getting a similar behavior with newrelic_one_dashboard as well, even without modifying anything between applies. It might be related to this. Applying the same terraform config without changing anything issues modifications like these, everytime:

          ~ widget_billboard {
              ~ column   = 1 -> 3
                id       = "72339701"
              ~ row      = 5 -> 4
              ~ title    = "#REDACTED#"
                # (4 unchanged attributes hidden)

              ~ nrql_query {
                  ~ query      = <<-EOT
                                FROM Metric
                                SELECT clamp_max((count(newrelic.sli.valid) - count(newrelic.sli.bad)) / count(newrelic.sli.valid) * 100, 100)
                      -         AS 'Availability' WHERE sli.id = '216029'
                      -         SINCE 24 HOURS AGO UNTIL 2 MINUTES AGO
                      +         AS 'Disponibilidade' WHERE sli.id = '192210'
                      +         SINCE 1 MONTH AGO UNTIL 2 MINUTES AGO
                    EOT
                    # (1 unchanged attribute hidden)
                }
            }

            # (7 unchanged blocks hidden)
        }

Looks like the widget ids get recycled at random, instead of being preserved between calls.

@melumuccu
Copy link

For now, I use "ignore_changes" in "lifecycle".
https://www.terraform.io/language/meta-arguments/lifecycle#ignore_changes

This is the only thing I can come up with.

@kidk
Copy link
Contributor

kidk commented Oct 6, 2022

Are you still experiencing this with latest version? There's been some changes on the API and Terraform side to improve this issue.

cc @melumuccu @guhcampos @tommyongsf

We also recently added support for json dashboards: #2044

@NSSPKrishna
Copy link
Member

We haven’t heard back from you in a long time so we will close the ticket. If you feel this is still a valid request or bug, feel free to create a new issue.

@18jwong
Copy link

18jwong commented May 1, 2024

I'm getting a similar behavior with newrelic_one_dashboard as well, even without modifying anything between applies. It might be related to this. Applying the same terraform config without changing anything issues modifications like these, everytime:

          ~ widget_billboard {
              ~ column   = 1 -> 3
                id       = "72339701"
              ~ row      = 5 -> 4
              ~ title    = "#REDACTED#"
                # (4 unchanged attributes hidden)

              ~ nrql_query {
                  ~ query      = <<-EOT
                                FROM Metric
                                SELECT clamp_max((count(newrelic.sli.valid) - count(newrelic.sli.bad)) / count(newrelic.sli.valid) * 100, 100)
                      -         AS 'Availability' WHERE sli.id = '216029'
                      -         SINCE 24 HOURS AGO UNTIL 2 MINUTES AGO
                      +         AS 'Disponibilidade' WHERE sli.id = '192210'
                      +         SINCE 1 MONTH AGO UNTIL 2 MINUTES AGO
                    EOT
                    # (1 unchanged attribute hidden)
                }
            }

            # (7 unchanged blocks hidden)
        }

Looks like the widget ids get recycled at random, instead of being preserved between calls.

I didn't have the same issue as OP, but I had the same issue as @guhcampos .

The solution is that widgets needs to be ordered primarily by row, and then secondarily by col. This will stop "flapping" changes in TF plans that never actually get applied.

@FlareLine
Copy link

This is still occurring with newrelic_one_dashboard in the latest version of the provider. Could we please get some eyes over #2531 and some fixes put in place? My team generates dashboards and pages dynamically, so re-ordering the Terraform itself is not a solution for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants