mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch: move QueryData input parsing types to separate package (#57165)
* CloudWatch: move parse request types separate package * Move metric query constants, unexport metricDataQuery json decoding type * Unexport isSearchExpression
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -13,8 +14,8 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
t.Run("should use metric stat", func(t *testing.T) {
|
||||
executor := newExecutor(nil, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures())
|
||||
query := getBaseQuery()
|
||||
query.MetricEditorMode = MetricEditorModeBuilder
|
||||
query.MetricQueryType = MetricQueryTypeSearch
|
||||
query.MetricEditorMode = models.MetricEditorModeBuilder
|
||||
query.MetricQueryType = models.MetricQueryTypeSearch
|
||||
mdq, err := executor.buildMetricDataQuery(query)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, mdq.Expression)
|
||||
@@ -25,8 +26,8 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
t.Run("should use custom built expression", func(t *testing.T) {
|
||||
executor := newExecutor(nil, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures())
|
||||
query := getBaseQuery()
|
||||
query.MetricEditorMode = MetricEditorModeBuilder
|
||||
query.MetricQueryType = MetricQueryTypeSearch
|
||||
query.MetricEditorMode = models.MetricEditorModeBuilder
|
||||
query.MetricQueryType = models.MetricQueryTypeSearch
|
||||
query.MatchExact = false
|
||||
mdq, err := executor.buildMetricDataQuery(query)
|
||||
require.NoError(t, err)
|
||||
@@ -37,8 +38,8 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
t.Run("should use sql expression", func(t *testing.T) {
|
||||
executor := newExecutor(nil, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures())
|
||||
query := getBaseQuery()
|
||||
query.MetricEditorMode = MetricEditorModeRaw
|
||||
query.MetricQueryType = MetricQueryTypeQuery
|
||||
query.MetricEditorMode = models.MetricEditorModeRaw
|
||||
query.MetricQueryType = models.MetricQueryTypeQuery
|
||||
query.SqlExpression = `SELECT SUM(CPUUTilization) FROM "AWS/EC2"`
|
||||
mdq, err := executor.buildMetricDataQuery(query)
|
||||
require.NoError(t, err)
|
||||
@@ -49,8 +50,8 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
t.Run("should use user defined math expression", func(t *testing.T) {
|
||||
executor := newExecutor(nil, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures())
|
||||
query := getBaseQuery()
|
||||
query.MetricEditorMode = MetricEditorModeRaw
|
||||
query.MetricQueryType = MetricQueryTypeSearch
|
||||
query.MetricEditorMode = models.MetricEditorModeRaw
|
||||
query.MetricQueryType = models.MetricQueryTypeSearch
|
||||
query.Expression = `SUM(x+y)`
|
||||
mdq, err := executor.buildMetricDataQuery(query)
|
||||
require.NoError(t, err)
|
||||
@@ -61,8 +62,8 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
t.Run("should set period in user defined expression", func(t *testing.T) {
|
||||
executor := newExecutor(nil, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures())
|
||||
query := getBaseQuery()
|
||||
query.MetricEditorMode = MetricEditorModeRaw
|
||||
query.MetricQueryType = MetricQueryTypeSearch
|
||||
query.MetricEditorMode = models.MetricEditorModeRaw
|
||||
query.MetricQueryType = models.MetricQueryTypeSearch
|
||||
query.MatchExact = false
|
||||
query.Expression = `SUM([a,b])`
|
||||
mdq, err := executor.buildMetricDataQuery(query)
|
||||
@@ -116,7 +117,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
const matchExact = true
|
||||
|
||||
t.Run("Query has three dimension values for a given dimension key", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -132,7 +133,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query has three dimension values for two given dimension keys", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -149,7 +150,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("No OR operator was added if a star was used for dimension value", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -165,7 +166,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query has one dimension key with a * value", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -181,7 +182,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query has three dimension values for two given dimension keys, and one value is a star", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -198,7 +199,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query has a dimension key with a space", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/Kafka",
|
||||
MetricName: "CpuUser",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -214,7 +215,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query has a custom namespace contains spaces", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "Test-API Cache by Minute",
|
||||
MetricName: "CpuUser",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -235,7 +236,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
const matchExact = false
|
||||
|
||||
t.Run("Query has three dimension values for a given dimension key", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -251,7 +252,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query has three dimension values for two given dimension keys", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -268,7 +269,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query has one dimension key with a * value", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -284,7 +285,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("query has three dimension values for two given dimension keys, and one value is a star", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -302,7 +303,7 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Query has invalid characters in dimension values", func(t *testing.T) {
|
||||
query := &cloudWatchQuery{
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
@@ -318,8 +319,8 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func getBaseQuery() *cloudWatchQuery {
|
||||
query := &cloudWatchQuery{
|
||||
func getBaseQuery() *models.CloudWatchQuery {
|
||||
query := &models.CloudWatchQuery{
|
||||
Namespace: "AWS/EC2",
|
||||
MetricName: "CPUUtilization",
|
||||
Dimensions: map[string][]string{
|
||||
|
||||
Reference in New Issue
Block a user