- Notifications
You must be signed in to change notification settings - Fork1k
fix: fix metric for hard-limited presets#18045
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -361,15 +361,23 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres | ||
slog.F("preset_name", ps.Preset.Name), | ||
) | ||
// Report a metric only if the preset uses the latest version of the template and the template is not deleted. | ||
// This avoids conflicts between metrics from old and new template versions. | ||
// | ||
// NOTE: Multiple versions of a preset can exist with the same orgName, templateName, and presetName, | ||
// because templates can have multiple versions — or deleted templates can share the same name. | ||
// | ||
// The safest approach is to report the metric only for the latest version of the preset. | ||
// When a new template version is released, the metric for the new preset should overwrite | ||
// the old value in Prometheus. | ||
// | ||
// However, there’s one edge case: if an admin creates a template, it becomes hard-limited, | ||
// then deletes the template and never creates another with the same name, | ||
// the old preset will continue to be reported as hard-limited — | ||
// even though it’s deleted. This will persist until `coderd` is restarted. | ||
if ps.Preset.UsingActiveVersion && !ps.Preset.Deleted { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. What if we added another label for the template version? ContributorAuthor
| ||
c.metrics.trackHardLimitedStatus(ps.Preset.OrganizationName, ps.Preset.TemplateName, ps.Preset.Name, ps.IsHardLimited) | ||
} | ||
// If the preset reached the hard failure limit for the first time during this iteration: | ||
// - Mark it as hard-limited in the database | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1034,15 +1034,18 @@ func TestHardLimitedPresetShouldNotBlockDeletion(t *testing.T) { | ||
require.Equal(t, database.WorkspaceTransitionDelete, workspaceBuilds[0].Transition) | ||
require.Equal(t, database.WorkspaceTransitionStart, workspaceBuilds[1].Transition) | ||
// The metric is still set to 1, even though the preset has become outdated. | ||
// This happens because the old value hasn't been overwritten by a newer preset yet. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: In ContributorAuthor
| ||
mf, err = registry.Gather() | ||
require.NoError(t, err) | ||
metric = findMetric(mf, prebuilds.MetricPresetHardLimitedGauge, map[string]string{ | ||
"template_name": template.Name, | ||
"preset_name": preset.Name, | ||
"org_name": org.Name, | ||
}) | ||
require.NotNil(t, metric) | ||
require.NotNil(t, metric.GetGauge()) | ||
require.EqualValues(t, 1, metric.GetGauge().GetValue()) | ||
}) | ||
} | ||
} | ||
Uh oh!
There was an error while loading.Please reload this page.