-
-
Notifications
You must be signed in to change notification settings - Fork 311
/
static.go
70 lines (61 loc) · 1.75 KB
/
static.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package job
import (
"context"
"sync"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/clients/cloudwatch"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/logging"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
)
func runStaticJob(
ctx context.Context,
logger logging.Logger,
resource model.StaticJob,
clientCloudwatch cloudwatch.Client,
) []*model.CloudwatchData {
cw := []*model.CloudwatchData{}
mux := &sync.Mutex{}
var wg sync.WaitGroup
for j := range resource.Metrics {
metric := resource.Metrics[j]
wg.Add(1)
go func() {
defer wg.Done()
data := model.CloudwatchData{
MetricName: metric.Name,
ResourceName: resource.Name,
Namespace: resource.Namespace,
Dimensions: createStaticDimensions(resource.Dimensions),
MetricMigrationParams: model.MetricMigrationParams{
NilToZero: metric.NilToZero,
AddCloudwatchTimestamp: metric.AddCloudwatchTimestamp,
},
Tags: nil,
GetMetricDataProcessingParams: nil,
GetMetricDataResult: nil,
GetMetricStatisticsResult: nil,
}
data.GetMetricStatisticsResult = &model.GetMetricStatisticsResult{
Datapoints: clientCloudwatch.GetMetricStatistics(ctx, logger, data.Dimensions, resource.Namespace, metric),
Statistics: metric.Statistics,
}
if data.GetMetricStatisticsResult.Datapoints != nil {
mux.Lock()
cw = append(cw, &data)
mux.Unlock()
}
}()
}
wg.Wait()
return cw
}
func createStaticDimensions(dimensions []model.Dimension) []model.Dimension {
out := make([]model.Dimension, 0, len(dimensions))
for _, d := range dimensions {
d := d
out = append(out, model.Dimension{
Name: d.Name,
Value: d.Value,
})
}
return out
}