Skip to content

feat: expose insights into user activity #9807

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 26 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Fix user IDs
  • Loading branch information
mtojek committed Sep 26, 2023
commit 4ce994f39f2b03bb729d59f5c2dd70d811537afd
32 changes: 30 additions & 2 deletions coderd/insights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,9 @@ func TestUserActivityInsights_Golden(t *testing.T) {

client *codersdk.Client
sdk codersdk.User

// Filled later.
id uuid.UUID
}

// Represent agent stats, to be inserted via stats batcher.
Expand Down Expand Up @@ -1341,6 +1344,10 @@ func TestUserActivityInsights_Golden(t *testing.T) {
for _, template := range templates {
template.id = newStableUUID()
}
for _, user := range users {
user.id = newStableUUID()
}

for _, user := range users {
for _, workspace := range user.workspaces {
workspace.user = user
Expand Down Expand Up @@ -1395,9 +1402,30 @@ func TestUserActivityInsights_Golden(t *testing.T) {

// Prepare all test users.
for _, user := range users {
user.client, user.sdk = coderdtest.CreateAnotherUserMutators(t, client, firstUser.OrganizationID, nil, func(r *codersdk.CreateUserRequest) {
r.Username = user.name
_ = dbgen.User(t, db, database.User{
ID: user.id,
Username: user.name,
Status: database.UserStatusActive,
})
_ = dbgen.OrganizationMember(t, db, database.OrganizationMember{
UserID: user.id,
OrganizationID: firstUser.OrganizationID,
})
token, err := client.CreateToken(context.Background(), user.id.String(), codersdk.CreateTokenRequest{
Lifetime: time.Hour * 24,
Scope: codersdk.APIKeyScopeAll,
TokenName: "no-password-user-token",
})
require.NoError(t, err)
userClient := codersdk.New(client.URL)
userClient.SetSessionToken(token.Key)

coderUser, err := userClient.User(context.Background(), user.id.String())
require.NoError(t, err)

user.client = userClient
user.sdk = coderUser

user.client.SetLogger(logger.Named("user").With(slog.Field{Name: "name", Value: user.name}))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 32400
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note-to-self: At first I thought this looked off, comparing the template golden file for the same setup, but upon verifying with the data it looks good, there is indeed 9h of distinct usage. 👍🏻

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
"00000000-0000-0000-0000-000000000003"
],
"users": [
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 30540
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note-to-self: Also verified this number, 1h is lost from users[0].workspaces[1] due to timeframe and all the minute intervals are summed from users[0].workspaces[0] giving us 8h + 29m. The hours in u0w0 overlap with u0w1 so we don't see an increase from those.

},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "037c6a21-c805-46d8-a1ff-d98096afb44a",
"user_id": "00000000-0000-0000-0000-000000000005",
"username": "user2",
"avatar_url": "",
"seconds": 3600
Expand All @@ -21,20 +31,10 @@
"template_ids": [
"00000000-0000-0000-0000-000000000003"
],
"user_id": "297dcbb4-2463-487a-92cd-7443d8d2a82d",
"user_id": "00000000-0000-0000-0000-000000000006",
"username": "user3",
"avatar_url": "",
"seconds": 4200
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"username": "user1",
"avatar_url": "",
"seconds": 30540
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
"00000000-0000-0000-0000-000000000003"
],
"users": [
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 30540
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "037c6a21-c805-46d8-a1ff-d98096afb44a",
"user_id": "00000000-0000-0000-0000-000000000005",
"username": "user2",
"avatar_url": "",
"seconds": 3600
Expand All @@ -21,20 +31,10 @@
"template_ids": [
"00000000-0000-0000-0000-000000000003"
],
"user_id": "297dcbb4-2463-487a-92cd-7443d8d2a82d",
"user_id": "00000000-0000-0000-0000-000000000006",
"username": "user3",
"avatar_url": "",
"seconds": 4200
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"username": "user1",
"avatar_url": "",
"seconds": 30540
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "037c6a21-c805-46d8-a1ff-d98096afb44a",
"username": "user2",
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 3600
"seconds": 5340
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"username": "user1",
"user_id": "00000000-0000-0000-0000-000000000005",
"username": "user2",
"avatar_url": "",
"seconds": 5340
"seconds": 3600
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
"00000000-0000-0000-0000-000000000003"
],
"users": [
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 23280
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "037c6a21-c805-46d8-a1ff-d98096afb44a",
"user_id": "00000000-0000-0000-0000-000000000005",
"username": "user2",
"avatar_url": "",
"seconds": 3600
Expand All @@ -21,20 +31,10 @@
"template_ids": [
"00000000-0000-0000-0000-000000000003"
],
"user_id": "297dcbb4-2463-487a-92cd-7443d8d2a82d",
"user_id": "00000000-0000-0000-0000-000000000006",
"username": "user3",
"avatar_url": "",
"seconds": 600
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"username": "user1",
"avatar_url": "",
"seconds": 23280
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 25200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"template_ids": [
"00000000-0000-0000-0000-000000000003"
],
"user_id": "297dcbb4-2463-487a-92cd-7443d8d2a82d",
"user_id": "00000000-0000-0000-0000-000000000006",
"username": "user3",
"avatar_url": "",
"seconds": 4200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
"00000000-0000-0000-0000-000000000003"
],
"users": [
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 29820
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "037c6a21-c805-46d8-a1ff-d98096afb44a",
"user_id": "00000000-0000-0000-0000-000000000005",
"username": "user2",
"avatar_url": "",
"seconds": 7200
Expand All @@ -21,20 +31,10 @@
"template_ids": [
"00000000-0000-0000-0000-000000000003"
],
"user_id": "297dcbb4-2463-487a-92cd-7443d8d2a82d",
"user_id": "00000000-0000-0000-0000-000000000006",
"username": "user3",
"avatar_url": "",
"seconds": 4200
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"username": "user1",
"avatar_url": "",
"seconds": 29820
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "037c6a21-c805-46d8-a1ff-d98096afb44a",
"username": "user2",
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 3600
"seconds": 5340
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"username": "user1",
"user_id": "00000000-0000-0000-0000-000000000005",
"username": "user2",
"avatar_url": "",
"seconds": 5340
"seconds": 3600
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
"00000000-0000-0000-0000-000000000003"
],
"users": [
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "00000000-0000-0000-0000-000000000004",
"username": "user1",
"avatar_url": "",
"seconds": 29820
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"user_id": "037c6a21-c805-46d8-a1ff-d98096afb44a",
"user_id": "00000000-0000-0000-0000-000000000005",
"username": "user2",
"avatar_url": "",
"seconds": 7200
Expand All @@ -21,20 +31,10 @@
"template_ids": [
"00000000-0000-0000-0000-000000000003"
],
"user_id": "297dcbb4-2463-487a-92cd-7443d8d2a82d",
"user_id": "00000000-0000-0000-0000-000000000006",
"username": "user3",
"avatar_url": "",
"seconds": 4200
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"user_id": "aba84ddd-48c3-4041-98db-f80913a424a3",
"username": "user1",
"avatar_url": "",
"seconds": 29820
}
]
}
Expand Down