Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f9a1d5

Browse files
committed
spike comments
1 parent78fc14f commit5f9a1d5

File tree

4 files changed

+83
-117
lines changed

4 files changed

+83
-117
lines changed

‎coderd/database/pubsub/pubsub_test.go

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"testing"
77

88
"github.com/prometheus/client_golang/prometheus"
9-
dto"github.com/prometheus/client_model/go"
109
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211

@@ -43,8 +42,8 @@ func TestPGPubsub_Metrics(t *testing.T) {
4342

4443
metrics,err:=registry.Gather()
4544
require.NoError(t,err)
46-
require.True(t,gaugeHasValue(t,metrics,0,"coder_pubsub_current_events"))
47-
require.True(t,gaugeHasValue(t,metrics,0,"coder_pubsub_current_subscribers"))
45+
require.True(t,testutil.PromGaugeHasValue(t,metrics,0,"coder_pubsub_current_events"))
46+
require.True(t,testutil.PromGaugeHasValue(t,metrics,0,"coder_pubsub_current_subscribers"))
4847

4948
event:="test"
5049
data:="testing"
@@ -63,14 +62,14 @@ func TestPGPubsub_Metrics(t *testing.T) {
6362
require.Eventually(t,func()bool {
6463
metrics,err=registry.Gather()
6564
assert.NoError(t,err)
66-
returngaugeHasValue(t,metrics,1,"coder_pubsub_current_events")&&
67-
gaugeHasValue(t,metrics,1,"coder_pubsub_current_subscribers")&&
68-
gaugeHasValue(t,metrics,1,"coder_pubsub_connected")&&
69-
counterHasValue(t,metrics,1,"coder_pubsub_publishes_total","true")&&
70-
counterHasValue(t,metrics,1,"coder_pubsub_subscribes_total","true")&&
71-
counterHasValue(t,metrics,1,"coder_pubsub_messages_total","normal")&&
72-
counterHasValue(t,metrics,7,"coder_pubsub_received_bytes_total")&&
73-
counterHasValue(t,metrics,7,"coder_pubsub_published_bytes_total")
65+
returntestutil.PromGaugeHasValue(t,metrics,1,"coder_pubsub_current_events")&&
66+
testutil.PromGaugeHasValue(t,metrics,1,"coder_pubsub_current_subscribers")&&
67+
testutil.PromGaugeHasValue(t,metrics,1,"coder_pubsub_connected")&&
68+
testutil.PromCounterHasValue(t,metrics,1,"coder_pubsub_publishes_total","true")&&
69+
testutil.PromCounterHasValue(t,metrics,1,"coder_pubsub_subscribes_total","true")&&
70+
testutil.PromCounterHasValue(t,metrics,1,"coder_pubsub_messages_total","normal")&&
71+
testutil.PromCounterHasValue(t,metrics,7,"coder_pubsub_received_bytes_total")&&
72+
testutil.PromCounterHasValue(t,metrics,7,"coder_pubsub_published_bytes_total")
7473
},testutil.WaitShort,testutil.IntervalFast)
7574

7675
colossalData:=make([]byte,7600)
@@ -93,54 +92,14 @@ func TestPGPubsub_Metrics(t *testing.T) {
9392
require.Eventually(t,func()bool {
9493
metrics,err=registry.Gather()
9594
assert.NoError(t,err)
96-
returngaugeHasValue(t,metrics,1,"coder_pubsub_current_events")&&
97-
gaugeHasValue(t,metrics,2,"coder_pubsub_current_subscribers")&&
98-
gaugeHasValue(t,metrics,1,"coder_pubsub_connected")&&
99-
counterHasValue(t,metrics,2,"coder_pubsub_publishes_total","true")&&
100-
counterHasValue(t,metrics,2,"coder_pubsub_subscribes_total","true")&&
101-
counterHasValue(t,metrics,1,"coder_pubsub_messages_total","normal")&&
102-
counterHasValue(t,metrics,1,"coder_pubsub_messages_total","colossal")&&
103-
counterHasValue(t,metrics,7607,"coder_pubsub_received_bytes_total")&&
104-
counterHasValue(t,metrics,7607,"coder_pubsub_published_bytes_total")
95+
returntestutil.PromGaugeHasValue(t,metrics,1,"coder_pubsub_current_events")&&
96+
testutil.PromGaugeHasValue(t,metrics,2,"coder_pubsub_current_subscribers")&&
97+
testutil.PromGaugeHasValue(t,metrics,1,"coder_pubsub_connected")&&
98+
testutil.PromCounterHasValue(t,metrics,2,"coder_pubsub_publishes_total","true")&&
99+
testutil.PromCounterHasValue(t,metrics,2,"coder_pubsub_subscribes_total","true")&&
100+
testutil.PromCounterHasValue(t,metrics,1,"coder_pubsub_messages_total","normal")&&
101+
testutil.PromCounterHasValue(t,metrics,1,"coder_pubsub_messages_total","colossal")&&
102+
testutil.PromCounterHasValue(t,metrics,7607,"coder_pubsub_received_bytes_total")&&
103+
testutil.PromCounterHasValue(t,metrics,7607,"coder_pubsub_published_bytes_total")
105104
},testutil.WaitShort,testutil.IntervalFast)
106105
}
107-
108-
funcgaugeHasValue(t testing.TB,metrics []*dto.MetricFamily,valuefloat64,namestring,label...string)bool {
109-
t.Helper()
110-
for_,family:=rangemetrics {
111-
iffamily.GetName()!=name {
112-
continue
113-
}
114-
ms:=family.GetMetric()
115-
for_,m:=rangems {
116-
require.Equal(t,len(label),len(m.GetLabel()))
117-
fori,lv:=rangelabel {
118-
iflv!=m.GetLabel()[i].GetValue() {
119-
continue
120-
}
121-
}
122-
returnvalue==m.GetGauge().GetValue()
123-
}
124-
}
125-
returnfalse
126-
}
127-
128-
funccounterHasValue(t testing.TB,metrics []*dto.MetricFamily,valuefloat64,namestring,label...string)bool {
129-
t.Helper()
130-
for_,family:=rangemetrics {
131-
iffamily.GetName()!=name {
132-
continue
133-
}
134-
ms:=family.GetMetric()
135-
for_,m:=rangems {
136-
require.Equal(t,len(label),len(m.GetLabel()))
137-
fori,lv:=rangelabel {
138-
iflv!=m.GetLabel()[i].GetValue() {
139-
continue
140-
}
141-
}
142-
returnvalue==m.GetCounter().GetValue()
143-
}
144-
}
145-
returnfalse
146-
}

‎coderd/tailnet.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ func NewServerTailnet(
9898
agentConnectionTimes:map[uuid.UUID]time.Time{},
9999
agentTickets:map[uuid.UUID]map[uuid.UUID]struct{}{},
100100
transport:tailnetTransport.Clone(),
101-
connsPerAgent:prometheus.NewGaugeVec(prometheus.GaugeOpts{
101+
connsPerAgent:prometheus.NewGauge(prometheus.GaugeOpts{
102102
Namespace:"coder",
103103
Subsystem:"servertailnet",
104-
Name:"open_conns",
104+
Name:"open_tcp_connections",
105105
Help:"Total number of TCP connections currently open to workspace agents.",
106-
}, []string{"agent_id"}),
107-
totalConns:prometheus.NewCounterVec(prometheus.CounterOpts{
106+
}),
107+
totalConns:prometheus.NewCounter(prometheus.CounterOpts{
108108
Namespace:"coder",
109109
Subsystem:"servertailnet",
110-
Name:"total_conns",
110+
Name:"tcp_connections_total",
111111
Help:"Total number of TCP connections made to workspace agents.",
112-
}, []string{"agent_id"}),
112+
}),
113113
}
114114
tn.transport.DialContext=tn.dialContext
115115
// These options are mostly just picked at random, and they can likely be
@@ -328,8 +328,8 @@ type ServerTailnet struct {
328328

329329
transport*http.Transport
330330

331-
connsPerAgent*prometheus.GaugeVec
332-
totalConns*prometheus.CounterVec
331+
connsPerAgent prometheus.Gauge
332+
totalConns prometheus.Counter
333333
}
334334

335335
func (s*ServerTailnet)ReverseProxy(targetURL,dashboardURL*url.URL,agentID uuid.UUID)*httputil.ReverseProxy {
@@ -380,8 +380,8 @@ func (s *ServerTailnet) dialContext(ctx context.Context, network, addr string) (
380380
returnnil,err
381381
}
382382

383-
s.connsPerAgent.With(prometheus.Labels{"agent_id":agentID.String()}).Inc()
384-
s.totalConns.With(prometheus.Labels{"agent_id":agentID.String()}).Inc()
383+
s.connsPerAgent.Inc()
384+
s.totalConns.Inc()
385385
return&instrumentedConn{
386386
Conn:nc,
387387
agentID:agentID,
@@ -498,12 +498,12 @@ type instrumentedConn struct {
498498

499499
agentID uuid.UUID
500500
closeOnce sync.Once
501-
connsPerAgent*prometheus.GaugeVec
501+
connsPerAgent prometheus.Gauge
502502
}
503503

504504
func (c*instrumentedConn)Close()error {
505505
c.closeOnce.Do(func() {
506-
c.connsPerAgent.With(prometheus.Labels{"agent_id":c.agentID.String()}).Dec()
506+
c.connsPerAgent.Dec()
507507
})
508508
returnc.Conn.Close()
509509
}

‎coderd/tailnet_test.go

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/google/uuid"
1616
"github.com/prometheus/client_golang/prometheus"
17-
dto"github.com/prometheus/client_model/go"
1817
"github.com/spf13/afero"
1918
"github.com/stretchr/testify/assert"
2019
"github.com/stretchr/testify/require"
@@ -113,8 +112,8 @@ func TestServerTailnet_ReverseProxy(t *testing.T) {
113112
require.Eventually(t,func()bool {
114113
metrics,err:=registry.Gather()
115114
assert.NoError(t,err)
116-
returncounterHasValue(t,metrics,1,"coder_servertailnet_total_conns",a.id.String())&&
117-
gaugeHasValue(t,metrics,1,"coder_servertailnet_open_conns",a.id.String())
115+
returntestutil.PromCounterHasValue(t,metrics,1,"coder_servertailnet_tcp_connections_total")&&
116+
testutil.PromGaugeHasValue(t,metrics,1,"coder_servertailnet_open_tcp_connections")
118117
},testutil.WaitShort,testutil.IntervalFast)
119118
})
120119

@@ -367,45 +366,3 @@ func setupServerTailnetAgent(t *testing.T, agentNum int) ([]agentWithID, *coderd
367366

368367
returnagents,serverTailnet
369368
}
370-
371-
funcgaugeHasValue(t testing.TB,metrics []*dto.MetricFamily,valuefloat64,namestring,label...string)bool {
372-
t.Helper()
373-
for_,family:=rangemetrics {
374-
iffamily.GetName()!=name {
375-
continue
376-
}
377-
ms:=family.GetMetric()
378-
metricsLoop:
379-
for_,m:=rangems {
380-
require.Equal(t,len(label),len(m.GetLabel()))
381-
fori,lv:=rangelabel {
382-
iflv!=m.GetLabel()[i].GetValue() {
383-
continue metricsLoop
384-
}
385-
}
386-
returnvalue==m.GetGauge().GetValue()
387-
}
388-
}
389-
returnfalse
390-
}
391-
392-
funccounterHasValue(t testing.TB,metrics []*dto.MetricFamily,valuefloat64,namestring,label...string)bool {
393-
t.Helper()
394-
for_,family:=rangemetrics {
395-
iffamily.GetName()!=name {
396-
continue
397-
}
398-
ms:=family.GetMetric()
399-
metricsLoop:
400-
for_,m:=rangems {
401-
require.Equal(t,len(label),len(m.GetLabel()))
402-
fori,lv:=rangelabel {
403-
iflv!=m.GetLabel()[i].GetValue() {
404-
continue metricsLoop
405-
}
406-
}
407-
returnvalue==m.GetCounter().GetValue()
408-
}
409-
}
410-
returnfalse
411-
}

‎testutil/prometheus.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package testutil
2+
3+
import (
4+
"testing"
5+
6+
dto"github.com/prometheus/client_model/go"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
funcPromGaugeHasValue(t testing.TB,metrics []*dto.MetricFamily,valuefloat64,namestring,label...string)bool {
11+
t.Helper()
12+
for_,family:=rangemetrics {
13+
iffamily.GetName()!=name {
14+
continue
15+
}
16+
ms:=family.GetMetric()
17+
metricsLoop:
18+
for_,m:=rangems {
19+
require.Equal(t,len(label),len(m.GetLabel()))
20+
fori,lv:=rangelabel {
21+
iflv!=m.GetLabel()[i].GetValue() {
22+
continue metricsLoop
23+
}
24+
}
25+
returnvalue==m.GetGauge().GetValue()
26+
}
27+
}
28+
returnfalse
29+
}
30+
31+
funcPromCounterHasValue(t testing.TB,metrics []*dto.MetricFamily,valuefloat64,namestring,label...string)bool {
32+
t.Helper()
33+
for_,family:=rangemetrics {
34+
iffamily.GetName()!=name {
35+
continue
36+
}
37+
ms:=family.GetMetric()
38+
metricsLoop:
39+
for_,m:=rangems {
40+
require.Equal(t,len(label),len(m.GetLabel()))
41+
fori,lv:=rangelabel {
42+
iflv!=m.GetLabel()[i].GetValue() {
43+
continue metricsLoop
44+
}
45+
}
46+
returnvalue==m.GetCounter().GetValue()
47+
}
48+
}
49+
returnfalse
50+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp