New creates a new CloudWatch instance
(ctx context.Context, config *Config, stats *stats.Stats)
| 38 | |
| 39 | // New creates a new CloudWatch instance |
| 40 | func New(ctx context.Context, config *Config, stats *stats.Stats) (*CloudWatch, error) { |
| 41 | if !config.Enabled() { |
| 42 | return nil, nil |
| 43 | } |
| 44 | |
| 45 | cw := &CloudWatch{ |
| 46 | config: config, |
| 47 | stats: stats, |
| 48 | } |
| 49 | |
| 50 | if err := config.Validate(); err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | |
| 54 | conf, err := awsConfig.LoadDefaultConfig(ctx) |
| 55 | if err != nil { |
| 56 | return nil, fmt.Errorf("can't load CloudWatch config: %w", err) |
| 57 | } |
| 58 | |
| 59 | if len(config.Region) > 0 { |
| 60 | conf.Region = config.Region |
| 61 | } |
| 62 | |
| 63 | if len(conf.Region) == 0 { |
| 64 | conf.Region = defaultAwsRegion |
| 65 | } |
| 66 | |
| 67 | cw.client = cloudwatch.NewFromConfig(conf) |
| 68 | cw.collectorCtx, cw.collectorCtxCancel = context.WithCancel(ctx) |
| 69 | |
| 70 | go cw.runMetricsCollector() |
| 71 | |
| 72 | return cw, nil |
| 73 | } |
| 74 | |
| 75 | // Stop stops the CloudWatch metrics collection |
| 76 | func (cw *CloudWatch) Stop(ctx context.Context) { |
no test coverage detected