-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathmetrics.go
102 lines (91 loc) · 3.09 KB
/
metrics.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package agent
import (
"sync"
"github.com/gitpod-io/gitpod/agent-smith/pkg/detector"
"github.com/prometheus/client_golang/prometheus"
)
type metrics struct {
penaltyAttempts *prometheus.CounterVec
penaltyFailures *prometheus.CounterVec
classificationBackpressureInCount prometheus.GaugeFunc
classificationBackpressureOutCount prometheus.GaugeFunc
classificationBackpressureInDrop prometheus.Counter
mu sync.RWMutex
cl []prometheus.Collector
}
func newAgentMetrics() *metrics {
m := &metrics{}
m.penaltyAttempts = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "gitpod",
Subsystem: "agent_smith",
Name: "penalty_attempts_total",
Help: "The total amount of attempts that agent-smith is trying to apply a penalty.",
}, []string{"penalty"},
)
m.penaltyFailures = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "gitpod",
Subsystem: "agent_smith",
Name: "penalty_attempts_failed_total",
Help: "The total amount of failed attempts that agent-smith is trying to apply a penalty.",
}, []string{"penalty", "reason"},
)
m.classificationBackpressureInDrop = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "gitpod",
Subsystem: "agent_smith",
Name: "classification_backpressure_in_drop_total",
Help: "total count of processes that went unclassified because of backpressure",
})
m.cl = []prometheus.Collector{
m.penaltyAttempts,
m.penaltyFailures,
m.classificationBackpressureInDrop,
}
return m
}
func (m *metrics) RegisterClassificationQueues(in chan detector.Process, out chan classifiedProcess) {
m.mu.Lock()
defer m.mu.Unlock()
m.classificationBackpressureInCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "gitpod",
Subsystem: "agent_smith",
Name: "classification_backpressure_in_count",
Help: "processes queued for classification",
}, func() float64 { return float64(len(in)) })
m.classificationBackpressureOutCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "gitpod",
Subsystem: "agent_smith",
Name: "classification_backpressure_out_count",
Help: "processes coming out of classification",
}, func() float64 { return float64(len(out)) })
}
func (m *metrics) Describe(d chan<- *prometheus.Desc) {
m.mu.RLock()
defer m.mu.RUnlock()
if m.classificationBackpressureInCount != nil {
m.classificationBackpressureInCount.Describe(d)
}
if m.classificationBackpressureOutCount != nil {
m.classificationBackpressureOutCount.Describe(d)
}
for _, c := range m.cl {
c.Describe(d)
}
}
func (m *metrics) Collect(d chan<- prometheus.Metric) {
m.mu.RLock()
defer m.mu.RUnlock()
if m.classificationBackpressureInCount != nil {
m.classificationBackpressureInCount.Collect(d)
}
if m.classificationBackpressureOutCount != nil {
m.classificationBackpressureOutCount.Collect(d)
}
for _, c := range m.cl {
c.Collect(d)
}
}