From ae00176bf7273b4cad99e08e06bb0318d7bef929 Mon Sep 17 00:00:00 2001 From: yduartep Date: Fri, 30 Aug 2024 10:59:39 +0200 Subject: [PATCH] define new gcp load balancer dashboard in csp-mixin --- csp-mixin/config.libsonnet | 1 + csp-mixin/dashboards.libsonnet | 22 +++++++++ csp-mixin/main.libsonnet | 1 + csp-mixin/panels.libsonnet | 16 +++++++ csp-mixin/rows.libsonnet | 19 ++++++++ csp-mixin/signals/loadbalancer.libsonnet | 61 ++++++++++++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 csp-mixin/signals/loadbalancer.libsonnet diff --git a/csp-mixin/config.libsonnet b/csp-mixin/config.libsonnet index 8a8481641..4564a20ec 100644 --- a/csp-mixin/config.libsonnet +++ b/csp-mixin/config.libsonnet @@ -9,6 +9,7 @@ blobstore: (import './signals/blobstore.libsonnet')(this), azureelasticpool: (import './signals/azureelasticpool.libsonnet')(this), azuresqldb: (import './signals/azuresqldb.libsonnet')(this), + loadbalancer: (import './signals/loadbalancer.libsonnet')(this), }, blobStorage: { enableAvailability: false, diff --git a/csp-mixin/dashboards.libsonnet b/csp-mixin/dashboards.libsonnet index dc90d5ec3..02a0fb741 100644 --- a/csp-mixin/dashboards.libsonnet +++ b/csp-mixin/dashboards.libsonnet @@ -27,6 +27,28 @@ local commonlib = import 'common-lib/common/main.libsonnet'; ), } + + { + [csplib.config.uid + '-loadbalancer.json']: + local variables = csplib.signals.loadbalancer.getVariablesMultiChoice(); + g.dashboard.new(csplib.config.dashboardNamePrefix + 'Load Balancing') + + g.dashboard.withUid(csplib.config.uid + '-loadbalancer') + + g.dashboard.withTags(csplib.config.dashboardTags) + + g.dashboard.withTimezone(csplib.config.dashboardTimezone) + + g.dashboard.withRefresh(csplib.config.dashboardRefresh) + + g.dashboard.timepicker.withTimeOptions(csplib.config.dashboardPeriod) + + g.dashboard.withVariables([ + if std.asciiLower(v.label) == std.asciiLower(csplib.config.blobStorage.bucketLabel) //v.label == 'Bucket_name' + then v { label: 'Bucket Name' } + else v + for v in variables + ]) + + g.dashboard.withPanels( + g.util.grid.wrapPanels( + csplib.grafana.rows.glb_requests + ) + ), + } + + if csplib.config.uid == 'azure' then { [csplib.config.uid + '-elasticpool.json']: diff --git a/csp-mixin/main.libsonnet b/csp-mixin/main.libsonnet index 9ffd7aece..38e2d634c 100644 --- a/csp-mixin/main.libsonnet +++ b/csp-mixin/main.libsonnet @@ -9,6 +9,7 @@ local commonlib = import 'common-lib/common/main.libsonnet'; blobstore: commonlib.signals.unmarshallJsonMulti(this.config.signals.blobstore, type=this.config.metricsSource), azureelasticpool: commonlib.signals.unmarshallJsonMulti(this.config.signals.azureelasticpool, type=this.config.metricsSource), azuresqldb: commonlib.signals.unmarshallJsonMulti(this.config.signals.azuresqldb, type=this.config.metricsSource), + loadbalancer: commonlib.signals.unmarshallJsonMulti(this.config.signals.loadbalancer, type=this.config.metricsSource), }, grafana: { panels: (import './panels.libsonnet').new(this), diff --git a/csp-mixin/panels.libsonnet b/csp-mixin/panels.libsonnet index 553ac40a0..110e9edab 100644 --- a/csp-mixin/panels.libsonnet +++ b/csp-mixin/panels.libsonnet @@ -383,5 +383,21 @@ local commonlib = import 'common-lib/common/main.libsonnet'; ], 'DTU utilization and limits by database' ) + self._asql_tableCommon(), + + glb_reqsec: + this.signals.loadbalancer.requestsByStatus.asTimeSeries() + + commonlib.panels.generic.timeSeries.base.stylize(), + + glb_reqcountry: + this.signals.loadbalancer.requestsByCountry.asTimeSeries() + + commonlib.panels.generic.timeSeries.base.stylize(), + + glb_reqcache: + this.signals.loadbalancer.requestsByCache.asTimeSeries() + + commonlib.panels.generic.timeSeries.base.stylize(), + + glb_reqprotocol: + this.signals.loadbalancer.requestsByProtocol.asTimeSeries() + + commonlib.panels.generic.timeSeries.base.stylize(), }, } diff --git a/csp-mixin/rows.libsonnet b/csp-mixin/rows.libsonnet index 8738c3911..f367f88a2 100644 --- a/csp-mixin/rows.libsonnet +++ b/csp-mixin/rows.libsonnet @@ -116,5 +116,24 @@ local g = import './g.libsonnet'; + g.panel.timeSeries.gridPos.withW(12) + g.panel.timeSeries.gridPos.withH(8), ], + + glb_requests: [ + g.panel.row.new('Load Balancer Requests'), + this.grafana.panels.glb_reqsec + + g.panel.timeSeries.gridPos.withW(12) + + g.panel.timeSeries.gridPos.withH(8), + + this.grafana.panels.glb_reqcountry + + g.panel.timeSeries.gridPos.withW(12) + + g.panel.timeSeries.gridPos.withH(8), + + this.grafana.panels.glb_reqcache + + g.panel.timeSeries.gridPos.withW(12) + + g.panel.timeSeries.gridPos.withH(8), + + this.grafana.panels.glb_reqprotocol + + g.panel.timeSeries.gridPos.withW(12) + + g.panel.timeSeries.gridPos.withH(8), + ], }, } diff --git a/csp-mixin/signals/loadbalancer.libsonnet b/csp-mixin/signals/loadbalancer.libsonnet new file mode 100644 index 000000000..69cd582f8 --- /dev/null +++ b/csp-mixin/signals/loadbalancer.libsonnet @@ -0,0 +1,61 @@ +local commonlib = import 'common-lib/common/main.libsonnet'; +function(this) + { + local s = self, + filteringSelector: this.filteringSelector, + groupLabels: this.groupLabels, + instanceLabels: this.instanceLabels, + aggLevel: 'instance', + discoveryMetric: { + stackdriver: 'stackdriver_https_lb_rule_loadbalancing_googleapis_com_https_request_count' + }, + signals: { + requestsByStatus: { + name: 'Requests / sec', + description: 'The number of requests per second by status code.', + type: 'raw', + sources: { + stackdriver: { + expr: 'label_replace(sum by (response_code_class) (rate(stackdriver_https_lb_rule_loadbalancing_googleapis_com_https_request_count{%(queriesSelector)s}[$__rate_interval])),"response_code_class","${1}xx","response_code_class","([0-9])00")', + legendCustomTemplate: '{{response_code_class}}', + }, + }, + }, + + requestsByCountry: { + name: 'Requests by Country', + description: 'The number of requests per second by client country.', + type: 'raw', + sources: { + stackdriver: { + expr: 'sum by (backend_target_name, client_country) (rate(stackdriver_https_lb_rule_loadbalancing_googleapis_com_https_request_count{%(queriesSelector)s}[$__rate_interval]))', + legendCustomTemplate: '{{client_country}}', + }, + }, + }, + + requestsByCache: { + name: 'Requests by Cache Results', + description: 'The cache results per second of requests.', + type: 'raw', + sources: { + stackdriver: { + expr: 'sum by (backend_target_name, cache_result) (rate(stackdriver_https_lb_rule_loadbalancing_googleapis_com_https_request_count{%(queriesSelector)s}[$__rate_interval]))', + legendCustomTemplate: '{{cache_result}}', + }, + }, + }, + + requestsByProtocol: { + name: 'Requests by protocol', + description: 'Requests per second by protocol.', + type: 'raw', + sources: { + stackdriver: { + expr: 'sum by (backend_target_name, protocol) (rate(stackdriver_https_lb_rule_loadbalancing_googleapis_com_https_request_count{%(queriesSelector)s}[$__rate_interval]))', + legendCustomTemplate: '{{protocol}}', + }, + }, + }, + }, + }