mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 23:53:10 +08:00

Fix unexpected error when creating a new cloudwatch datasource. Involves a fair amount of refactoring, so if this causes unexpected issues related to region fetching we can turn this off with the cloudwatchNewRegionsHandler feature toggle, although we do not predict it will so we are enabling it to default to true and hope to remove it shortly.
73 lines
3.0 KiB
Go
73 lines
3.0 KiB
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
|
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
|
"github.com/aws/aws-sdk-go/service/oam"
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources"
|
|
)
|
|
|
|
type RequestContextFactoryFunc func(ctx context.Context, pluginCtx backend.PluginContext, region string) (reqCtx RequestContext, err error)
|
|
|
|
type RouteHandlerFunc func(ctx context.Context, pluginCtx backend.PluginContext, reqContextFactory RequestContextFactoryFunc, parameters url.Values) ([]byte, *HttpError)
|
|
|
|
type RequestContext struct {
|
|
MetricsClientProvider MetricsClientProvider
|
|
LogsAPIProvider CloudWatchLogsAPIProvider
|
|
OAMAPIProvider OAMAPIProvider
|
|
EC2APIProvider EC2APIProvider
|
|
Settings CloudWatchSettings
|
|
Features featuremgmt.FeatureToggles
|
|
}
|
|
|
|
// Services
|
|
type ListMetricsProvider interface {
|
|
GetDimensionKeysByDimensionFilter(resources.DimensionKeysRequest) ([]resources.ResourceResponse[string], error)
|
|
GetDimensionValuesByDimensionFilter(resources.DimensionValuesRequest) ([]resources.ResourceResponse[string], error)
|
|
GetMetricsByNamespace(r resources.MetricsRequest) ([]resources.ResourceResponse[resources.Metric], error)
|
|
}
|
|
|
|
type LogGroupsProvider interface {
|
|
GetLogGroups(request resources.LogGroupsRequest) ([]resources.ResourceResponse[resources.LogGroup], error)
|
|
GetLogGroupFields(request resources.LogGroupFieldsRequest) ([]resources.ResourceResponse[resources.LogGroupField], error)
|
|
}
|
|
|
|
type AccountsProvider interface {
|
|
GetAccountsForCurrentUserOrRole() ([]resources.ResourceResponse[resources.Account], error)
|
|
}
|
|
|
|
type RegionsAPIProvider interface {
|
|
GetRegions() ([]resources.ResourceResponse[resources.Region], error)
|
|
}
|
|
|
|
// Clients
|
|
type MetricsClientProvider interface {
|
|
ListMetricsWithPageLimit(params *cloudwatch.ListMetricsInput) ([]resources.MetricResponse, error)
|
|
}
|
|
|
|
// APIs - instead of using the API defined in the services within the aws-sdk-go directly, specify a subset of the API with methods that are actually used in a service or a client
|
|
type CloudWatchMetricsAPIProvider interface {
|
|
ListMetricsPages(*cloudwatch.ListMetricsInput, func(*cloudwatch.ListMetricsOutput, bool) bool) error
|
|
}
|
|
|
|
type CloudWatchLogsAPIProvider interface {
|
|
DescribeLogGroups(*cloudwatchlogs.DescribeLogGroupsInput) (*cloudwatchlogs.DescribeLogGroupsOutput, error)
|
|
GetLogGroupFields(*cloudwatchlogs.GetLogGroupFieldsInput) (*cloudwatchlogs.GetLogGroupFieldsOutput, error)
|
|
}
|
|
|
|
type OAMAPIProvider interface {
|
|
ListSinks(*oam.ListSinksInput) (*oam.ListSinksOutput, error)
|
|
ListAttachedLinks(*oam.ListAttachedLinksInput) (*oam.ListAttachedLinksOutput, error)
|
|
}
|
|
|
|
type EC2APIProvider interface {
|
|
DescribeRegions(in *ec2.DescribeRegionsInput) (*ec2.DescribeRegionsOutput, error)
|
|
DescribeInstancesPages(in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool) error
|
|
}
|