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
Prev Previous commit
Next Next commit
Address comments + attempt to fix protoc
  • Loading branch information
ammario committed Sep 1, 2022
commit 22b2028ad6193b222dfd39f5f47f289bb00b389c
11 changes: 7 additions & 4 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,13 @@ jobs:
run: ./scripts/yarn_install.sh

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
# This must be in lockstep with our dogfood Dockerfile
version: "3.21.5"
run: |
# protoc must be in lockstep with our dogfood Dockerfile
# or the version in the comments will differ.
cd dogfood
DOCKER_BUILDKIT=1 docker build . --target proto -t protoc
docker run --rm --entrypoint cat protoc /tmp/bin/protoc > /usr/bin/protoc
chmod +x /usr/bin/protoc
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
Expand Down
14 changes: 7 additions & 7 deletions agent/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ import (
"cdr.dev/slog"
)

// StatsConn wraps a net.Conn with statistics.
type StatsConn struct {
// statsConn wraps a net.Conn with statistics.
type statsConn struct {
*Stats
net.Conn `json:"-"`
}

var _ net.Conn = new(StatsConn)
var _ net.Conn = new(statsConn)

func (c *StatsConn) Read(b []byte) (n int, err error) {
func (c *statsConn) Read(b []byte) (n int, err error) {
n, err = c.Conn.Read(b)
atomic.AddInt64(&c.RxBytes, int64(n))
return n, err
}

func (c *StatsConn) Write(b []byte) (n int, err error) {
func (c *statsConn) Write(b []byte) (n int, err error) {
n, err = c.Conn.Write(b)
atomic.AddInt64(&c.TxBytes, int64(n))
return n, err
}

var _ net.Conn = new(StatsConn)
var _ net.Conn = new(statsConn)

// Stats records the Agent's network connection statistics for use in
// user-facing metrics and debugging.
Expand All @@ -51,7 +51,7 @@ func (s *Stats) Copy() *Stats {
// wrapConn returns a new connection that records statistics.
func (s *Stats) wrapConn(conn net.Conn) net.Conn {
atomic.AddInt64(&s.NumConns, 1)
cs := &StatsConn{
cs := &statsConn{
Stats: s,
Conn: conn,
}
Expand Down
4 changes: 2 additions & 2 deletions coderd/database/databasefake/databasefake.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ func (q *fakeQuerier) GetTemplateDAUs(_ context.Context, templateID uuid.UUID) (
var rs []database.GetTemplateDAUsRow
for _, key := range countKeys {
rs = append(rs, database.GetTemplateDAUsRow{
Date: key,
Daus: int64(len(counts[key])),
Date: key,
Amount: int64(len(counts[key])),
})
}

Expand Down
8 changes: 4 additions & 4 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/queries/agentstats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ VALUES
-- name: GetTemplateDAUs :many
select
(created_at at TIME ZONE 'UTC')::date as date,
count(distinct(user_id)) as daus
count(distinct(user_id)) as amount
from
agent_stats
where template_id = $1
Expand Down
6 changes: 3 additions & 3 deletions coderd/metricscache/metricscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func fillEmptyDays(rows []database.GetTemplateDAUsRow) []database.GetTemplateDAU
break
}
last.Date = last.Date.Add(day)
last.Daus = 0
last.Amount = 0
newRows = append(newRows, last)
diff -= day
}
Expand Down Expand Up @@ -101,8 +101,8 @@ func (c *Cache) refresh(ctx context.Context) error {
var resp codersdk.TemplateDAUsResponse
for _, ent := range fillEmptyDays(daus) {
resp.Entries = append(resp.Entries, codersdk.DAUEntry{
Date: ent.Date,
DAUs: int(ent.Daus),
Date: ent.Date,
Amount: int(ent.Amount),
})
}
templateDAUs[template.ID.String()] = resp
Expand Down
56 changes: 28 additions & 28 deletions coderd/metricscache/metricscache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ func TestCache(t *testing.T) {
},
}, []codersdk.DAUEntry{
{
Date: date(2022, 8, 27),
DAUs: 1,
Date: date(2022, 8, 27),
Amount: 1,
},
{
Date: date(2022, 8, 28),
DAUs: 0,
Date: date(2022, 8, 28),
Amount: 0,
},
{
Date: date(2022, 8, 29),
DAUs: 0,
Date: date(2022, 8, 29),
Amount: 0,
},
{
Date: date(2022, 8, 30),
DAUs: 1,
Date: date(2022, 8, 30),
Amount: 1,
},
}},
{"no holes", args{
Expand All @@ -84,16 +84,16 @@ func TestCache(t *testing.T) {
},
}, []codersdk.DAUEntry{
{
Date: date(2022, 8, 27),
DAUs: 1,
Date: date(2022, 8, 27),
Amount: 1,
},
{
Date: date(2022, 8, 28),
DAUs: 1,
Date: date(2022, 8, 28),
Amount: 1,
},
{
Date: date(2022, 8, 29),
DAUs: 1,
Date: date(2022, 8, 29),
Amount: 1,
},
}},
{"holes", args{
Expand Down Expand Up @@ -121,32 +121,32 @@ func TestCache(t *testing.T) {
},
}, []codersdk.DAUEntry{
{
Date: date(2022, 1, 1),
DAUs: 2,
Date: date(2022, 1, 1),
Amount: 2,
},
{
Date: date(2022, 1, 2),
DAUs: 0,
Date: date(2022, 1, 2),
Amount: 0,
},
{
Date: date(2022, 1, 3),
DAUs: 0,
Date: date(2022, 1, 3),
Amount: 0,
},
{
Date: date(2022, 1, 4),
DAUs: 1,
Date: date(2022, 1, 4),
Amount: 1,
},
{
Date: date(2022, 1, 5),
DAUs: 0,
Date: date(2022, 1, 5),
Amount: 0,
},
{
Date: date(2022, 1, 6),
DAUs: 0,
Date: date(2022, 1, 6),
Amount: 0,
},
{
Date: date(2022, 1, 7),
DAUs: 2,
Date: date(2022, 1, 7),
Amount: 2,
},
}},
}
Expand Down
4 changes: 2 additions & 2 deletions coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ func TestTemplateDAUs(t *testing.T) {
Entries: []codersdk.DAUEntry{
{

Date: time.Now().UTC().Truncate(time.Hour * 24),
DAUs: 1,
Date: time.Now().UTC().Truncate(time.Hour * 24),
Amount: 1,
},
},
}
Expand Down
7 changes: 3 additions & 4 deletions codersdk/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func (c *Client) TemplateVersionByName(ctx context.Context, template uuid.UUID,
}

type DAUEntry struct {
Date time.Time `json:"date"`
DAUs int `json:"daus"`
Date time.Time `json:"date"`
Amount int `json:"amount"`
}

type TemplateDAUsResponse struct {
Expand All @@ -158,10 +158,9 @@ func (c *Client) TemplateDAUs(ctx context.Context, templateID uuid.UUID) (*Templ
return &resp, json.NewDecoder(res.Body).Decode(&resp)
}

// @typescript-ignore AgentStatsReportRequest

// AgentStatsReportRequest is a WebSocket request by coderd
// to the agent for stats.
// @typescript-ignore AgentStatsReportRequest
type AgentStatsReportRequest struct {
}

Expand Down
2 changes: 1 addition & 1 deletion site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export interface CreateWorkspaceRequest {
// From codersdk/templates.go
export interface DAUEntry {
readonly date: string
readonly daus: number
readonly amount: number
}

// From codersdk/workspaceresources.go
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/TemplatePage/DAUChart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("DAUChart", () => {
render(
<DAUChart
templateDAUs={{
entries: [{ date: "2020-01-01", daus: 1 }],
entries: [{ date: "2020-01-01", amount: 1 }],
}}
/>,
)
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/TemplatePage/DAUChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const DAUChart: FC<DAUChartProps> = ({ templateDAUs: templateMetricsData
})

const data = templateMetricsData.entries.map((val) => {
return val.daus
return val.amount
})

defaults.font.family = theme.typography.fontFamily
Expand Down
49 changes: 0 additions & 49 deletions site/src/testHelpers/coder.code-workspace

This file was deleted.

6 changes: 3 additions & 3 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as TypesGen from "../api/typesGenerated"

export const MockTemplateDAUResponse: TypesGen.TemplateDAUsResponse = {
entries: [
{ date: "2022-08-27T00:00:00Z", daus: 1 },
{ date: "2022-08-29T00:00:00Z", daus: 2 },
{ date: "2022-08-30T00:00:00Z", daus: 1 },
{ date: "2022-08-27T00:00:00Z", amount: 1 },
{ date: "2022-08-29T00:00:00Z", amount: 2 },
{ date: "2022-08-30T00:00:00Z", amount: 1 },
],
}
export const MockSessionToken: TypesGen.LoginWithPasswordResponse = {
Expand Down