8000 chore: completing refactor since https://github.com/coder/coder/pull/… · coder/coder@f74d799 · GitHub
[go: up one dir, main page]

Skip to content

Commit f74d799

Browse files
committed
chore: completing refactor since #17792 was since merged
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent 5f62702 commit f74d799

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

enterprise/coderd/prebuilds/metricscollector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
MetricDesiredGauge = namespace + "desired"
2828
MetricRunningGauge = namespace + "running"
2929
MetricEligibleGauge = namespace + "eligible"
30+
MetricLastUpdatedGauge = namespace + "metrics_last_updated"
3031
)
3132

3233
var (
@@ -82,7 +83,7 @@ var (
8283
nil,
8384
)
8485
lastUpdateDesc = prometheus.NewDesc(
85-
"coderd_prebuilt_workspaces_metrics_last_updated",
86+
MetricLastUpdatedGauge,
8687
"The unix timestamp when the metrics related to prebuilt workspaces were last updated; these metrics are cached.",
8788
[]string{},
8889
nil,

enterprise/coderd/prebuilds/reconcile.go

Lines changed: 10 additions & 0 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,16 @@ func (c *StoreReconciler) provision(
641641
return nil
642642
}
643643

644+
// ForceMetricsUpdate forces the metrics collector, if defined, to update its state (we cache the metrics state to
645+
// reduce load on the database).
646+
func (c *StoreReconciler) ForceMetricsUpdate(ctx context.Context) error {
647+
if c.metrics == nil {
648+
return nil
649+
}
650+
651+
return c.metrics.UpdateState(ctx, time.Second*10)
652+
}
653+
644654
func (c *StoreReconciler) TrackResourceReplacement(ctx context.Context, workspaceID, buildID uuid.UUID, replacements []*sdkproto.ResourceReplacement) {
645655
// nolint:gocritic // Necessary to query all the required data.
646656
ctx = dbauthz.AsSystemRestricted(ctx)

enterprise/coderd/prebuilds/reconcile_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ func TestTrackResourceReplacement(t *testing.T) {
968968
prebuiltWorkspace, prebuild := setupTestDBPrebuild(t, clock, db, ps, database.WorkspaceTransitionStart, database.ProvisionerJobStatusSucceeded, org.ID, preset, template.ID, templateVersionID)
969969

970970
// Given: no replacement has been tracked yet, we should not see a metric for it yet.
971+
require.NoError(t, reconciler.ForceMetricsUpdate(ctx))
971972
mf, err := registry.Gather()
972973
require.NoError(t, err)
973974
require.Nil(t, findMetric(mf, prebuilds.MetricResourceReplacementsCount, map[string]string{

0 commit comments

Comments
 (0)
0