Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0cb7f3

Browse files
committed
chore: improve comments and add logging
1 parent e3139cd commit f0cb7f3

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

scripts/metricsdocgen/generated_metrics

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ coderd_insights_templates_active_users{template_name=""} 0
2828
# HELP coderd_license_active_users The number of active users.
2929
# TYPE coderd_license_active_users gauge
3030
coderd_license_active_users 0
31+
# HELP coderd_license_errors The number of active license errors.
32+
# TYPE coderd_license_errors gauge
33+
coderd_license_errors 0
3134
# HELP coderd_license_limit_users The user seats limit based on the active Coder license.
3235
# TYPE coderd_license_limit_users gauge
3336
coderd_license_limit_users 0
3437
# HELP coderd_license_user_limit_enabled Returns 1 if the current license enforces the user limit.
3538
# TYPE coderd_license_user_limit_enabled gauge
3639
coderd_license_user_limit_enabled 0
40+
# HELP coderd_license_warnings The number of active license warnings.
41+
# TYPE coderd_license_warnings gauge
42+
coderd_license_warnings 0
3743
# HELP coderd_prebuilt_workspaces_claimed_total Total number of prebuilt workspaces which were claimed by users. Claiming refers to creating a workspace with a preset selected for which eligible prebuilt workspaces are available and one is reassigned to a user.
3844
# TYPE coderd_prebuilt_workspaces_claimed_total counter
3945
coderd_prebuilt_workspaces_claimed_total{template_name="",preset_name="",organization_name=""} 0

scripts/metricsdocgen/scanner/scanner.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ func resolveBinaryExpr(expr *ast.BinaryExpr, decls declarations) string {
196196
}
197197

198198
// extractStringSlice extracts a []string from a composite literal.
199+
// Example:
200+
// - []string{"a", "b", myConst}: ["a", "b", <resolved value of myConst>]
199201
func extractStringSlice(lit *ast.CompositeLit, decls declarations) []string {
200202
var labels []string
201203
for _, elt := range lit.Elts {
@@ -242,8 +244,8 @@ func collectDecls(file *ast.File) declarations {
242244
}
243245
case *ast.CompositeLit:
244246
// Slice literal: var labels = []string{"a", "b"}
245-
if labels := extractStringSlice(v, decls); labels != nil {
246-
decls.stringSlices[name.Name] = labels
247+
if resolved := extractStringSlice(v, decls); resolved != nil {
248+
decls.stringSlices[name.Name] = resolved
247249
}
248250
}
249251
}
@@ -253,8 +255,12 @@ func collectDecls(file *ast.File) declarations {
253255
return decls
254256
}
255257

256-
// extractLabels extracts label names from an expression.
257-
// Handles []string{...} literals and variable references.
258+
// extractLabels extracts label names from an expression passed as an argument
259+
// to a metric constructor. Handles both inline []string literals and
260+
// variable references from decls.
261+
// Examples:
262+
// - []string{"label1", "label2"}: ["label1", "label2"] (inline literal)
263+
// - myLabels: resolved value of myLabels variable (variable reference)
258264
func extractLabels(expr ast.Expr, decls declarations) []string {
259265
switch e := expr.(type) {
260266
case *ast.CompositeLit:
@@ -281,6 +287,9 @@ func extractNewDescMetric(call *ast.CallExpr, decls declarations) (Metric, bool)
281287
return Metric{}, false
282288
}
283289

290+
// Match calls that are exactly "prometheus.NewDesc()". This checks the local
291+
// package identifier, not the resolved import path. If the prometheus package
292+
// is imported with an alias, this will not match.
284293
ident, ok := sel.X.(*ast.Ident)
285294
if !ok || ident.Name != "prometheus" || sel.Sel.Name != "NewDesc" {
286295
return Metric{}, false
@@ -294,6 +303,7 @@ func extractNewDescMetric(call *ast.CallExpr, decls declarations) (Metric, bool)
294303
// Extract name (first argument).
295304
name := resolveStringExpr(call.Args[0], decls)
296305
if name == "" {
306+
log.Printf("extractNewDescMetric: skipping prometheus.NewDesc() call: could not resolve metric name")
297307
return Metric{}, false
298308
}
299309

0 commit comments

Comments
 (0)