mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Cloudwatch: Prevent log group requests with ARNs if feature flag is off (#75672)
This commit is contained in:
parent
ac3fe55d17
commit
b83a58ef55
@ -19,6 +19,7 @@ import (
|
|||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -211,7 +212,7 @@ func (e *cloudWatchExecutor) executeStartQuery(ctx context.Context, logsClient c
|
|||||||
QueryString: aws.String(modifiedQueryString),
|
QueryString: aws.String(modifiedQueryString),
|
||||||
}
|
}
|
||||||
|
|
||||||
if logsQuery.LogGroups != nil && len(logsQuery.LogGroups) > 0 {
|
if logsQuery.LogGroups != nil && len(logsQuery.LogGroups) > 0 && e.features.IsEnabled(featuremgmt.FlagCloudWatchCrossAccountQuerying) {
|
||||||
var logGroupIdentifiers []string
|
var logGroupIdentifiers []string
|
||||||
for _, lg := range logsQuery.LogGroups {
|
for _, lg := range logsQuery.LogGroups {
|
||||||
arn := lg.Arn
|
arn := lg.Arn
|
||||||
|
@ -450,6 +450,110 @@ func Test_executeStartQuery(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}, cli.calls.startQueryWithContext)
|
}, cli.calls.startQueryWithContext)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("uses LogGroupNames if the cross account feature flag is not enabled, and log group names is present", func(t *testing.T) {
|
||||||
|
cli = fakeCWLogsClient{}
|
||||||
|
im := datasource.NewInstanceManager(func(ctx context.Context, s backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
||||||
|
return DataSource{Settings: models.CloudWatchSettings{}}, nil
|
||||||
|
})
|
||||||
|
executor := newExecutor(im, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures())
|
||||||
|
_, err := executor.QueryData(context.Background(), &backend.QueryDataRequest{
|
||||||
|
PluginContext: backend.PluginContext{DataSourceInstanceSettings: &backend.DataSourceInstanceSettings{}},
|
||||||
|
Queries: []backend.DataQuery{
|
||||||
|
{
|
||||||
|
RefID: "A",
|
||||||
|
TimeRange: backend.TimeRange{From: time.Unix(0, 0), To: time.Unix(1, 0)},
|
||||||
|
JSON: json.RawMessage(`{
|
||||||
|
"type": "logAction",
|
||||||
|
"subtype": "StartQuery",
|
||||||
|
"limit": 12,
|
||||||
|
"queryString":"fields @message",
|
||||||
|
"logGroups":[{"arn": "*fake**ARN*"}],
|
||||||
|
"LogGroupNames": ["/log-group-name"]
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []*cloudwatchlogs.StartQueryInput{
|
||||||
|
{
|
||||||
|
StartTime: aws.Int64(0),
|
||||||
|
EndTime: aws.Int64(1),
|
||||||
|
Limit: aws.Int64(12),
|
||||||
|
QueryString: aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
|
||||||
|
LogGroupNames: []*string{aws.String("/log-group-name")},
|
||||||
|
},
|
||||||
|
}, cli.calls.startQueryWithContext)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("ignores logGroups if feature flag is disabled even if logGroupNames is not present", func(t *testing.T) {
|
||||||
|
cli = fakeCWLogsClient{}
|
||||||
|
im := datasource.NewInstanceManager(func(ctx context.Context, s backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
||||||
|
return DataSource{Settings: models.CloudWatchSettings{}}, nil
|
||||||
|
})
|
||||||
|
executor := newExecutor(im, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures())
|
||||||
|
_, err := executor.QueryData(context.Background(), &backend.QueryDataRequest{
|
||||||
|
PluginContext: backend.PluginContext{DataSourceInstanceSettings: &backend.DataSourceInstanceSettings{}},
|
||||||
|
Queries: []backend.DataQuery{
|
||||||
|
{
|
||||||
|
RefID: "A",
|
||||||
|
TimeRange: backend.TimeRange{From: time.Unix(0, 0), To: time.Unix(1, 0)},
|
||||||
|
JSON: json.RawMessage(`{
|
||||||
|
"type": "logAction",
|
||||||
|
"subtype": "StartQuery",
|
||||||
|
"limit": 12,
|
||||||
|
"queryString":"fields @message",
|
||||||
|
"logGroups":[{"arn": "*fake**ARN*"}]
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []*cloudwatchlogs.StartQueryInput{
|
||||||
|
{
|
||||||
|
StartTime: aws.Int64(0),
|
||||||
|
EndTime: aws.Int64(1),
|
||||||
|
Limit: aws.Int64(12),
|
||||||
|
QueryString: aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
|
||||||
|
LogGroupNames: []*string{},
|
||||||
|
},
|
||||||
|
}, cli.calls.startQueryWithContext)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("it always uses logGroups when feature flag is enabled and ignores log group names", func(t *testing.T) {
|
||||||
|
cli = fakeCWLogsClient{}
|
||||||
|
im := datasource.NewInstanceManager(func(ctx context.Context, s backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
||||||
|
return DataSource{Settings: models.CloudWatchSettings{}}, nil
|
||||||
|
})
|
||||||
|
executor := newExecutor(im, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures(featuremgmt.FlagCloudWatchCrossAccountQuerying))
|
||||||
|
_, err := executor.QueryData(context.Background(), &backend.QueryDataRequest{
|
||||||
|
PluginContext: backend.PluginContext{DataSourceInstanceSettings: &backend.DataSourceInstanceSettings{}},
|
||||||
|
Queries: []backend.DataQuery{
|
||||||
|
{
|
||||||
|
RefID: "A",
|
||||||
|
TimeRange: backend.TimeRange{From: time.Unix(0, 0), To: time.Unix(1, 0)},
|
||||||
|
JSON: json.RawMessage(`{
|
||||||
|
"type": "logAction",
|
||||||
|
"subtype": "StartQuery",
|
||||||
|
"limit": 12,
|
||||||
|
"queryString":"fields @message",
|
||||||
|
"logGroups":[{"arn": "*fake**ARN*"}],
|
||||||
|
"logGroupNames":["/log-group"]
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, []*cloudwatchlogs.StartQueryInput{
|
||||||
|
{
|
||||||
|
StartTime: aws.Int64(0),
|
||||||
|
EndTime: aws.Int64(1),
|
||||||
|
Limit: aws.Int64(12),
|
||||||
|
QueryString: aws.String("fields @timestamp,ltrim(@log) as __log__grafana_internal__,ltrim(@logStream) as __logstream__grafana_internal__|fields @message"),
|
||||||
|
LogGroupIdentifiers: []*string{aws.String("*fake**ARN")},
|
||||||
|
},
|
||||||
|
}, cli.calls.startQueryWithContext)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuery_StopQuery(t *testing.T) {
|
func TestQuery_StopQuery(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user