diff --git a/.gitignore b/.gitignore index 95ffc73..064fef3 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ override.tf.json # IDE .idea/ + +# Development +development/ diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..1c26b47 --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/newrelic/newrelic" { + version = "2.18.0" + constraints = "~> 2.18.0" + hashes = [ + "h1:+WtcDO3S28455QdnakM0EsbSO9uO9FpvC6pPXvlOsD4=", + "zh:08805968cb924655c8b27e64dddb462c977dc8646fc9f4b77904ec34c6a29cc6", + "zh:285dd29eacf069dddf4d3628ae00e209f9d1131bd671d3a9fcfac1dc33df427b", + "zh:359a9501ed7b1df3a94d12ea07b79b5f550329dbdc4f9ea5e7d507bdd97979a9", + "zh:4847da1d793cb6a616b804305227b390bafa87e88171918849969777595d6e1c", + "zh:51cb14f62fd4caa5c735297584814a9b680bd39006eaac59c7d367af1c1eb516", + "zh:5db6a859ad3ec7faaa81e94ca0545741ff8e6fcbbc569e0a50e61f250fd200cf", + "zh:69b0194b31a5f62af870b90d870b1ca4f9625af3a06a9d876adf6419c6cdd8e7", + "zh:706d885aebd1e809ffb6298254667a7bdd5e53394764a62b720f8f77950abd50", + "zh:ade5bf4f3396af578a97f1ec3c6c5b509829568fa21ba19b2c6eba8484370ee1", + "zh:c672d6b28f5c1754d2d798ba8ce8759a06c7941583338df0510afee095def222", + "zh:da30768c39b8841b120d499b122f902638db7b8baae7102cd0c1fc9220fc2111", + "zh:e9c572d26ffe54b0bf323a7ea17361923e6597f6736e51d8c68e4b92e841f788", + "zh:f09481275e2ec27b70b4f782f49249c81358149870111b26f0800cde2751c46c", + "zh:fb52113fa30d1d06c56838663cf87cb6f9be4aafe706c5dedc809480f6d25eff", + ] +} diff --git a/README.md b/README.md index 996eaff..7beaa2b 100644 --- a/README.md +++ b/README.md @@ -13,32 +13,38 @@ data "newrelic_entity" "app_grpc" { } module "grpc_dashboard" { - source = "git::https://github.com/rizalgowandy/terraform-peractio-newrelic?ref=v0.0.2" - - # Replace with your service name. - dashboard_name = "app_grpc" - service_name = "app_grpc" + source = "git::https://github.com/rizalgowandy/terraform-peractio-newrelic?ref=v0.1.0" + # Replace with your account id. + account_id = var.account_id # Replace with your application id. application_id = data.newrelic_entity.app_grpc.application_id - # Replace with your metric name. - event_name = "grpc_performance" + # Replace with your dashboard name, should be unique for your account. + dashboard_name = "app_grpc" + service_name = "app_grpc" + # Replace with your metric name. + event_name = "grpc_performance" + # Help make widget name more feasible with replacing long method name. + # Example: + # "/inventory.v1.Inventory/GetProducts" => "/v1.Inventory/GetProducts" + event_method_substring = "/inventory./" + event_method_replace = "" # Replace with your metric method name. - event_methods = [ + event_methods = [ "/inventory.v1.Inventory/GetProducts", "/inventory.v1.Inventory/CheckStocks", ] } ``` -### Required Event Tags +### Standardized Event Tags -- metric_status -- method -- ops -- code -- err -- err_line -- message +- metric_status => `ENUM('success', 'error', 'expected_error')` +- method => e.g `"/inventory.v1.Inventory/GetProducts"` +- ops => e.g `"service/Inventory.GetProductDetail"` +- code => e.g `'invalid'`, and `'not_found'` +- err => the value of `error.Error()` +- err_line => e.g `"/inventory-mgmt/internal/service/inventory.go:634"` +- message => humanize error message diff --git a/main.tf b/main.tf index bff084f..20f6d25 100644 --- a/main.tf +++ b/main.tf @@ -1,213 +1,674 @@ -resource "newrelic_dashboard" "main" { - title = var.dashboard_name - - filter { - event_types = [ - "Transaction" - ] - attributes = [ - "appName", - "name", - "metric_status", - "method", - "ops", - "code", - "err", - "err_line", - "message", - ] - } +resource "newrelic_one_dashboard" "main" { + name = var.dashboard_name - ##################### - # Standard widgets. - ##################### + page { + name = "Summary" - widget { - title = "Requests per minute" - visualization = "billboard" - nrql = "SELECT rate(count(*), 1 minute) FROM Transaction WHERE appName ='${var.service_name}'" - row = 1 - column = 1 - } + # 1 - widget { - title = "Requests per minute, by transaction" - visualization = "facet_table" - nrql = "SELECT rate(count(*), 1 minute) FROM Transaction WHERE appName ='${var.service_name}' FACET name" - row = 1 - column = 2 - width = 2 - } + widget_billboard { + title = "Requests per minute" + row = 1 + column = 1 + width = 2 - widget { - title = "Metric status percentage" - visualization = "facet_pie_chart" - nrql = "SELECT count(*) FROM ${var.event_name} FACET `metric_status` LIMIT 10 EXTRAPOLATE" - row = 2 - column = 1 - } + nrql_query { + account_id = var.account_id + query = "SELECT rate(count(*), 1 minute) AS 'RPM' FROM Transaction WHERE appName = '${var.service_name}'" + } + } - widget { - title = "Metric status histogram" - visualization = "faceted_line_chart" - nrql = "SELECT count(*) FROM ${var.event_name} FACET `metric_status` LIMIT 10 EXTRAPOLATE TIMESERIES" - row = 2 - column = 2 - } + widget_line { + title = "Requests per minute histogram" + row = 1 + column = 3 + width = 4 - widget { - title = "Method with most errors" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' or metric_status = 'expected_error' FACET `method` LIMIT 10 EXTRAPOLATE" - row = 2 - column = 3 - } + nrql_query { + account_id = var.account_id + query = "SELECT rate(count(*), 1 minute) AS 'RPM' FROM Transaction WHERE appName = '${var.service_name}' TIMESERIES EXTRAPOLATE COMPARE WITH 1 week ago" + } + } - widget { - title = "Error with most occurrence" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' or metric_status = 'expected_error' FACET `err` LIMIT 10 EXTRAPOLATE" - row = 3 - column = 1 - } + widget_table { + title = "Requests per minute by transaction" + row = 1 + column = 7 + width = 6 - widget { - title = "Error code with most occurrence" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' or metric_status = 'expected_error' FACET `code` LIMIT 10 EXTRAPOLATE" - row = 3 - column = 2 - } + nrql_query { + account_id = var.account_id + query = "SELECT rate(count(*), 1 minute) FROM Transaction WHERE appName = '${var.service_name}' FACET name" + } + } - widget { - title = "Human error message with most occurrence" - visualization = "facet_table" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' or metric_status = 'expected_error' FACET `message` LIMIT 10 EXTRAPOLATE" - row = 3 - column = 3 - } + # 2 - widget { - title = "Operation with most errors" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' or metric_status = 'expected_error' FACET `ops` LIMIT 10 EXTRAPOLATE" - row = 4 - column = 1 - } + widget_billboard { + title = "Success rate = success + expected_error" + row = 2 + column = 1 + width = 2 - widget { - title = "Line with most errors" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' or metric_status = 'expected_error' FACET `err_line` LIMIT 10 EXTRAPOLATE" - row = 4 - column = 2 - width = 2 - } + nrql_query { + account_id = var.account_id + query = "SELECT percentage(count(*), WHERE metric_status IN ('success', 'expected_error')) as 'Success Rate' from ${var.event_name}" + } + } - ##################### - # Event widgets. - ##################### + widget_pie { + title = "Metric status percentage" + row = 2 + column = 3 + width = 4 - # First rows. + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} FACET `metric_status` LIMIT 10 EXTRAPOLATE" + } + } - dynamic "widget" { - for_each = var.event_methods + widget_line { + title = "Metric status histogram" + row = 2 + column = 7 + width = 6 - content { - title = "${widget.value} request per minute" - visualization = "billboard" - nrql = "SELECT rate(count(*), 1 minute) FROM ${var.event_name} WHERE method = '${widget.value}'" - row = var.base_row + widget.key * (var.total_column_per_method / 3) - column = 1 + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} FACET `metric_status` EXTRAPOLATE TIMESERIES" + } } - } - dynamic "widget" { - for_each = var.event_methods + # 3 + + widget_billboard { + title = "Error count" + row = 3 + column = 1 + width = 2 - content { - title = "${widget.value} metric status percentage" - visualization = "facet_pie_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE method = '${widget.value}' FACET `metric_status` LIMIT 10 EXTRAPOLATE" - row = var.base_row + widget.key * (var.total_column_per_method / 3) - column = 2 + nrql_query { + account_id = var.account_id + query = "SELECT count(*) as 'Error count' from ${var.event_name} WHERE metric_status IN ('error')" + } } - } - dynamic "widget" { - for_each = var.event_methods + widget_pie { + title = "Error code with most occurrence" + row = 3 + column = 3 + width = 4 - content { - title = "${widget.value} metric status histogram" - visualization = "faceted_line_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE method = '${widget.value}' FACET `metric_status` LIMIT 10 EXTRAPOLATE TIMESERIES" - row = var.base_row + widget.key * (var.total_column_per_method / 3) - column = 3 + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' FACET `code` LIMIT 10 EXTRAPOLATE" + } } - } - # Second rows. + widget_table { + title = "Method with most errors" + row = 3 + column = 7 + width = 6 - dynamic "widget" { - for_each = var.event_methods + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' FACET `method` LIMIT 10 EXTRAPOLATE" + } + } + + # 4 - content { - title = "${widget.value} error with most occurrence" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE method ='${widget.value}' AND metric_status = 'error' or metric_status = 'expected_error' FACET `err` LIMIT 10 EXTRAPOLATE" - row = 1 + var.base_row + widget.key * (var.total_column_per_method / 3) - column = 1 + widget_bar { + title = "Error with most occurrence" + row = 4 + column = 1 + width = 6 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' FACET `err` LIMIT 10 EXTRAPOLATE" + } + } + + widget_bar { + title = "Human error message with most occurrence" + row = 4 + column = 7 + width = 6 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' FACET `message` LIMIT 10 EXTRAPOLATE" + } + } + + # 5 + + widget_bar { + title = "Operation with most errors" + row = 5 + column = 1 + width = 6 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' FACET `ops` LIMIT 10 EXTRAPOLATE" + } } - } - dynamic "widget" { - for_each = var.event_methods + widget_bar { + title = "Line with most errors" + row = 5 + column = 7 + width = 6 - content { - title = "${widget.value} error code with most occurrence" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE method ='${widget.value}' AND metric_status = 'error' or metric_status = 'expected_error' FACET `code` LIMIT 10 EXTRAPOLATE" - row = 1 + var.base_row + widget.key * (var.total_column_per_method / 3) - column = 2 + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' FACET `err_line` LIMIT 10 EXTRAPOLATE" + } } } - dynamic "widget" { - for_each = var.event_methods + page { + name = "Timeline" - content { - title = "${widget.value} human error message with most occurrence" - visualization = "facet_table" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE method ='${widget.value}' AND metric_status = 'error' or metric_status = 'expected_error' FACET `message` LIMIT 10 EXTRAPOLATE" - row = 1 + var.base_row + widget.key * (var.total_column_per_method / 3) - column = 3 + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 1 + (widget_billboard.key * 3) + column = 1 + ((widget_billboard.key % 3) * 4) + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT percentage(count(*), WHERE metric_status IN ('success', 'expected_error')) as 'Success' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 2 + (widget_billboard.key * 3) + column = 1 + ((widget_billboard.key % 3) * 4) + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT rate(count(*), 1 minute) as 'RPM' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 3 + (widget_billboard.key * 3) + column = 1 + ((widget_billboard.key % 3) * 4) + width = 1 + height = 1 + + warning = 1000 + critical = 2000 + + nrql_query { + account_id = var.account_id + query = "SELECT percentile(timer, 95) as ms FROM ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_line" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_line.value, var.event_method_substring, var.event_method_replace) : widget_line.value + row = 1 + floor(widget_line.key / 3) + column = 2 + ((widget_line.key % 3) * 4) + width = 3 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) as 'Attempt', filter(count(*), WHERE metric_status IN ('success', 'expected_error')) as 'Success', filter(count(*), WHERE metric_status IN ('error')) as 'Error' from ${var.event_name} WHERE method = '${widget_line.value}' EXTRAPOLATE TIMESERIES" + } + } } } - # Third rows. + page { + name = "Statistic" + + dynamic "widget_billboard" { + for_each = var.event_methods - dynamic "widget" { - for_each = var.event_methods + content { + title = "Success Rate" + row = 1 + (widget_billboard.key * 1) + column = 1 + width = 2 + height = 3 + + nrql_query { + account_id = var.account_id + query = "SELECT percentage(count(*), WHERE metric_status IN ('success', 'expected_error')) as 'Success' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } - content { - title = "${widget.value} operation with most errors" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE method ='${widget.value}' AND metric_status = 'error' or metric_status = 'expected_error' FACET `ops` LIMIT 10 EXTRAPOLATE" - row = 2 + var.base_row + widget.key * (var.total_column_per_method / 3) - column = 1 + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = "Request per minute" + row = 1 + (widget_billboard.key * 1) + column = 3 + width = 2 + height = 3 + + nrql_query { + account_id = var.account_id + query = "SELECT rate(count(*), 1 minute) as 'RPM' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_line" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_line.value, var.event_method_substring, var.event_method_replace) : widget_line.value + row = 1 + (widget_line.key * 1) + column = 5 + width = 4 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE method = '${widget_line.value}' FACET metric_status EXTRAPOLATE TIMESERIES" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 1 + (widget_billboard.key * 3) + column = 9 + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT percentage(count(*), WHERE metric_status IN ('success', 'expected_error')) as 'Success' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 1 + (widget_billboard.key * 3) + column = 10 + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT percentage(count(*), WHERE metric_status IN ('success')) as 'Real Success' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 1 + (widget_billboard.key * 3) + column = 11 + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT percentage(count(*), WHERE metric_status IN ('expected_error')) as 'Expected Error' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 1 + (widget_billboard.key * 3) + column = 12 + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT percentage(count(*), WHERE metric_status IN ('error')) as 'Error' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 2 + (widget_billboard.key * 3) + column = 9 + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) as 'Success' from ${var.event_name} WHERE method = '${widget_billboard.value}' AND metric_status IN ('success', 'expected_error')" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 2 + (widget_billboard.key * 3) + column = 10 + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) as 'Real Success' from ${var.event_name} WHERE method = '${widget_billboard.value}' AND metric_status IN ('success')" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 2 + (widget_billboard.key * 3) + column = 11 + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) as 'Expected Error' from ${var.event_name} WHERE method = '${widget_billboard.value}' AND metric_status IN ('expected_error')" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 2 + (widget_billboard.key * 3) + column = 12 + width = 1 + height = 1 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) as 'Error' from ${var.event_name} WHERE method = '${widget_billboard.value}' AND metric_status IN ('error')" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 3 + (widget_billboard.key * 3) + column = 9 + width = 1 + height = 1 + + warning = 1000 + critical = 2000 + + nrql_query { + account_id = var.account_id + query = "SELECT average(timer) as 'ms (avg)' FROM ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 3 + (widget_billboard.key * 3) + column = 10 + width = 1 + height = 1 + + warning = 1000 + critical = 2000 + + nrql_query { + account_id = var.account_id + query = "SELECT percentile(timer, 95) as ms FROM ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 3 + (widget_billboard.key * 3) + column = 11 + width = 1 + height = 1 + + warning = 1000 + critical = 2000 + + nrql_query { + account_id = var.account_id + query = "SELECT percentile(timer, 99) as ms FROM ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 3 + (widget_billboard.key * 3) + column = 12 + width = 1 + height = 1 + + warning = 1000 + critical = 2000 + + nrql_query { + account_id = var.account_id + query = "SELECT max(timer) as 'ms (slowest)' FROM ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } } } - dynamic "widget" { - for_each = var.event_methods + page { + name = "Detail" + + # 1 + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 1 + (widget_billboard.key * 3) + column = 1 + width = 2 + height = 3 + + nrql_query { + account_id = var.account_id + query = "SELECT percentage(count(*), WHERE metric_status IN ('success', 'expected_error')) as 'Success' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_billboard" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_billboard.value, var.event_method_substring, var.event_method_replace) : widget_billboard.value + row = 1 + (widget_billboard.key * 3) + column = 3 + width = 2 + height = 3 + + nrql_query { + account_id = var.account_id + query = "SELECT rate(count(*), 1 minute) as 'RPM' from ${var.event_name} WHERE method = '${widget_billboard.value}'" + } + } + } + + dynamic "widget_line" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_line.value, var.event_method_substring, var.event_method_replace) : widget_line.value + row = 1 + (widget_line.key * 3) + column = 5 + width = 4 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) as 'Attempt', filter(count(*), WHERE metric_status IN ('success', 'expected_error')) as 'Success', filter(count(*), WHERE metric_status IN ('error')) as 'Error' from ${var.event_name} WHERE method = '${widget_line.value}' EXTRAPOLATE TIMESERIES" + } + } + } + + + dynamic "widget_line" { + for_each = var.event_methods + + content { + title = var.event_method_substring != "" ? replace(widget_line.value, var.event_method_substring, var.event_method_replace) : widget_line.value + row = 1 + (widget_line.key * 3) + column = 9 + width = 4 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) as 'Attempt' from ${var.event_name} WHERE method = '${widget_line.value}' EXTRAPOLATE TIMESERIES COMPARE WITH 1 WEEK AGO" + } + } + } + + # 2 + + dynamic "widget_pie" { + for_each = var.event_methods + + content { + title = "${var.event_method_substring != "" ? replace(widget_pie.value, var.event_method_substring, var.event_method_replace) : widget_pie.value} - Error code with most occurrence" + row = 2 + (widget_pie.key * 3) + column = 1 + width = 4 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' FACET `code` LIMIT 10 EXTRAPOLATE" + } + } + } + + dynamic "widget_bar" { + for_each = var.event_methods + + content { + title = "${var.event_method_substring != "" ? replace(widget_bar.value, var.event_method_substring, var.event_method_replace) : widget_bar.value} - Error with most occurrence" + row = 2 + (widget_bar.key * 3) + column = 5 + width = 4 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' AND method = '${widget_bar.value}' FACET `err` LIMIT 10 EXTRAPOLATE" + } + } + } + + dynamic "widget_bar" { + for_each = var.event_methods + + content { + title = "${var.event_method_substring != "" ? replace(widget_bar.value, var.event_method_substring, var.event_method_replace) : widget_bar.value} - Human error message with most occurrence" + row = 2 + (widget_bar.key * 3) + column = 9 + width = 4 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' AND method = '${widget_bar.value}' FACET `message` LIMIT 10 EXTRAPOLATE" + } + } + } + + # 3 + + dynamic "widget_bar" { + for_each = var.event_methods + + content { + title = "${var.event_method_substring != "" ? replace(widget_bar.value, var.event_method_substring, var.event_method_replace) : widget_bar.value} - Operation with most errors" + row = 3 + (widget_bar.key * 3) + column = 1 + width = 4 + + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' AND method = '${widget_bar.value}' FACET `ops` LIMIT 10 EXTRAPOLATE" + } + } + } + + dynamic "widget_bar" { + for_each = var.event_methods + + content { + title = "${var.event_method_substring != "" ? replace(widget_bar.value, var.event_method_substring, var.event_method_replace) : widget_bar.value} - Line with most errors" + row = 3 + (widget_bar.key * 3) + column = 5 + width = 8 - content { - title = "${widget.value} line with most errors" - visualization = "facet_bar_chart" - nrql = "SELECT count(*) FROM ${var.event_name} WHERE method ='${widget.value}' AND metric_status = 'error' or metric_status = 'expected_error' FACET `err_line` LIMIT 10 EXTRAPOLATE" - row = 2 + var.base_row + widget.key * (var.total_column_per_method / 3) - column = 2 - width = 2 + nrql_query { + account_id = var.account_id + query = "SELECT count(*) FROM ${var.event_name} WHERE metric_status = 'error' AND method = '${widget_bar.value}' FACET `err_line` LIMIT 10 EXTRAPOLATE" + } + } } } } diff --git a/outputs.tf b/outputs.tf index ba025e4..d69e187 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,4 +1,4 @@ output "dashboard_url" { - value = newrelic_dashboard.main.dashboard_url + value = newrelic_one_dashboard.main.permalink description = "The created dashboard url" } diff --git a/variables.tf b/variables.tf index 85b785b..7d8f00e 100644 --- a/variables.tf +++ b/variables.tf @@ -10,6 +10,10 @@ variable "application_id" { type = number } +variable "account_id" { + type = number +} + variable "event_name" { type = string } @@ -18,12 +22,10 @@ variable "event_methods" { type = list(string) } -variable "base_row" { - type = number - default = 5 +variable "event_method_substring" { + type = string } -variable "total_column_per_method" { - type = number - default = 9 +variable "event_method_replace" { + type = string } \ No newline at end of file diff --git a/versions.tf b/versions.tf index 006ed90..65c22fd 100644 --- a/versions.tf +++ b/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { newrelic = { source = "newrelic/newrelic" - version = "~> 2.15.1" + version = "~> 2.18.0" } } } \ No newline at end of file