Skip to content

fix: return empty metrics data when no metric queries are built - #168

Merged
BSick7 merged 1 commit into
masterfrom
fix/cloudwatch-empty-metric-queries
Aug 28, 2026
Merged

BSick7 merged 1 commit into
masterfrom
fix/cloudwatch-empty-metric-queries

Conversation

@BSick7

@BSick7 BSick7 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Problem

CloudWatch GetMetricData rejects a request with an empty MetricDataQueries:

400 ValidationError: The parameter MetricDataQueries is required.

For workspaces with no metrics mappings (e.g. aws/aws-fargate-task, whose base_metrics is empty), Getter.GetMetrics built zero queries and sent the request anyway, surfacing in the Nullstone UI Monitoring tab as:

unable to retrieve metrics: error retrieving metrics data: ...

Fix

After building queries, if the slice is empty, return workspace.NewMetricsData(), nil without calling CloudWatch — the UI renders an empty/no-metrics state instead of an error.

The guard is on the built queries rather than len(g.Infra.MetricsMappings) because options.Metrics acts as a filter inside BuildMetricQueries, so non-empty mappings can still produce zero queries.

The GCP getter (gcp/cloudmonitoring) iterates mappings per-series and is naturally safe when empty — no change needed there.

Testing

New TestGetter_GetMetrics_NoQueries covers both empty mappings and a filter matching nothing; both assert empty metrics data and nil error with no AWS call. go test ./aws/cloudwatch/metrics/ passes (run with -mod=mod — the vendor tree is out of sync with go.mod on master, unrelated to this change).

CloudWatch GetMetricData rejects a request with an empty MetricDataQueries
(400 ValidationError), which surfaced as an error in the Monitoring tab for
workspaces with no metrics mappings (e.g. aws/aws-fargate-task). Skip the
CloudWatch call and return empty metrics data instead.
@BSick7
BSick7 merged commit 0ec56f1 into master Aug 28, 2026
1 check failed
@BSick7
BSick7 deleted the fix/cloudwatch-empty-metric-queries branch August 28, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants