mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch: Set period in math expressions (#39458)
* set period field * add test * add insights rule permission to docs
This commit is contained in:
parent
0229146c3b
commit
c2604e04ab
@ -55,6 +55,7 @@ Here is a minimal policy example:
|
|||||||
"cloudwatch:ListMetrics",
|
"cloudwatch:ListMetrics",
|
||||||
"cloudwatch:GetMetricStatistics",
|
"cloudwatch:GetMetricStatistics",
|
||||||
"cloudwatch:GetMetricData"
|
"cloudwatch:GetMetricData"
|
||||||
|
"cloudwatch:GetInsightRuleReport"
|
||||||
],
|
],
|
||||||
"Resource": "*"
|
"Resource": "*"
|
||||||
},
|
},
|
||||||
|
@ -18,6 +18,7 @@ func (e *cloudWatchExecutor) buildMetricDataQuery(query *cloudWatchQuery) (*clou
|
|||||||
|
|
||||||
if query.Expression != "" {
|
if query.Expression != "" {
|
||||||
mdq.Expression = aws.String(query.Expression)
|
mdq.Expression = aws.String(query.Expression)
|
||||||
|
mdq.Period = aws.Int64(int64(query.Period))
|
||||||
} else {
|
} else {
|
||||||
if query.isSearchExpression() {
|
if query.isSearchExpression() {
|
||||||
mdq.Expression = aws.String(buildSearchExpression(query, query.Statistic))
|
mdq.Expression = aws.String(buildSearchExpression(query, query.Statistic))
|
||||||
|
@ -4,9 +4,32 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMetricDataQueryBuilder_buildSearchExpression(t *testing.T) {
|
func TestMetricDataQueryBuilder_buildSearchExpression(t *testing.T) {
|
||||||
|
t.Run("buildMetricDataQuery", func(t *testing.T) {
|
||||||
|
t.Run("should set period in user defined expression", func(t *testing.T) {
|
||||||
|
executor := newExecutor(nil, nil, newTestConfig(), fakeSessionCache{})
|
||||||
|
query := &cloudWatchQuery{
|
||||||
|
Namespace: "AWS/EC2",
|
||||||
|
MetricName: "CPUUtilization",
|
||||||
|
Dimensions: map[string][]string{
|
||||||
|
"LoadBalancer": {"lb1"},
|
||||||
|
},
|
||||||
|
Period: 300,
|
||||||
|
Expression: "SUM([a,b])",
|
||||||
|
MatchExact: true,
|
||||||
|
}
|
||||||
|
query.MatchExact = false
|
||||||
|
mdq, err := executor.buildMetricDataQuery(query)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Nil(t, mdq.MetricStat)
|
||||||
|
assert.Equal(t, int64(300), *mdq.Period)
|
||||||
|
assert.Equal(t, `SUM([a,b])`, *mdq.Expression)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Query should be matched exact", func(t *testing.T) {
|
t.Run("Query should be matched exact", func(t *testing.T) {
|
||||||
const matchExact = true
|
const matchExact = true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user