forked from fluxcd/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitoring.go
76 lines (63 loc) · 1.84 KB
/
monitoring.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
71
72
73
74
75
76
// Monitoring middlewares for registry interfaces
package registry
import (
"strconv"
"time"
"github.com/weaveworks/flux"
fluxmetrics "github.com/weaveworks/flux/metrics"
)
type InstrumentedRegistry Registry
type instrumentedRegistry struct {
next Registry
}
func NewInstrumentedRegistry(next Registry) InstrumentedRegistry {
return &instrumentedRegistry{
next: next,
}
}
func (m *instrumentedRegistry) GetRepository(repository Repository) (res []flux.Image, err error) {
start := time.Now()
res, err = m.next.GetRepository(repository)
fetchDuration.With(
fluxmetrics.LabelSuccess, strconv.FormatBool(err == nil),
).Observe(time.Since(start).Seconds())
return
}
func (m *instrumentedRegistry) GetImage(repository Repository, tag string) (res flux.Image, err error) {
start := time.Now()
res, err = m.next.GetImage(repository, tag)
fetchDuration.With(
fluxmetrics.LabelSuccess, strconv.FormatBool(err == nil),
).Observe(time.Since(start).Seconds())
return
}
type InstrumentedRemote Remote
type instrumentedRemote struct {
next Remote
}
func NewInstrumentedRemote(next Remote) Remote {
return &instrumentedRemote{
next: next,
}
}
func (m *instrumentedRemote) Manifest(repository Repository, tag string) (res flux.Image, err error) {
start := time.Now()
res, err = m.next.Manifest(repository, tag)
requestDuration.With(
LabelRequestKind, RequestKindMetadata,
fluxmetrics.LabelSuccess, strconv.FormatBool(err == nil),
).Observe(time.Since(start).Seconds())
return
}
func (m *instrumentedRemote) Tags(repository Repository) (res []string, err error) {
start := time.Now()
res, err = m.next.Tags(repository)
requestDuration.With(
LabelRequestKind, RequestKindTags,
fluxmetrics.LabelSuccess, strconv.FormatBool(err == nil),
).Observe(time.Since(start).Seconds())
return
}
func (m *instrumentedRemote) Cancel() {
m.next.Cancel()
}