Skip to content

Commit

Permalink
feat: add account to CloudwatchMetricsTarget (#661)
Browse files Browse the repository at this point in the history
* feat: add account to CloudwatchMetricsTarget

* docs: update changelog

* Update grafanalib/cloudwatch.py

---------

Co-authored-by: JamesGibo <[email protected]>
  • Loading branch information
MattiasMTS and JamesGibo authored Jul 16, 2024
1 parent 05d801c commit d4c10e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Changelog
=========

x.x.x ?
* Fix mappings for Table

==================
x.x.x ?
=======

* Added ...
* Fix mappings for Table
* Added support for AWS Cross-Account in CloudwatchMetricsTarget

0.7.1 2024-01-12
==================
================

* Extended DashboardLink to support links to dashboards and urls, as per the docs_

Expand Down
12 changes: 9 additions & 3 deletions grafanalib/cloudwatch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Helpers to create Cloudwatch-specific Grafana queries."""

import attr

from attr.validators import instance_of

from grafanalib.core import Target


Expand All @@ -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 accountId: AWS Account ID where Cloudwatch is used
:param metricName: Cloudwatch metric name
:param namespace: Cloudwatch namespace
:param period: Cloudwatch data period
Expand All @@ -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="")
Expand All @@ -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,
Expand Down Expand Up @@ -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))
Expand All @@ -99,7 +106,6 @@ class CloudwatchLogsInsightsTarget(Target):
datasource = attr.ib(default=None)

def to_json_data(self):

return {
"expression": self.expression,
"id": self.id,
Expand Down

0 comments on commit d4c10e9

Please sign in to comment.