weaveworks / grafanalib

Python library for building Grafana dashboards
Apache License 2.0
1.88k stars 316 forks source link

CloudwatchMetrics Alerts not working #616

Open call-stack opened 1 year ago

call-stack commented 1 year ago

What happened?

Setting up a cloudwatch alert on metric. But when I am opening the alert in grafana. Getting below error. Screenshot 2023-08-17 at 11 43 24 AM

but when I re-select the same datasource from the list(done in UI) again, it worked.

How to reproduce it?

Below is the code I am using to setup alert.

cloudwatch_alert = AlertRulev9(
    title="Test Alert",
    condition="B",
    triggers=[
        CloudwatchMetricsTarget(
            datasource="fO0jguEGk",
            refId="A",
            dimensions={
                "ClusterName": "test-cluster-qa",
                "ServiceName":"test-cluster-qa-jamuna"
            },
            metricName = "RunningTaskCount",
            namespace="ECS/ContainerInsights"
        ),
        AlertExpression(
            refId="B",
            expressionType=EXP_TYPE_CLASSIC,
            expression='A',
            conditions=[
               AlertCondition(
                   evaluator=LowerThan(1),
                   operator=OP_AND,
                   reducerType=RTYPE_MIN

               )
            ]
        )
    ],
    evaluateFor="3m",
)

# An AlertGroup is one group contained in an alert folder.
alertgroup = AlertGroup(
    name="test-alert-group",
    rules=[
        cloudwatch_alert
    ]
)

my_alergroup_json = json.dumps(alertgroup.to_json_data())
call-stack commented 1 year ago

Removing "datasource": self.datasource, from CloudwatchMetricsTarget inside grafanalib/cloudwatch.py fixed issue for me. Not sure if that is a correct way to handle it but temporarily it working fine for me.