mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 07:35:45 -06:00
* add support for code editor and builder * refactor cloudwatch migration * Add tooltip to editor field (#56) * add tooltip * add old tooltips * Bug bash feedback fixes (#58) * make ASC the default option * update sql preview whenever sql changes * don't allow queries without aggregation * set default value for aggregation * use new input field * cleanup * pr feedback * prevent unnecessary rerenders * use frame error instead of main error * remove not used snapshot * Use dimension filter in schema picker (#63) * use dimension key filter in group by and schema labels * add dimension filter also to code editor * add tests * fix build error * fix strict error * remove debug code * fix annotation editor (#64) * fix annotation editor * fix broken test * revert annotation backend change * PR feedback (#67) * pr feedback * removed dimension filter from group by * add spacing between common fields and rest * do not generate deep link for metric queries (#70) * update docs (#69) Co-authored-by: Erik Sundell <erik.sundell87@gmail.com> * fix lint problem caused by merge conflict Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
162 lines
4.5 KiB
Go
162 lines
4.5 KiB
Go
package cloudwatch
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCloudWatchQuery(t *testing.T) {
|
|
t.Run("Deeplink is not generated for MetricQueryTypeQuery", func(t *testing.T) {
|
|
startTime := time.Now()
|
|
endTime := startTime.Add(2 * time.Hour)
|
|
query := &cloudWatchQuery{
|
|
RefId: "A",
|
|
Region: "us-east-1",
|
|
Expression: "",
|
|
Statistic: "Average",
|
|
Period: 300,
|
|
Id: "id1",
|
|
MatchExact: true,
|
|
Dimensions: map[string][]string{
|
|
"InstanceId": {"i-12345678"},
|
|
},
|
|
MetricQueryType: MetricQueryTypeQuery,
|
|
MetricEditorMode: MetricEditorModeBuilder,
|
|
}
|
|
|
|
deepLink, err := query.buildDeepLink(startTime, endTime)
|
|
require.NoError(t, err)
|
|
assert.Empty(t, deepLink)
|
|
})
|
|
|
|
t.Run("SEARCH(someexpression) was specified in the query editor", func(t *testing.T) {
|
|
query := &cloudWatchQuery{
|
|
RefId: "A",
|
|
Region: "us-east-1",
|
|
Expression: "SEARCH(someexpression)",
|
|
Statistic: "Average",
|
|
Period: 300,
|
|
Id: "id1",
|
|
}
|
|
|
|
assert.True(t, query.isSearchExpression(), "Expected a search expression")
|
|
assert.False(t, query.isMathExpression(), "Expected not math expression")
|
|
})
|
|
|
|
t.Run("No expression, no multi dimension key values and no * was used", func(t *testing.T) {
|
|
query := &cloudWatchQuery{
|
|
RefId: "A",
|
|
Region: "us-east-1",
|
|
Expression: "",
|
|
Statistic: "Average",
|
|
Period: 300,
|
|
Id: "id1",
|
|
MatchExact: true,
|
|
Dimensions: map[string][]string{
|
|
"InstanceId": {"i-12345678"},
|
|
},
|
|
}
|
|
|
|
assert.False(t, query.isSearchExpression(), "Expected not a search expression")
|
|
assert.False(t, query.isMathExpression(), "Expected not math expressions")
|
|
})
|
|
|
|
t.Run("No expression but multi dimension key values exist", func(t *testing.T) {
|
|
query := &cloudWatchQuery{
|
|
RefId: "A",
|
|
Region: "us-east-1",
|
|
Expression: "",
|
|
Statistic: "Average",
|
|
Period: 300,
|
|
Id: "id1",
|
|
Dimensions: map[string][]string{
|
|
"InstanceId": {"i-12345678", "i-34562312"},
|
|
},
|
|
}
|
|
|
|
assert.True(t, query.isSearchExpression(), "Expected a search expression")
|
|
assert.False(t, query.isMathExpression(), "Expected not math expressions")
|
|
})
|
|
|
|
t.Run("No expression but dimension values has *", func(t *testing.T) {
|
|
query := &cloudWatchQuery{
|
|
RefId: "A",
|
|
Region: "us-east-1",
|
|
Expression: "",
|
|
Statistic: "Average",
|
|
Period: 300,
|
|
Id: "id1",
|
|
Dimensions: map[string][]string{
|
|
"InstanceId": {"i-12345678", "*"},
|
|
"InstanceType": {"abc", "def"},
|
|
},
|
|
}
|
|
|
|
assert.True(t, query.isSearchExpression(), "Expected a search expression")
|
|
assert.False(t, query.isMathExpression(), "Expected not math expression")
|
|
})
|
|
|
|
t.Run("Query has a multi-valued dimension", func(t *testing.T) {
|
|
query := &cloudWatchQuery{
|
|
RefId: "A",
|
|
Region: "us-east-1",
|
|
Expression: "",
|
|
Statistic: "Average",
|
|
Period: 300,
|
|
Id: "id1",
|
|
Dimensions: map[string][]string{
|
|
"InstanceId": {"i-12345678", "i-12345679"},
|
|
"InstanceType": {"abc"},
|
|
},
|
|
}
|
|
|
|
assert.True(t, query.isSearchExpression(), "Expected a search expression")
|
|
assert.True(t, query.isMultiValuedDimensionExpression(), "Expected a multi-valued dimension expression")
|
|
})
|
|
|
|
t.Run("No dimensions were added", func(t *testing.T) {
|
|
query := &cloudWatchQuery{
|
|
RefId: "A",
|
|
Region: "us-east-1",
|
|
Expression: "",
|
|
Statistic: "Average",
|
|
Period: 300,
|
|
Id: "id1",
|
|
MatchExact: false,
|
|
Dimensions: make(map[string][]string),
|
|
}
|
|
t.Run("Match exact is false", func(t *testing.T) {
|
|
query.MatchExact = false
|
|
assert.True(t, query.isSearchExpression(), "Expected a search expression")
|
|
assert.False(t, query.isMathExpression(), "Expected not math expression")
|
|
})
|
|
|
|
t.Run("Match exact is true", func(t *testing.T) {
|
|
query.MatchExact = true
|
|
assert.False(t, query.isSearchExpression(), "Exxpected not search expression")
|
|
assert.False(t, query.isMathExpression(), "Expected not math expression")
|
|
})
|
|
})
|
|
|
|
t.Run("Match exact is", func(t *testing.T) {
|
|
query := &cloudWatchQuery{
|
|
RefId: "A",
|
|
Region: "us-east-1",
|
|
Expression: "",
|
|
Statistic: "Average",
|
|
Period: 300,
|
|
Id: "id1",
|
|
MatchExact: false,
|
|
Dimensions: map[string][]string{
|
|
"InstanceId": {"i-12345678"},
|
|
},
|
|
}
|
|
|
|
assert.True(t, query.isSearchExpression(), "Expected search expression")
|
|
assert.False(t, query.isMathExpression(), "Expected not math expression")
|
|
})
|
|
}
|