Skip to content

Commit d9cd468

Browse files
committed
Correct backoff calculation
int32 was overflowing Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent 8e2732a commit d9cd468

File tree

11 files changed

+18
-18
lines changed

11 files changed

+18
-18
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ func (q *querier) GetPresetParametersByTemplateVersionID(ctx context.Context, te
20562056
return q.db.GetPresetParametersByTemplateVersionID(ctx, templateVersionID)
20572057
}
20582058

2059-
func (q *querier) GetPresetsBackoff(ctx context.Context, period int32) ([]database.GetPresetsBackoffRow, error) {
2059+
func (q *querier) GetPresetsBackoff(ctx context.Context, period int64) ([]database.GetPresetsBackoffRow, error) {
20602060
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceTemplate); err != nil {
20612061
return nil, err
20622062
}

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4066,7 +4066,7 @@ func (q *FakeQuerier) GetPresetParametersByTemplateVersionID(_ context.Context,
40664066
return parameters, nil
40674067
}
40684068

4069-
func (q *FakeQuerier) GetPresetsBackoff(ctx context.Context, period int32) ([]database.GetPresetsBackoffRow, error) {
4069+
func (q *FakeQuerier) GetPresetsBackoff(ctx context.Context, period int64) ([]database.GetPresetsBackoffRow, error) {
40704070
panic("not implemented")
40714071
}
40724072

coderd/database/dbmetrics/querymetrics.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/prebuilds.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ WITH filtered_builds AS (
6565
SELECT preset_id, COUNT(*) AS num_failed
6666
FROM filtered_builds
6767
WHERE job_status = 'failed'::provisioner_job_status
68-
AND created_at >= NOW() - (sqlc.arg('lookback')::integer * INTERVAL '1 microsecond') -- microsecond is the smallest unit in PG
68+
AND created_at >= NOW() - (sqlc.arg('lookback')::bigint * INTERVAL '1 microsecond') -- microsecond is the smallest unit in PG, bigint is used because Go deals with time as int64
6969
GROUP BY preset_id)
7070
SELECT lb.template_version_id,
7171
lb.preset_id,

coderd/prebuilds/noop.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ func NewNoopReconciler() *NoopReconciler {
1212
return &NoopReconciler{}
1313
}
1414

15-
func (NoopReconciler) RunLoop(ctx context.Context) {}
16-
func (NoopReconciler) Stop(ctx context.Context, cause error) {}
17-
func (NoopReconciler) SnapshotState(ctx context.Context, store database.Store) (*ReconciliationState, error) { return &ReconciliationState{}, nil }
18-
func (NoopReconciler) DetermineActions(ctx context.Context, state PresetState) (*ReconciliationActions, error) { return &ReconciliationActions{}, nil}
19-
func (NoopReconciler) Reconcile(ctx context.Context, state PresetState, actions ReconciliationActions) error { return nil}
15+
func (NoopReconciler) RunLoop(context.Context) {}
16+
func (NoopReconciler) Stop(context.Context, error) {}
17+
func (NoopReconciler) SnapshotState(context.Context, database.Store) (*ReconciliationState, error) { return &ReconciliationState{}, nil }
18+
func (NoopReconciler) DetermineActions(context.Context, PresetState) (*ReconciliationActions, error) { return &ReconciliationActions{}, nil}
19+
func (NoopReconciler) Reconcile(context.Context, PresetState, ReconciliationActions) error { return nil}
2020

2121
var _ ReconciliationOrchestrator = NoopReconciler{}

coderd/prebuilds/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func GenerateName() (string, error) {
2727
}
2828

2929
// DurationToInterval converts a given duration to microseconds, which is the unit PG represents intervals in.
30-
func DurationToInterval(d time.Duration) int32 {
30+
func DurationToInterval(d time.Duration) int64 {
3131
// Convert duration to seconds (as an example)
32-
return int32(d.Microseconds())
32+
return d.Microseconds()
3333
}

codersdk/deployment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ Write out the current server config as YAML to stdout.`,
29752975
Name: "Reconciliation Backoff Interval",
29762976
Description: "Interval to increase reconciliation backoff by when unrecoverable errors occur.",
29772977
Flag: "workspace-prebuilds-reconciliation-backoff-interval",
2978-
Env: "CODER_WORKSPACE_PREBUILDS_RECONCILIATION_INTERVAL",
2978+
Env: "CODER_WORKSPACE_PREBUILDS_RECONCILIATION_BACKOFF_INTERVAL",
29792979
Value: &c.Prebuilds.ReconciliationBackoffInterval,
29802980
Default: (time.Second * 15).String(),
29812981
Group: &deploymentGroupPrebuilds,
@@ -2986,7 +2986,7 @@ Write out the current server config as YAML to stdout.`,
29862986
Name: "Reconciliation Backoff Lookback Period",
29872987
Description: "Interval to look back to determine number of failed builds, which influences backoff.",
29882988
Flag: "workspace-prebuilds-reconciliation-backoff-lookback-period",
2989-
Env: "CODER_WORKSPACE_PREBUILDS_LOOKBACK_PERIOD",
2989+
Env: "CODER_WORKSPACE_PREBUILDS_RECONCILIATION_BACKOFF_LOOKBACK_PERIOD",
29902990
Value: &c.Prebuilds.ReconciliationBackoffLookback,
29912991
Default: (time.Hour).String(), // TODO: use https://pkg.go.dev/github.com/jackc/pgtype@v1.12.0#Interval
29922992
Group: &deploymentGroupPrebuilds,

0 commit comments

Comments
 (0)