Skip to content

Commit

Permalink
update cloudwatch metrics provider
Browse files Browse the repository at this point in the history
Signed-off-by: Modestas Kulpinskas <modestas.kulpinskas@kevin.eu>
  • Loading branch information
Modestas Kulpinskas committed Aug 4, 2023
1 parent 0f7aca2 commit 6677040
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
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

0 comments on commit 6677040

Please sign in to comment.