MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / New

Function New

monitoring/cloudwatch/cloudwatch.go:40–73  ·  view source on GitHub ↗

New creates a new CloudWatch instance

(ctx context.Context, config *Config, stats *stats.Stats)

Source from the content-addressed store, hash-verified

38
39// New creates a new CloudWatch instance
40func 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
76func (cw *CloudWatch) Stop(ctx context.Context) {

Callers 1

NewFunction · 0.92

Calls 4

runMetricsCollectorMethod · 0.95
ErrorfMethod · 0.80
EnabledMethod · 0.65
ValidateMethod · 0.45

Tested by

no test coverage detected