use logger context in cloudwatch (#57842)

This commit is contained in:
Yuriy Tseretyan
2022-11-02 10:14:02 -04:00
committed by GitHub
parent e3a4bde622
commit 3a5ddbfbdf
19 changed files with 93 additions and 92 deletions
@@ -14,7 +14,8 @@ import (
"github.com/google/uuid"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/cwlog"
"github.com/grafana/grafana/pkg/infra/log"
)
type (
@@ -61,7 +62,7 @@ type CloudWatchQuery struct {
MetricEditorMode MetricEditorMode
}
func (q *CloudWatchQuery) GetGMDAPIMode() GMDApiMode {
func (q *CloudWatchQuery) GetGMDAPIMode(logger log.Logger) GMDApiMode {
if q.MetricQueryType == MetricQueryTypeSearch && q.MetricEditorMode == MetricEditorModeBuilder {
if q.IsInferredSearchExpression() {
return GMDApiModeInferredSearchExpression
@@ -73,7 +74,7 @@ func (q *CloudWatchQuery) GetGMDAPIMode() GMDApiMode {
return GMDApiModeSQLExpression
}
cwlog.Warn("could not resolve CloudWatch metric query type. Falling back to metric stat.", "query", q)
logger.Warn("could not resolve CloudWatch metric query type. Falling back to metric stat.", "query", q)
return GMDApiModeMetricStat
}
@@ -10,6 +10,8 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/infra/log/logtest"
)
func TestCloudWatchQuery(t *testing.T) {
@@ -642,7 +644,7 @@ func Test_ParseMetricDataQueries_query_type_and_metric_editor_mode_and_GMD_query
require.NotNil(t, res[0])
assert.Equal(t, tc.expectedMetricQueryType, res[0].MetricQueryType)
assert.Equal(t, tc.expectedMetricEditorMode, res[0].MetricEditorMode)
assert.Equal(t, tc.expectedGMDApiMode, res[0].GetGMDAPIMode())
assert.Equal(t, tc.expectedGMDApiMode, res[0].GetGMDAPIMode(&logtest.Fake{}))
})
}
}