-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.go
68 lines (57 loc) · 1.61 KB
/
handler.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
package main
import (
"fmt"
"log"
"sync"
"github.com/anodot/anodot-common/pkg/metrics3"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
)
type SyncMetricList struct {
mux sync.Mutex
metrics []metrics3.AnodotMetrics30
}
func (ml *SyncMetricList) Append(newmetrics []metrics3.AnodotMetrics30) {
ml.mux.Lock()
defer ml.mux.Unlock()
ml.metrics = append(ml.metrics, newmetrics...)
}
type ErrorList struct {
mux sync.Mutex
errors []error
}
func (el *ErrorList) Append(err error) {
el.mux.Lock()
defer el.mux.Unlock()
el.errors = append(el.errors, err)
}
func Handle(resources map[string]*MonitoredResource, wg *sync.WaitGroup, sess *session.Session, cloudwatchsvc *cloudwatch.CloudWatch, ml *SyncMetricList, el *ErrorList) {
for resourceName, resource := range resources {
wg.Add(1)
rs := resource
session_copy := sess
rname := resourceName
go func(wg *sync.WaitGroup, ss *session.Session, rs *MonitoredResource, rname string) {
defer wg.Done()
mfunc := GetMetricsFunction(rname)
metrics, err := mfunc(ss, cloudwatchsvc, rs)
if err != nil {
log.Printf("ERROR encoutered during processing %s metrics ", rname)
el.Append(err)
return
}
sId, ok := schemaIds[rname]
if !ok {
el.Append(fmt.Errorf("failed to get schema ID for %s", rname))
return
}
metricsUpdated := make([]metrics3.AnodotMetrics30, 0)
for _, m := range metrics {
m.SchemaId = sId
metricsUpdated = append(metricsUpdated, m)
}
log.Printf("Got %d metrics for %s", len(metrics), rname)
ml.Append(metricsUpdated)
}(wg, session_copy, rs, rname)
}
}