Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ee/agent-smith/pkg/agent/metrics.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package agent
6
7
import (
8
"sync"
9
10
"github.com/gitpod-io/gitpod/agent-smith/pkg/detector"
11
"github.com/prometheus/client_golang/prometheus"
12
)
13
14
type metrics struct {
15
penaltyAttempts *prometheus.CounterVec
16
penaltyFailures *prometheus.CounterVec
17
classificationBackpressureInCount prometheus.GaugeFunc
18
classificationBackpressureOutCount prometheus.GaugeFunc
19
classificationBackpressureInDrop prometheus.Counter
20
21
mu sync.RWMutex
22
cl []prometheus.Collector
23
}
24
25
func newAgentMetrics() *metrics {
26
m := &metrics{}
27
28
m.penaltyAttempts = prometheus.NewCounterVec(
29
prometheus.CounterOpts{
30
Namespace: "gitpod",
31
Subsystem: "agent_smith",
32
Name: "penalty_attempts_total",
33
Help: "The total amount of attempts that agent-smith is trying to apply a penalty.",
34
}, []string{"penalty"},
35
)
36
m.penaltyFailures = prometheus.NewCounterVec(
37
prometheus.CounterOpts{
38
Namespace: "gitpod",
39
Subsystem: "agent_smith",
40
Name: "penalty_attempts_failed_total",
41
Help: "The total amount of failed attempts that agent-smith is trying to apply a penalty.",
42
}, []string{"penalty", "reason"},
43
)
44
m.classificationBackpressureInDrop = prometheus.NewCounter(prometheus.CounterOpts{
45
Namespace: "gitpod",
46
Subsystem: "agent_smith",
47
Name: "classification_backpressure_in_drop_total",
48
Help: "total count of processes that went unclassified because of backpressure",
49
})
50
m.cl = []prometheus.Collector{
51
m.penaltyAttempts,
52
m.penaltyFailures,
53
m.classificationBackpressureInDrop,
54
}
55
return m
56
}
57
58
func (m *metrics) RegisterClassificationQueues(in chan detector.Process, out chan classifiedProcess) {
59
m.mu.Lock()
60
defer m.mu.Unlock()
61
62
m.classificationBackpressureInCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
63
Namespace: "gitpod",
64
Subsystem: "agent_smith",
65
Name: "classification_backpressure_in_count",
66
Help: "processes queued for classification",
67
}, func() float64 { return float64(len(in)) })
68
m.classificationBackpressureOutCount = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
69
Namespace: "gitpod",
70
Subsystem: "agent_smith",
71
Name: "classification_backpressure_out_count",
72
Help: "processes coming out of classification",
73
}, func() float64 { return float64(len(out)) })
74
}
75
76
func (m *metrics) Describe(d chan<- *prometheus.Desc) {
77
m.mu.RLock()
78
defer m.mu.RUnlock()
79
if m.classificationBackpressureInCount != nil {
80
m.classificationBackpressureInCount.Describe(d)
81
}
82
if m.classificationBackpressureOutCount != nil {
83
m.classificationBackpressureOutCount.Describe(d)
84
}
85
for _, c := range m.cl {
86
c.Describe(d)
87
}
88
}
89
90
func (m *metrics) Collect(d chan<- prometheus.Metric) {
91
m.mu.RLock()
92
defer m.mu.RUnlock()
93
if m.classificationBackpressureInCount != nil {
94
m.classificationBackpressureInCount.Collect(d)
95
}
96
if m.classificationBackpressureOutCount != nil {
97
m.classificationBackpressureOutCount.Collect(d)
98
}
99
for _, c := range m.cl {
100
c.Collect(d)
101
}
102
}
103
104