- Notifications
You must be signed in to change notification settings - Fork928
feat(coderd): export metric indicating each experiment's status#12657
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
62c0551
c93e4e2
6f351d7
50ccb7c
11abaa6
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 |
---|---|---|
@@ -258,6 +258,7 @@ func enablePrometheus( | ||
), nil | ||
} | ||
//nolint:gocognit // TODO(dannyk): reduce complexity of this function | ||
func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *serpent.Command { | ||
if newAPI == nil { | ||
newAPI = func(_ context.Context, o *coderd.Options) (*coderd.API, io.Closer, error) { | ||
@@ -892,6 +893,15 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd. | ||
return xerrors.Errorf("register agents prometheus metric: %w", err) | ||
} | ||
defer closeAgentsFunc() | ||
var active codersdk.Experiments | ||
for _, exp := range options.DeploymentValues.Experiments.Value() { | ||
active = append(active, codersdk.Experiment(exp)) | ||
} | ||
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. This is fine, but optionally to keep it cleaner, you could move this to | ||
if err = prometheusmetrics.Experiments(options.PrometheusRegistry, active); err != nil { | ||
return xerrors.Errorf("register experiments metric: %w", err) | ||
} | ||
} | ||
client := codersdk.New(localURL) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -516,6 +516,32 @@ func AgentStats(ctx context.Context, logger slog.Logger, registerer prometheus.R | ||
}, nil | ||
} | ||
// Experiments registers a metric which indicates whether each experiment is enabled or not. | ||
func Experiments(registerer prometheus.Registerer, active codersdk.Experiments) error { | ||
experimentsGauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: "coderd", | ||
Name: "experiments", | ||
Help: "Indicates whether each experiment is enabled (1) or not (0)", | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
}, []string{"experiment"}) | ||
if err := registerer.Register(experimentsGauge); err != nil { | ||
return err | ||
} | ||
for _, exp := range codersdk.ExperimentsAll { | ||
var val float64 | ||
for _, enabled := range active { | ||
if exp == enabled { | ||
val = 1 | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
break | ||
} | ||
} | ||
experimentsGauge.WithLabelValues(string(exp)).Set(val) | ||
} | ||
return nil | ||
} | ||
// filterAcceptableAgentLabels handles a slightly messy situation whereby `prometheus-aggregate-agent-stats-by` can control on | ||
// which labels agent stats are aggregated, but for these specific metrics in this file there is no `template` label value, | ||
// and therefore we have to exclude it from the list of acceptable labels. | ||