/
store.go
44 lines (37 loc) · 1.07 KB
/
store.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
package controller
import (
"context"
log "github.com/sirupsen/logrus"
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/schemas"
"github.com/mvisonneau/gitlab-ci-pipelines-exporter/pkg/store"
)
func metricLogFields(m schemas.Metric) log.Fields {
return log.Fields{
"metric-kind": m.Kind,
"metric-labels": m.Labels,
}
}
func storeGetMetric(ctx context.Context, s store.Store, m *schemas.Metric) {
if err := s.GetMetric(ctx, m); err != nil {
log.WithContext(ctx).
WithFields(metricLogFields(*m)).
WithError(err).
Errorf("reading metric from the store")
}
}
func storeSetMetric(ctx context.Context, s store.Store, m schemas.Metric) {
if err := s.SetMetric(ctx, m); err != nil {
log.WithContext(ctx).
WithFields(metricLogFields(m)).
WithError(err).
Errorf("writing metric from the store")
}
}
func storeDelMetric(ctx context.Context, s store.Store, m schemas.Metric) {
if err := s.DelMetric(ctx, m.Key()); err != nil {
log.WithContext(ctx).
WithFields(metricLogFields(m)).
WithError(err).
Errorf("deleting metric from the store")
}
}