Skip to content

fix: use floats in report template #14714

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 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
notificationsManager.Run(dbauthz.AsSystemRestricted(ctx))

// Run report generator to distribute periodic reports.
notificationReportGenerator := reports.NewReportGenerator(ctx, logger, options.Database, options.NotificationsEnqueuer, quartz.NewReal())
notificationReportGenerator := reports.NewReportGenerator(ctx, logger.Named("notifications.report_generator"), options.Database, options.NotificationsEnqueuer, quartz.NewReal())
defer notificationReportGenerator.Close()
}

Expand Down
5 changes: 5 additions & 0 deletions coderd/database/migrations/000254_fix_report_float.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UPDATE notification_templates
SET
body_template = REPLACE(body_template::text, '{{if gt $version.failed_count 1.0}}', '{{if gt $version.failed_count 1}}')::text
WHERE
id = '34a20db2-e9cc-4a93-b0e4-8569699d7a00';
5 changes: 5 additions & 0 deletions coderd/database/migrations/000254_fix_report_float.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
UPDATE notification_templates
SET
body_template = REPLACE(body_template::text, '{{if gt $version.failed_count 1}}', '{{if gt $version.failed_count 1.0}}')::text
WHERE
id = '34a20db2-e9cc-4a93-b0e4-8569699d7a00';
17 changes: 9 additions & 8 deletions coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,40 +853,41 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
"template_name": "bobby-first-template",
"template_display_name": "Bobby First Template",
},
// We need to use floats as `json.Unmarshal` unmarshal numbers in `map[string]any` to floats.
Data: map[string]any{
"failed_builds": 4,
"total_builds": 55,
"failed_builds": 4.0,
"total_builds": 55.0,
"report_frequency": "week",
"template_versions": []map[string]any{
{
"template_version_name": "bobby-template-version-1",
"failed_count": 3,
"failed_count": 3.0,
"failed_builds": []map[string]any{
{
"workspace_owner_username": "mtojek",
"workspace_name": "workspace-1",
"build_number": 1234,
"build_number": 1234.0,
},
{
"workspace_owner_username": "johndoe",
"workspace_name": "my-workspace-3",
"build_number": 5678,
"build_number": 5678.0,
},
{
"workspace_owner_username": "jack",
"workspace_name": "workwork",
"build_number": 774,
"build_number": 774.0,
},
},
},
{
"template_version_name": "bobby-template-version-2",
"failed_count": 1,
"failed_count": 1.0,
"failed_builds": []map[string]any{
{
"workspace_owner_username": "ben",
"workspace_name": "cool-workspace",
"build_number": 8888,
"build_number": 8888.0,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions coderd/notifications/reports/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func NewReportGenerator(ctx context.Context, logger slog.Logger, db database.Sto
return
case tick := <-ticker.C:
ticker.Stop()

doTick(dbtime.Time(tick).UTC())
}
}
Expand Down
Loading