Skip to content

Commit

Permalink
Merge pull request #23 from dasmeta/DMVP-5378-main-k8s-dashboard
Browse files Browse the repository at this point in the history
feat(DMVP-5378): Refactored ingress block
  • Loading branch information
viktoryathegreat authored Nov 13, 2024
2 parents dbedce6 + f177e7a commit 05c8d82
Show file tree
Hide file tree
Showing 59 changed files with 1,512 additions and 70 deletions.
10 changes: 9 additions & 1 deletion modules/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,23 @@ module "this" {
| <a name="module_block_sla"></a> [block\_sla](#module\_block\_sla) | ./modules/blocks/sla | n/a |
| <a name="module_container_cpu_widget"></a> [container\_cpu\_widget](#module\_container\_cpu\_widget) | ./modules/widgets/container/cpu | n/a |
| <a name="module_container_memory_widget"></a> [container\_memory\_widget](#module\_container\_memory\_widget) | ./modules/widgets/container/memory | n/a |
| <a name="module_container_network_traffic_widget"></a> [container\_network\_traffic\_widget](#module\_container\_network\_traffic\_widget) | ./modules/widgets/container/network-traffic | n/a |
| <a name="module_container_network_transmit_widget"></a> [container\_network\_transmit\_widget](#module\_container\_network\_transmit\_widget) | ./modules/widgets/container/network-transmit | n/a |
| <a name="module_container_network_widget"></a> [container\_network\_widget](#module\_container\_network\_widget) | ./modules/widgets/container/network | n/a |
| <a name="module_container_replicas_widget"></a> [container\_replicas\_widget](#module\_container\_replicas\_widget) | ./modules/widgets/container/replicas | n/a |
| <a name="module_container_request_count_widget"></a> [container\_request\_count\_widget](#module\_container\_request\_count\_widget) | ./modules/widgets/container/request-count | n/a |
| <a name="module_container_response_time_widget"></a> [container\_response\_time\_widget](#module\_container\_response\_time\_widget) | ./modules/widgets/container/response-time | n/a |
| <a name="module_container_restarts_widget"></a> [container\_restarts\_widget](#module\_container\_restarts\_widget) | ./modules/widgets/container/restarts | n/a |
| <a name="module_ingress_connections_widget"></a> [ingress\_connections\_widget](#module\_ingress\_connections\_widget) | ./modules/widgets/ingress/connections | n/a |
| <a name="module_ingress_cpu_widget"></a> [ingress\_cpu\_widget](#module\_ingress\_cpu\_widget) | ./modules/widgets/ingress/cpu | n/a |
| <a name="module_ingress_latency_widget"></a> [ingress\_latency\_widget](#module\_ingress\_latency\_widget) | ./modules/widgets/ingress/latency | n/a |
| <a name="module_ingress_memory_widget"></a> [ingress\_memory\_widget](#module\_ingress\_memory\_widget) | ./modules/widgets/ingress/memory | n/a |
| <a name="module_ingress_request_count_widget"></a> [ingress\_request\_count\_widget](#module\_ingress\_request\_count\_widget) | ./modules/widgets/ingress/request-count | n/a |
| <a name="module_ingress_request_rate_widget"></a> [ingress\_request\_rate\_widget](#module\_ingress\_request\_rate\_widget) | ./modules/widgets/ingress/request-rate | n/a |
| <a name="module_ingress_response_time_widget"></a> [ingress\_response\_time\_widget](#module\_ingress\_response\_time\_widget) | ./modules/widgets/ingress/response-time | n/a |
| <a name="module_logs_count_widget"></a> [logs\_count\_widget](#module\_logs\_count\_widget) | ./modules/widgets/logs/count | n/a |
| <a name="module_logs_error_rate_widget"></a> [logs\_error\_rate\_widget](#module\_logs\_error\_rate\_widget) | ./modules/widgets/logs/error-rate | n/a |
| <a name="module_logs_warning_rate_widget"></a> [logs\_warning\_rate\_widget](#module\_logs\_warning\_rate\_widget) | ./modules/widgets/logs/warning-rate | n/a |
| <a name="module_pod_cpu_widget"></a> [pod\_cpu\_widget](#module\_pod\_cpu\_widget) | ./modules/widgets/pod/cpu | n/a |
| <a name="module_text_title"></a> [text\_title](#module\_text\_title) | ./modules/widgets/text/title | n/a |
| <a name="module_text_title_with_collapse"></a> [text\_title\_with\_collapse](#module\_text\_title\_with\_collapse) | ./modules/widgets/text/title-with-collapse | n/a |
| <a name="module_text_title_with_link"></a> [text\_title\_with\_link](#module\_text\_title\_with\_link) | ./modules/widgets/text/title-with-link | n/a |
Expand Down
18 changes: 15 additions & 3 deletions modules/dashboard/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ locals {
# default values from module and provided from outside
widget_default_values = merge(
{
period = 3 # in minutes
period = 5 # in minutes
stat = "Sum"
width = 6
height = 8
height = 5
expressions = []
yAxis = { left = { min = 0 } }
data_source = var.data_source
Expand Down Expand Up @@ -112,12 +112,19 @@ locals {
values(module.container_replicas_widget).*.data,
values(module.container_request_count_widget).*.data,
values(module.container_response_time_widget).*.data,
values(module.container_network_traffic_widget).*.data,
values(module.container_network_transmit_widget).*.data,

# Pod widgets
values(module.pod_cpu_widget).*.data,

# Ingress widgets
values(module.ingress_connections_widget).*.data,
values(module.ingress_request_rate_widget).*.data,
values(module.ingress_request_count_widget).*.data,
values(module.ingress_response_time_widget).*.data,
values(module.ingress_latency_widget).*.data,
values(module.ingress_cpu_widget).*.data,
values(module.ingress_memory_widget).*.data,

# Text widgets
values(module.text_title).*.data,
Expand All @@ -130,5 +137,10 @@ locals {

# single widgets
values(module.widget_custom).*.data,

# Logs widgets
values(module.logs_count_widget).*.data,
values(module.logs_error_rate_widget).*.data,
values(module.logs_warning_rate_widget).*.data,
)
}
21 changes: 13 additions & 8 deletions modules/dashboard/modules/blocks/ingress/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@ output "result" {
[
{ type : "ingress/request-rate" },
{ type : "ingress/connections" },
{ type : "ingress/response-time" },
{ type : "ingress/request-count" }
{ type : "ingress/latency" },
{ type : "ingress/latency", by_host : true },
],
[
{ type : "ingress/request-rate", by_host : true },
{ type : "ingress/response-time", by_host : true },
{ type : "ingress/request-count", by_host : true },
{ type : "ingress/request-count", by_host : true, only_5xx : true }
{ type : "ingress/request-count" },
{ type : "ingress/request-count", only_5xx : true },
{ type : "ingress/request-count", only_5xx : true, by_path : true },
{ type : "ingress/request-count", only_5xx : true, by_status_path : true },
],
[
{ type : "container/cpu", container : "controller", namespace : "ingress-nginx", width : 12 },
{ type : "container/memory", container : "controller", namespace : "ingress-nginx", width : 12 }
{ type : "ingress/cpu", pod : "nginx-ingress", namespace : "ingress-nginx", width : 4, },
{ type : "ingress/memory", pod : "nginx-ingress", namespace : "ingress-nginx", width : 4, },
{ type : "container/network-traffic", pod : "nginx-ingress", width : 4 },
{ type : "container/network-transmit", pod : "nginx-ingress", width : 4 },
# { type : "logs/count", aggregated_metric : "controller"},
# { type : "logs/error-rate", aggregated_metric : "controller"},
# { type : "logs/warning-rate", aggregated_metric : "controller"},
],
]
}
3 changes: 3 additions & 0 deletions modules/dashboard/modules/widgets/base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ No resources.
| <a name="input_data_source"></a> [data\_source](#input\_data\_source) | The custom datasource for widget item | <pre>object({<br> uid = optional(string, null)<br> type = optional(string, "prometheus")<br> })</pre> | n/a | yes |
| <a name="input_decimals"></a> [decimals](#input\_decimals) | The decimals to enable on numbers | `number` | `0` | no |
| <a name="input_defaults"></a> [defaults](#input\_defaults) | Default values that will be passed to all metrics. | `any` | `{}` | no |
| <a name="input_description"></a> [description](#input\_description) | Description for the widget | `string` | `""` | no |
| <a name="input_end"></a> [end](#input\_end) | end of widget | `string` | `null` | no |
| <a name="input_expressions"></a> [expressions](#input\_expressions) | Custom metric expressions over metrics, note that metrics have auto generated m1,m2,..., m{n} ids | <pre>list(object({<br> expression = string<br> label = optional(string, null)<br> accountId = optional(string, null)<br> visible = optional(bool, null)<br> color = optional(string, null)<br> yAxis = optional(string, null)<br> region = optional(string, null)<br> id = optional(string, null)<br> }))</pre> | `[]` | no |
| <a name="input_fillOpacity"></a> [fillOpacity](#input\_fillOpacity) | The fillOpacity value | `number` | `0` | no |
| <a name="input_metrics"></a> [metrics](#input\_metrics) | Metrics to be displayed on the widget. | `any` | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | n/a | `string` | n/a | yes |
| <a name="input_options"></a> [options](#input\_options) | Configuration options for widget legend and tooltip. | <pre>object({<br> legend = object({<br> calcs = optional(list(string), [])<br> displayMode = optional(string, "list")<br> placement = optional(string, "bottom")<br> show_legend = optional(bool, true)<br> })<br> tooltip = optional(object({<br> mode = optional(string, "single")<br> sort = optional(string, "none")<br> }), {})<br> })</pre> | <pre>{<br> "legend": {<br> "calcs": [],<br> "displayMode": "list",<br> "placement": "bottom",<br> "show_legend": true<br> },<br> "tooltip": {<br> "mode": "single",<br> "sort": "none"<br> }<br>}</pre> | no |
| <a name="input_period"></a> [period](#input\_period) | n/a | `number` | `3` | no |
| <a name="input_properties_type"></a> [properties\_type](#input\_properties\_type) | The properties->type option for alarm widgets | `string` | `null` | no |
| <a name="input_query"></a> [query](#input\_query) | The Logs Insights complete build query without sources and other options(in case of metric) query | `string` | `null` | no |
Expand All @@ -49,6 +51,7 @@ No resources.
| <a name="input_stat"></a> [stat](#input\_stat) | n/a | `string` | `"Average"` | no |
| <a name="input_trend"></a> [trend](#input\_trend) | trend of widget | `bool` | `null` | no |
| <a name="input_type"></a> [type](#input\_type) | The type of widget to be prepared | `string` | `"metric"` | no |
| <a name="input_unit"></a> [unit](#input\_unit) | Unit used for widget metric | `string` | `""` | no |
| <a name="input_view"></a> [view](#input\_view) | The view for log insights and alarm widgets | `string` | `null` | no |
| <a name="input_yAxis"></a> [yAxis](#input\_yAxis) | Widget Item common yAxis option (applied only metric type widgets). | `any` | <pre>{<br> "left": {}<br>}</pre> | no |

Expand Down
3 changes: 3 additions & 0 deletions modules/dashboard/modules/widgets/base/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module "base_grafana" {
source = "./platforms/grafana"

name = var.name
description = var.description
data_source = var.data_source
coordinates = var.coordinates
metrics = var.metrics
Expand All @@ -19,5 +20,7 @@ module "base_grafana" {
alarms = var.alarms
properties_type = var.properties_type
decimals = var.decimals
unit = var.unit
fillOpacity = var.fillOpacity
options = var.options
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ No resources.
| <a name="input_data_source"></a> [data\_source](#input\_data\_source) | The custom datasource for widget item | <pre>object({<br> uid = optional(string, null)<br> type = optional(string, "prometheus")<br> })</pre> | n/a | yes |
| <a name="input_decimals"></a> [decimals](#input\_decimals) | The decimals to enable on numbers | `number` | `0` | no |
| <a name="input_defaults"></a> [defaults](#input\_defaults) | Default values that will be passed to all metrics. | `any` | `{}` | no |
| <a name="input_description"></a> [description](#input\_description) | Description for the widget | `string` | `""` | no |
| <a name="input_fillOpacity"></a> [fillOpacity](#input\_fillOpacity) | The fillOpacity value | `number` | `0` | no |
| <a name="input_metrics"></a> [metrics](#input\_metrics) | Metrics to be displayed on the widget. | `any` | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | n/a | `string` | n/a | yes |
| <a name="input_options"></a> [options](#input\_options) | Configuration options for widget legend and tooltip. | <pre>object({<br> legend = object({<br> calcs = optional(list(string), [])<br> displayMode = optional(string, "list")<br> placement = optional(string, "bottom")<br> show_legend = optional(bool, true)<br> })<br> tooltip = optional(object({<br> mode = optional(string, "single")<br> sort = optional(string, "none")<br> }), {})<br> })</pre> | <pre>{<br> "legend": {<br> "calcs": [],<br> "displayMode": "list",<br> "placement": "bottom",<br> "show_legend": true<br> },<br> "tooltip": {<br> "mode": "single",<br> "sort": "none"<br> }<br>}</pre> | no |
| <a name="input_period"></a> [period](#input\_period) | n/a | `number` | `3` | no |
| <a name="input_properties_type"></a> [properties\_type](#input\_properties\_type) | The properties->type option for alarm widgets | `string` | `null` | no |
| <a name="input_query"></a> [query](#input\_query) | The Logs Insights complete build query without sources and other options(in case of metric) query | `string` | `null` | no |
| <a name="input_sources"></a> [sources](#input\_sources) | Log groups list for Logs Insights query | `list(string)` | `[]` | no |
| <a name="input_stacked"></a> [stacked](#input\_stacked) | The stacked option for log insights and alarm widgets | `bool` | `null` | no |
| <a name="input_stat"></a> [stat](#input\_stat) | n/a | `string` | `"Average"` | no |
| <a name="input_type"></a> [type](#input\_type) | The type of widget to be prepared | `string` | `"metric"` | no |
| <a name="input_unit"></a> [unit](#input\_unit) | Unit used for widget metric | `string` | `""` | no |
| <a name="input_view"></a> [view](#input\_view) | The view for log insights and alarm widgets | `string` | `null` | no |

## Outputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,48 @@ variable "decimals" {
description = "The decimals to enable on numbers"
}

variable "unit" {
type = string
default = ""
description = "Unit used for widget metric"
}

variable "fillOpacity" {
type = number
default = 0
description = "The fillOpacity value"
}

variable "options" {
type = object({
legend = object({
calcs = optional(list(string), [])
displayMode = optional(string, "list")
placement = optional(string, "bottom")
show_legend = optional(bool, true)
})
tooltip = optional(object({
mode = optional(string, "single")
sort = optional(string, "none")
}), {})
})
default = {
legend = {
calcs = []
displayMode = "list"
placement = "bottom"
show_legend = true
}
tooltip = {
mode = "single"
sort = "none"
}
}
description = "Configuration options for widget legend and tooltip."
}

variable "description" {
type = string
description = "Description for the widget"
default = ""
}
40 changes: 32 additions & 8 deletions modules/dashboard/modules/widgets/base/platforms/grafana/widget.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,37 @@ locals {
},
]
}
unit = var.unit
}

field_config_overrides = [
for metric in local.metrics_with_defaults : {
matcher = {
id = "byName"
options = metric.label
}
properties = [
{
id = "color"
value = {
mode = "fixed"
fixedColor = format("#%s", metric.color)
}
}
]
} if metric.color != null
]


common_fields = ["MetricNamespace", "MetricName"]
attribute_fields = ["accountId", "period", "stat", "label", "visible", "color", "yAxis"]
custom_fields = ["anomaly_detection", "anomaly_deviation"]
metrics_local = var.metrics == null ? [] : var.metrics

# merge metrics with defaults
metrics_with_defaults = [for metric in local.metrics_local : merge(var.defaults, metric)]
metrics_with_defaults = [for metric in local.metrics_local : merge(var.defaults, metric, {
color = lookup(metric, "color", null)
})]

type_map = {
timeSeries = "timeseries"
Expand Down Expand Up @@ -95,10 +117,11 @@ locals {
}]

data = {
datasource = var.data_source
datasource = var.data_source
description = var.description
fieldConfig = {
defaults = local.field_config_defaults
overrides = []
overrides = local.field_config_overrides
}
gridPos = {
h = var.coordinates.height
Expand All @@ -110,13 +133,14 @@ locals {
type = try(local.type_map[var.view], local.type_map.timeSeries)
options = {
legend = {
calcs = []
displayMode = "list"
placement = "bottom"
calcs = lookup(var.options.legend, "calcs", [])
displayMode = lookup(var.options.legend, "displayMode", "list")
placement = lookup(var.options.legend, "placement", "bottom")
showLegend = lookup(var.options.legend, "show_legend", true)
}
tooltip = {
mode = "single"
sort = "none"
mode = lookup(var.options.tooltip, "mode", "single")
sort = lookup(var.options.tooltip, "sort", "none")
}
}
targets = concat(local.query_targets, local.metric_targets)
Expand Down
40 changes: 40 additions & 0 deletions modules/dashboard/modules/widgets/base/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,43 @@ variable "fillOpacity" {
default = 0
description = "The fillOpacity value"
}

variable "options" {
type = object({
legend = object({
calcs = optional(list(string), [])
displayMode = optional(string, "list")
placement = optional(string, "bottom")
show_legend = optional(bool, true)
})
tooltip = optional(object({
mode = optional(string, "single")
sort = optional(string, "none")
}), {})
})
default = {
legend = {
calcs = []
displayMode = "list"
placement = "bottom"
show_legend = true
}
tooltip = {
mode = "single"
sort = "none"
}
}
description = "Configuration options for widget legend and tooltip."
}

variable "unit" {
type = string
default = ""
description = "Unit used for widget metric"
}

variable "description" {
type = string
description = "Description for the widget"
default = ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# connections

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_base"></a> [base](#module\_base) | ../../base | n/a |

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | n/a | `string` | `null` | no |
| <a name="input_anomaly_detection"></a> [anomaly\_detection](#input\_anomaly\_detection) | Allow to enable anomaly detection on widget metrics | `bool` | `false` | no |
| <a name="input_anomaly_deviation"></a> [anomaly\_deviation](#input\_anomaly\_deviation) | Deviation of the anomaly band | `number` | `6` | no |
| <a name="input_coordinates"></a> [coordinates](#input\_coordinates) | position | <pre>object({<br> x : number<br> y : number<br> width : number<br> height : number<br> })</pre> | n/a | yes |
| <a name="input_data_source"></a> [data\_source](#input\_data\_source) | The custom datasource for widget item | <pre>object({<br> uid = optional(string, null)<br> type = optional(string, "prometheus")<br> })</pre> | n/a | yes |
| <a name="input_ingress_type"></a> [ingress\_type](#input\_ingress\_type) | n/a | `string` | `"nginx"` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | n/a | `string` | `"default"` | no |
| <a name="input_period"></a> [period](#input\_period) | stats | `number` | `3` | no |
| <a name="input_pod"></a> [pod](#input\_pod) | n/a | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `""` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_data"></a> [data](#output\_data) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Loading

0 comments on commit 05c8d82

Please sign in to comment.