Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1804a9

Browse files
committed
Fix continuous stats
1 parent 12a52b1 commit a1804a9

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

agent/agent.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"os/exec"
1818
"os/user"
1919
"path/filepath"
20+
"reflect"
2021
"runtime"
2122
"sort"
2223
"strconv"
@@ -155,6 +156,7 @@ type agent struct {
155156

156157
network *tailnet.Conn
157158
connStatsChan chan *agentsdk.Stats
159+
latestStat atomic.Pointer[agentsdk.Stats]
158160

159161
connCountVSCode atomic.Int64
160162
connCountJetBrains atomic.Int64
@@ -1241,6 +1243,13 @@ func (a *agent) startReportingConnectionStats(ctx context.Context) {
12411243
// Convert from microseconds to milliseconds.
12421244
stats.ConnectionMedianLatencyMS /= 1000
12431245

1246+
lastStat := a.latestStat.Load()
1247+
if lastStat != nil && reflect.DeepEqual(lastStat, stats) {
1248+
a.logger.Info(ctx, "skipping stat because nothing changed")
1249+
return
1250+
}
1251+
a.latestStat.Store(stats)
1252+
12441253
select {
12451254
case a.connStatsChan <- stats:
12461255
default:

agent/agent_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ func TestAgent_Stats_Magic(t *testing.T) {
156156
require.Eventuallyf(t, func() bool {
157157
var ok bool
158158
s, ok = <-stats
159-
fmt.Printf("WE GOT STATS %+v\n", s)
160159
return ok && s.ConnectionCount > 0 && s.RxBytes > 0 && s.TxBytes > 0 &&
161160
// Ensure that the connection didn't count as a "normal" SSH session.
162161
// This was a special one, so it should be labeled specially in the stats!

cli/deployment/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func newConfig() *codersdk.DeploymentConfig {
406406
Usage: "How frequently agent stats are recorded",
407407
Flag: "agent-stats-refresh-interval",
408408
Hidden: true,
409-
Default: time.Minute,
409+
Default: 30 * time.Second,
410410
},
411411
AgentFallbackTroubleshootingURL: &codersdk.DeploymentConfigField[string]{
412412
Name: "Agent Fallback Troubleshooting URL",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ replace github.com/tcnksm/go-httpstat => github.com/kylecarbs/go-httpstat v0.0.0
4040

4141
// There are a few minor changes we make to Tailscale that we're slowly upstreaming. Compare here:
4242
// https://github.com/tailscale/tailscale/compare/main...coder:tailscale:main
43-
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20230301203426-fb16ae7c5bba
43+
replace tailscale.com => github.com/coder/tailscale v1.1.1-0.20230306185501-ae6dbba0a7ee
4444

4545
// Switch to our fork that imports fixes from http://github.com/tailscale/ssh.
4646
// See: https://github.com/coder/coder/issues/3371

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ github.com/coder/tailscale v1.1.1-0.20230228220447-d27e5d3056e9 h1:bFcFXLUUi+cwg
407407
github.com/coder/tailscale v1.1.1-0.20230228220447-d27e5d3056e9/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
408408
github.com/coder/tailscale v1.1.1-0.20230301203426-fb16ae7c5bba h1:JOD5pqNtiz9lkSX74PY2BJOyNqsBmvGUjFGIuECtG+o=
409409
github.com/coder/tailscale v1.1.1-0.20230301203426-fb16ae7c5bba/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
410+
github.com/coder/tailscale v1.1.1-0.20230306185501-ae6dbba0a7ee h1:0o3Q9u7+r7zNPaRCW/bLXuxPv8ukExtyig7RZfzcs8A=
411+
github.com/coder/tailscale v1.1.1-0.20230306185501-ae6dbba0a7ee/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
410412
github.com/coder/terraform-provider-coder v0.6.14 h1:NsJ1mo0MN1x/VyNLYmsgPUYn2JgzdVNZBqnj9OSIDgY=
411413
github.com/coder/terraform-provider-coder v0.6.14/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
412414
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=

0 commit comments

Comments
 (0)