Skip to content

feat(coderd): support weekly aggregated insights #9684

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 16 commits into from
Sep 19, 2023
Merged
Prev Previous commit
Next Next commit
golden files
  • Loading branch information
mtojek committed Sep 15, 2023
commit 01afb9bf4aa80a47dca0d956ea2ee8e02ff49958
43 changes: 43 additions & 0 deletions coderd/insights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,16 @@ func TestTemplateInsights_Golden(t *testing.T) {
}
},
},
{
name: "weekly aggregated deployment wide",
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
return codersdk.TemplateInsightsRequest{
StartTime: frozenWeekAgo.AddDate(0, 0, -3),
EndTime: frozenWeekAgo.AddDate(0, 0, 4),
Interval: codersdk.InsightsReportIntervalWeek,
}
},
},
{
name: "week all templates",
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
Expand All @@ -933,6 +943,17 @@ func TestTemplateInsights_Golden(t *testing.T) {
}
},
},
{
name: "weekly aggregated templates",
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
return codersdk.TemplateInsightsRequest{
TemplateIDs: []uuid.UUID{templates[0].id, templates[1].id, templates[2].id},
StartTime: frozenWeekAgo.AddDate(0, 0, -1),
EndTime: frozenWeekAgo.AddDate(0, 0, 6),
Interval: codersdk.InsightsReportIntervalWeek,
}
},
},
{
name: "week first template",
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
Expand All @@ -944,6 +965,17 @@ func TestTemplateInsights_Golden(t *testing.T) {
}
},
},
{
name: "weekly aggregated first template",
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
return codersdk.TemplateInsightsRequest{
TemplateIDs: []uuid.UUID{templates[0].id},
StartTime: frozenWeekAgo,
EndTime: frozenWeekAgo.AddDate(0, 0, 7),
Interval: codersdk.InsightsReportIntervalWeek,
}
},
},
{
name: "week second template",
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
Expand All @@ -955,6 +987,17 @@ func TestTemplateInsights_Golden(t *testing.T) {
}
},
},
{
name: "three weeks second template",
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
return codersdk.TemplateInsightsRequest{
TemplateIDs: []uuid.UUID{templates[1].id},
StartTime: frozenWeekAgo.AddDate(0, 0, -14),
EndTime: frozenWeekAgo.AddDate(0, 0, 7),
Interval: codersdk.InsightsReportIntervalWeek,
}
},
},
{
name: "week third template",
makeRequest: func(templates []*testTemplate) codersdk.TemplateInsightsRequest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"report": {
"start_time": "2023-08-01T00:00:00Z",
"end_time": "2023-08-22T00:00:00Z",
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"active_users": 1,
"apps_usage": [
{
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"type": "builtin",
"display_name": "Visual Studio Code",
"slug": "vscode",
"icon": "/icon/code.svg",
"seconds": 3600
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"type": "builtin",
"display_name": "JetBrains",
"slug": "jetbrains",
"icon": "/icon/intellij.svg",
"seconds": 0
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"type": "builtin",
"display_name": "Web Terminal",
"slug": "reconnecting-pty",
"icon": "/icon/terminal.svg",
"seconds": 0
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"type": "builtin",
"display_name": "SSH",
"slug": "ssh",
"icon": "/icon/terminal.svg",
"seconds": 3600
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"type": "app",
"display_name": "app1",
"slug": "app1",
"icon": "/icon1.png",
"seconds": 21600
}
],
"parameters_usage": []
},
"interval_reports": [
{
"start_time": "2023-08-01T00:00:00Z",
"end_time": "2023-08-08T00:00:00Z",
"template_ids": [],
"interval": "week",
"active_users": 0
},
{
"start_time": "2023-08-08T00:00:00Z",
"end_time": "2023-08-15T00:00:00Z",
"template_ids": [],
"interval": "week",
"active_users": 0
},
{
"start_time": "2023-08-15T00:00:00Z",
"end_time": "2023-08-22T00:00:00Z",
"template_ids": [
"00000000-0000-0000-0000-000000000002"
],
"interval": "week",
"active_users": 1
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"report": {
"start_time": "2023-08-12T00:00:00Z",
"end_time": "2023-08-19T00:00:00Z",
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002",
"00000000-0000-0000-0000-000000000003"
],
"active_users": 3,
"apps_usage": [
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002",
"00000000-0000-0000-0000-000000000003"
],
"type": "builtin",
"display_name": "Visual Studio Code",
"slug": "vscode",
"icon": "/icon/code.svg",
"seconds": 7200
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002",
"00000000-0000-0000-0000-000000000003"
],
"type": "builtin",
"display_name": "JetBrains",
"slug": "jetbrains",
"icon": "/icon/intellij.svg",
"seconds": 120
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002",
"00000000-0000-0000-0000-000000000003"
],
"type": "builtin",
"display_name": "Web Terminal",
"slug": "reconnecting-pty",
"icon": "/icon/terminal.svg",
"seconds": 3600
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002",
"00000000-0000-0000-0000-000000000003"
],
"type": "builtin",
"display_name": "SSH",
"slug": "ssh",
"icon": "/icon/terminal.svg",
"seconds": 15120
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002"
],
"type": "app",
"display_name": "app1",
"slug": "app1",
"icon": "/icon1.png",
"seconds": 25380
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"type": "app",
"display_name": "app3",
"slug": "app3",
"icon": "/icon2.png",
"seconds": 3600
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000003"
],
"type": "app",
"display_name": "otherapp1",
"slug": "otherapp1",
"icon": "/icon1.png",
"seconds": 300
}
],
"parameters_usage": []
},
"interval_reports": [
{
"start_time": "2023-08-12T00:00:00Z",
"end_time": "2023-08-19T00:00:00Z",
"template_ids": [
"00000000-0000-0000-0000-000000000001",
"00000000-0000-0000-0000-000000000002",
"00000000-0000-0000-0000-000000000003"
],
"interval": "week",
"active_users": 3
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"report": {
"start_time": "2023-08-15T00:00:00Z",
"end_time": "2023-08-22T00:00:00Z",
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"active_users": 2,
"apps_usage": [
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"type": "builtin",
"display_name": "Visual Studio Code",
"slug": "vscode",
"icon": "/icon/code.svg",
"seconds": 3600
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"type": "builtin",
"display_name": "JetBrains",
"slug": "jetbrains",
"icon": "/icon/intellij.svg",
"seconds": 120
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"type": "builtin",
"display_name": "Web Terminal",
"slug": "reconnecting-pty",
"icon": "/icon/terminal.svg",
"seconds": 0
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"type": "builtin",
"display_name": "SSH",
"slug": "ssh",
"icon": "/icon/terminal.svg",
"seconds": 7920
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"type": "app",
"display_name": "app1",
"slug": "app1",
"icon": "/icon1.png",
"seconds": 3780
},
{
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"type": "app",
"display_name": "app3",
"slug": "app3",
"icon": "/icon2.png",
"seconds": 720
}
],
"parameters_usage": []
},
"interval_reports": [
{
"start_time": "2023-08-15T00:00:00Z",
"end_time": "2023-08-22T00:00:00Z",
"template_ids": [
"00000000-0000-0000-0000-000000000001"
],
"interval": "week",
"active_users": 2
}
]
}
Loading