From 781bccf64fffd5b998e18d3df3211ec3056be8da Mon Sep 17 00:00:00 2001 From: MattiasMTS Date: Tue, 18 Jun 2024 14:46:17 +0200 Subject: [PATCH 1/3] feat: add account to CloudwatchMetricsTarget --- grafanalib/cloudwatch.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/grafanalib/cloudwatch.py b/grafanalib/cloudwatch.py index a9a22248..2c72ae56 100644 --- a/grafanalib/cloudwatch.py +++ b/grafanalib/cloudwatch.py @@ -1,8 +1,8 @@ """Helpers to create Cloudwatch-specific Grafana queries.""" import attr - from attr.validators import instance_of + from grafanalib.core import Target @@ -22,6 +22,8 @@ class CloudwatchMetricsTarget(Target): :param expression: Cloudwatch Metric math expressions :param id: unique id :param matchExact: Only show metrics that exactly match all defined dimension names. + :param account: AWS Account where Cloudwatch is used + :param account: AWS Account ID where Cloudwatch is used :param metricName: Cloudwatch metric name :param namespace: Cloudwatch namespace :param period: Cloudwatch data period @@ -32,11 +34,14 @@ class CloudwatchMetricsTarget(Target): :param hide: controls if given metric is displayed on visualization :param datasource: Grafana datasource name """ + alias = attr.ib(default="") dimensions = attr.ib(factory=dict, validator=instance_of(dict)) expression = attr.ib(default="") id = attr.ib(default="") matchExact = attr.ib(default=True, validator=instance_of(bool)) + account = attr.ib(default="") + accountId = attr.ib(default="") metricName = attr.ib(default="") namespace = attr.ib(default="") period = attr.ib(default="") @@ -48,13 +53,14 @@ class CloudwatchMetricsTarget(Target): datasource = attr.ib(default=None) def to_json_data(self): - return { "alias": self.alias, "dimensions": self.dimensions, "expression": self.expression, "id": self.id, "matchExact": self.matchExact, + "account": self.account, + "accountId": self.accountId, "metricName": self.metricName, "namespace": self.namespace, "period": self.period, @@ -88,6 +94,7 @@ class CloudwatchLogsInsightsTarget(Target): :param hide: controls if given metric is displayed on visualization :param datasource: Grafana datasource name """ + expression = attr.ib(default="") id = attr.ib(default="") logGroupNames = attr.ib(factory=list, validator=instance_of(list)) @@ -99,7 +106,6 @@ class CloudwatchLogsInsightsTarget(Target): datasource = attr.ib(default=None) def to_json_data(self): - return { "expression": self.expression, "id": self.id, From 0bdb4464bcc09efc92e6f45fda16268b241f0550 Mon Sep 17 00:00:00 2001 From: MattiasMTS Date: Tue, 18 Jun 2024 15:15:39 +0200 Subject: [PATCH 2/3] docs: update changelog --- CHANGELOG.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index cc53f617..40766ddb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,10 +2,10 @@ Changelog ========= -x.x.x ? +0.7.2 2024-06-18 ================== -* Added ... +* Added support for AWS Cross-Account in CloudwatchMetricsTarget 0.7.1 2024-01-12 ================== From 3975e1a1070919755630a9913813affae8e3bc27 Mon Sep 17 00:00:00 2001 From: JamesGibo <22477854+JamesGibo@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:24:49 +0100 Subject: [PATCH 3/3] Update grafanalib/cloudwatch.py --- grafanalib/cloudwatch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafanalib/cloudwatch.py b/grafanalib/cloudwatch.py index 2c72ae56..f72d891b 100644 --- a/grafanalib/cloudwatch.py +++ b/grafanalib/cloudwatch.py @@ -23,7 +23,7 @@ class CloudwatchMetricsTarget(Target): :param id: unique id :param matchExact: Only show metrics that exactly match all defined dimension names. :param account: AWS Account where Cloudwatch is used - :param account: AWS Account ID where Cloudwatch is used + :param accountId: AWS Account ID where Cloudwatch is used :param metricName: Cloudwatch metric name :param namespace: Cloudwatch namespace :param period: Cloudwatch data period