Skip to content

Commit 3f4696b

Browse files
committed
Finish impl
1 parent 27fc9a0 commit 3f4696b

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

agent/agentssh/agentssh.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,6 @@ func (s *Server) sessionHandler(session ssh.Session) {
218218
_ = session.Exit(0)
219219
}
220220

221-
func magicType(session ssh.Session) string {
222-
for _, kv := range session.Environ() {
223-
if !strings.HasPrefix(kv, MagicSessionTypeEnvironmentVariable) {
224-
continue
225-
}
226-
return strings.TrimPrefix(kv, MagicSessionTypeEnvironmentVariable+"=")
227-
}
228-
return ""
229-
}
230-
231221
func (s *Server) sessionStart(session ssh.Session, extraEnv []string) (retErr error) {
232222
ctx := session.Context()
233223
env := append(session.Environ(), extraEnv...)

coderd/prometheusmetrics/aggregator.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/prometheus/client_golang/prometheus"
8+
"golang.org/x/exp/slices"
89
"golang.org/x/xerrors"
910

1011
"cdr.dev/slog"
@@ -56,7 +57,6 @@ type annotatedMetric struct {
5657
username string
5758
workspaceName string
5859
agentName string
59-
labels []agentsdk.AgentMetricLabel
6060

6161
expiryDate time.Time
6262
}
@@ -123,7 +123,7 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
123123
UpdateLoop:
124124
for _, m := range req.metrics {
125125
for i, q := range ma.queue {
126-
if q.username == req.username && q.workspaceName == req.workspaceName && q.agentName == req.agentName && q.Name == m.Name && q.labels == m.Labels {
126+
if q.username == req.username && q.workspaceName == req.workspaceName && q.agentName == req.agentName && q.Name == m.Name && slices.Equal(q.Labels, m.Labels) {
127127
ma.queue[i].AgentMetric.Value = m.Value
128128
ma.queue[i].expiryDate = req.timestamp.Add(ma.metricsCleanupInterval)
129129
continue UpdateLoop
@@ -147,13 +147,40 @@ func (ma *MetricsAggregator) Run(ctx context.Context) func() {
147147

148148
output := make([]prometheus.Metric, 0, len(ma.queue))
149149
for _, m := range ma.queue {
150-
desc := prometheus.NewDesc(m.Name, metricHelpForAgent, agentMetricsLabels, nil)
150+
labels := make([]string, len(agentMetricsLabels)+len(m.Labels))
151+
var i int
152+
for _, l := range agentMetricsLabels {
153+
labels[i] = l
154+
i++
155+
}
156+
157+
for _, l := range m.Labels {
158+
labels[i] = l.Name
159+
i++
160+
}
161+
162+
desc := prometheus.NewDesc(m.Name, metricHelpForAgent, labels, nil)
151163
valueType, err := asPrometheusValueType(m.Type)
152164
if err != nil {
153165
ma.log.Error(ctx, "can't convert Prometheus value type", slog.F("name", m.Name), slog.F("type", m.Type), slog.F("value", m.Value), slog.Error(err))
154166
continue
155167
}
156-
constMetric := prometheus.MustNewConstMetric(desc, valueType, m.Value, m.username, m.workspaceName, m.agentName)
168+
169+
labelValues := make([]string, len(agentMetricsLabels)+len(m.Labels))
170+
labelValues[0] = m.username
171+
labelValues[1] = m.workspaceName
172+
labelValues[2] = m.agentName
173+
174+
if len(m.Labels) > 0 {
175+
i = 3
176+
177+
for _, l := range m.Labels {
178+
labelValues[i] = l.Value
179+
i++
180+
}
181+
}
182+
183+
constMetric := prometheus.MustNewConstMetric(desc, valueType, m.Value, labelValues...)
157184
output = append(output, constMetric)
158185
}
159186
outputCh <- output

0 commit comments

Comments
 (0)