[v9.3.x] CloudWatch: Cross-account querying support (#59389)
* add cross-account querying support * fix tests
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
type AccountsServiceMock struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (a *AccountsServiceMock) GetAccountsForCurrentUserOrRole() ([]resources.ResourceResponse[resources.Account], error) {
|
||||
args := a.Called()
|
||||
|
||||
return args.Get(0).([]resources.ResourceResponse[resources.Account]), args.Error(1)
|
||||
}
|
||||
@@ -9,9 +9,8 @@ import (
|
||||
)
|
||||
|
||||
type FakeMetricsAPI struct {
|
||||
cloudwatchiface.CloudWatchAPI
|
||||
|
||||
Metrics []*cloudwatch.Metric
|
||||
OwningAccounts []*string
|
||||
MetricsPerPage int
|
||||
}
|
||||
|
||||
@@ -23,7 +22,8 @@ func (c *FakeMetricsAPI) ListMetricsPages(input *cloudwatch.ListMetricsInput, fn
|
||||
|
||||
for i, metrics := range chunks {
|
||||
response := fn(&cloudwatch.ListMetricsOutput{
|
||||
Metrics: metrics,
|
||||
Metrics: metrics,
|
||||
OwningAccounts: c.OwningAccounts,
|
||||
}, i+1 == len(chunks))
|
||||
if !response {
|
||||
break
|
||||
|
||||
@@ -9,26 +9,20 @@ type ListMetricsServiceMock struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (a *ListMetricsServiceMock) GetDimensionKeysByDimensionFilter(r resources.DimensionKeysRequest) ([]string, error) {
|
||||
func (a *ListMetricsServiceMock) GetDimensionKeysByDimensionFilter(r resources.DimensionKeysRequest) ([]resources.ResourceResponse[string], error) {
|
||||
args := a.Called(r)
|
||||
|
||||
return args.Get(0).([]string), args.Error(1)
|
||||
return args.Get(0).([]resources.ResourceResponse[string]), args.Error(1)
|
||||
}
|
||||
|
||||
func (a *ListMetricsServiceMock) GetDimensionValuesByDimensionFilter(r resources.DimensionValuesRequest) ([]string, error) {
|
||||
func (a *ListMetricsServiceMock) GetDimensionValuesByDimensionFilter(r resources.DimensionValuesRequest) ([]resources.ResourceResponse[string], error) {
|
||||
args := a.Called(r)
|
||||
|
||||
return args.Get(0).([]string), args.Error(1)
|
||||
return args.Get(0).([]resources.ResourceResponse[string]), args.Error(1)
|
||||
}
|
||||
|
||||
func (a *ListMetricsServiceMock) GetDimensionKeysByNamespace(namespace string) ([]string, error) {
|
||||
args := a.Called(namespace)
|
||||
func (a *ListMetricsServiceMock) GetMetricsByNamespace(r resources.MetricsRequest) ([]resources.ResourceResponse[resources.Metric], error) {
|
||||
args := a.Called(r)
|
||||
|
||||
return args.Get(0).([]string), args.Error(1)
|
||||
}
|
||||
|
||||
func (a *ListMetricsServiceMock) GetMetricsByNamespace(namespace string) ([]resources.Metric, error) {
|
||||
args := a.Called(namespace)
|
||||
|
||||
return args.Get(0).([]resources.Metric), args.Error(1)
|
||||
return args.Get(0).([]resources.ResourceResponse[resources.Metric]), args.Error(1)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
type LogsAPI struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (l *LogsAPI) DescribeLogGroups(input *cloudwatchlogs.DescribeLogGroupsInput) (*cloudwatchlogs.DescribeLogGroupsOutput, error) {
|
||||
args := l.Called(input)
|
||||
|
||||
return args.Get(0).(*cloudwatchlogs.DescribeLogGroupsOutput), args.Error(1)
|
||||
}
|
||||
|
||||
type LogsService struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (l *LogsService) GetLogGroups(request resources.LogGroupsRequest) ([]resources.ResourceResponse[resources.LogGroup], error) {
|
||||
args := l.Called(request)
|
||||
|
||||
return args.Get(0).([]resources.ResourceResponse[resources.LogGroup]), args.Error(1)
|
||||
}
|
||||
|
||||
type MockFeatures struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (f *MockFeatures) IsEnabled(feature string) bool {
|
||||
args := f.Called(feature)
|
||||
|
||||
return args.Bool(0)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
@@ -9,7 +10,7 @@ type FakeMetricsClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *FakeMetricsClient) ListMetricsWithPageLimit(params *cloudwatch.ListMetricsInput) ([]*cloudwatch.Metric, error) {
|
||||
func (m *FakeMetricsClient) ListMetricsWithPageLimit(params *cloudwatch.ListMetricsInput) ([]resources.MetricResponse, error) {
|
||||
args := m.Called(params)
|
||||
return args.Get(0).([]*cloudwatch.Metric), args.Error(1)
|
||||
return args.Get(0).([]resources.MetricResponse), args.Error(1)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/service/oam"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
type FakeOAMClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (o *FakeOAMClient) ListSinks(input *oam.ListSinksInput) (*oam.ListSinksOutput, error) {
|
||||
args := o.Called(input)
|
||||
return args.Get(0).(*oam.ListSinksOutput), args.Error(1)
|
||||
}
|
||||
|
||||
func (o *FakeOAMClient) ListAttachedLinks(input *oam.ListAttachedLinksInput) (*oam.ListAttachedLinksOutput, error) {
|
||||
args := o.Called(input)
|
||||
return args.Get(0).(*oam.ListAttachedLinksOutput), args.Error(1)
|
||||
}
|
||||
Reference in New Issue
Block a user