Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cloudwatch metrics provider multiple dimensions #2932

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions metricproviders/cloudwatch/cloudwatch.go
Expand Up @@ -154,9 +154,11 @@ func convertType(data []v1alpha1.CloudWatchMetricDataQuery) []types.MetricDataQu
if v.MetricStat.Metric.Dimensions != nil {
metricStat.Metric.Dimensions = make([]types.Dimension, len(v.MetricStat.Metric.Dimensions))
for j, d := range v.MetricStat.Metric.Dimensions {
name := d.Name
value := d.Value
metricStat.Metric.Dimensions[j] = types.Dimension{
Name: &d.Name,
Value: &d.Value,
Name: &name,
Value: &value,
}
}
}
Expand Down
86 changes: 86 additions & 0 deletions metricproviders/cloudwatch/cloudwatch_test.go
Expand Up @@ -382,6 +382,92 @@ func TestConvertType(t *testing.T) {
},
},
},
{
query: []v1alpha1.CloudWatchMetricDataQuery{
{
Id: "rate",
Expression: pointer.StringPtr("errors / requests"),
},
{
Id: "errors",
MetricStat: &v1alpha1.CloudWatchMetricStat{
Metric: v1alpha1.CloudWatchMetricStatMetric{
Dimensions: []v1alpha1.CloudWatchMetricStatMetricDimension{
{
Name: "hoge",
Value: "fuga",
},
{
Name: "poge",
Value: "doge",
},
},
Namespace: pointer.StringPtr("app1"),
MetricName: "errors",
},
Period: period,
Stat: "Max",
Unit: "Count",
},
ReturnData: pointer.BoolPtr(false),
},
{
Id: "requests",
MetricStat: &v1alpha1.CloudWatchMetricStat{
Metric: v1alpha1.CloudWatchMetricStatMetric{
Namespace: pointer.StringPtr("app2"),
MetricName: "requests",
},
Period: period,
Stat: "Sum",
Unit: "Bytes/Second",
},
ReturnData: pointer.BoolPtr(true),
},
},
expected: []types.MetricDataQuery{
{
Id: pointer.StringPtr("rate"),
Expression: pointer.StringPtr("errors / requests"),
},
{
Id: pointer.StringPtr("errors"),
MetricStat: &types.MetricStat{
Metric: &types.Metric{
Namespace: pointer.StringPtr("app1"),
MetricName: pointer.StringPtr("errors"),
Dimensions: []types.Dimension{
{
Name: pointer.StringPtr("hoge"),
Value: pointer.StringPtr("fuga"),
},
{
Name: pointer.StringPtr("poge"),
Value: pointer.StringPtr("doge"),
},
},
},
Period: pointer.Int32Ptr(300),
Stat: pointer.StringPtr("Max"),
Unit: types.StandardUnitCount,
},
ReturnData: pointer.BoolPtr(false),
},
{
Id: pointer.StringPtr("requests"),
MetricStat: &types.MetricStat{
Metric: &types.Metric{
Namespace: pointer.StringPtr("app2"),
MetricName: pointer.StringPtr("requests"),
},
Period: pointer.Int32Ptr(300),
Stat: pointer.StringPtr("Sum"),
Unit: types.StandardUnitBytesSecond,
},
ReturnData: pointer.BoolPtr(true),
},
},
},
}

for _, tt := range tests {
Expand Down