Skip to content

Daily Active User Metrics #3735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
502aa52
agent: add ConnStats
ammario Aug 29, 2022
3893045
agent: add StatsReporter
ammario Aug 29, 2022
c03ad90
Frontend tests pass
ammario Sep 1, 2022
1bd9cec
Split DAUChart into its own file
ammario Sep 1, 2022
e46329b
Get FE tests passing with real data!
ammario Sep 1, 2022
d472b13
Test frontend
ammario Sep 1, 2022
e0295e0
Fix compilation error
ammario Sep 1, 2022
2f1a423
Rename ConnStats to StatsConn
ammario Sep 1, 2022
0a50cc9
continues instead of returns
ammario Sep 1, 2022
7feab5e
Fix some test failures
ammario Sep 1, 2022
a4d2cf7
Redo tests
ammario Sep 1, 2022
52c9d10
Address review comments
ammario Sep 1, 2022
3f9901e
REVAMP — backend tests work
ammario Sep 1, 2022
7840509
Black triangle
ammario Sep 1, 2022
39170cf
Consolidate template state machines
ammario Sep 1, 2022
eb373d6
Move workspaceagent endpoint
ammario Sep 1, 2022
a3d87b8
Address most review comments
ammario Sep 1, 2022
31ba0c6
Improve contrast in chart
ammario Sep 1, 2022
5b906c1
Add more agent tests
ammario Sep 1, 2022
49d9386
Fix JS ci
ammario Sep 1, 2022
b14a077
A bunch of minor touch ups
ammario Sep 1, 2022
8da24c4
Stabilize protoc
ammario Sep 1, 2022
00ec953
Merge remote-tracking branch 'origin/main' into metrics
ammario Sep 1, 2022
4940319
Update lockfile
ammario Sep 1, 2022
22b2028
Address comments + attempt to fix protoc
ammario Sep 1, 2022
0157365
fixup! Address comments + attempt to fix protoc
ammario Sep 1, 2022
b166cdd
Try to fix protoc...
ammario Sep 1, 2022
4201998
PROTO!
ammario Sep 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
agent: add ConnStats
  • Loading branch information
ammario committed Sep 1, 2022
commit 502aa5240183a8e05c14ccee70ed232fb1fb8d8b
38 changes: 38 additions & 0 deletions agent/stats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package agent

import (
"net"
"time"
)

// ConnStats wraps a net.Conn with statistics.
type ConnStats struct {
CreatedAt time.Time `json:"created_at,omitempty"`
Protocol string `json:"protocol,omitempty"`
RxBytes uint64 `json:"rx_bytes,omitempty"`
TxBytes uint64 `json:"tx_bytes,omitempty"`

net.Conn `json:"-"`
}

var _ net.Conn = new(ConnStats)

func (c *ConnStats) Read(b []byte) (n int, err error) {
n, err = c.Conn.Read(b)
c.RxBytes += uint64(n)
return n, err
}

func (c *ConnStats) Write(b []byte) (n int, err error) {
n, err = c.Conn.Write(b)
c.TxBytes += uint64(n)
return n, err
}

var _ net.Conn = new(ConnStats)

// Stats records the Agent's network connection statistics for use in
// user-facing metrics and debugging.
type Stats struct {
Conns []ConnStats `json:"conns,omitempty"`
}
61 changes: 61 additions & 0 deletions agent/stats_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package agent_test

import (
"io"
"net"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/agent"
)

func TestConnStats(t *testing.T) {
t.Parallel()

t.Run("Write", func(t *testing.T) {
t.Parallel()

c1, c2 := net.Pipe()

payload := []byte("dogs & cats")
statsConn := &agent.ConnStats{Conn: c1}

got := make(chan []byte)
go func() {
b, _ := io.ReadAll(c2)
got <- b
}()
n, err := statsConn.Write(payload)
require.NoError(t, err)
assert.Equal(t, len(payload), n)
statsConn.Close()

require.Equal(t, payload, <-got)

require.EqualValues(t, statsConn.TxBytes, len(payload))
require.EqualValues(t, statsConn.RxBytes, 0)
})

t.Run("Read", func(t *testing.T) {
t.Parallel()

c1, c2 := net.Pipe()

payload := []byte("cats & dogs")
statsConn := &agent.ConnStats{Conn: c1}

go func() {
c2.Write(payload)
c2.Close()
}()

got, err := io.ReadAll(statsConn)
require.NoError(t, err)
assert.Equal(t, len(payload), len(got))

require.EqualValues(t, statsConn.RxBytes, len(payload))
require.EqualValues(t, statsConn.TxBytes, 0)
})
}