MCPcopy Create free account
hub / github.com/coder/coder / extractLabels

Function extractLabels

scripts/metricsdocgen/scanner/scanner.go:375–388  ·  view source on GitHub ↗

extractLabels extracts label names from an expression passed as an argument to a metric constructor. Handles both inline []string literals and variable references from decls. Examples: - []string{"label1", "label2"}: ["label1", "label2"] (inline literal) - myLabels: resolved value of myLabels variab

(expr ast.Expr, decls declarations)

Source from the content-addressed store, hash-verified

373// - []string{"label1", "label2"}: ["label1", "label2"] (inline literal)
374// - myLabels: resolved value of myLabels variable (variable reference)
375func extractLabels(expr ast.Expr, decls declarations) []string {
376 switch e := expr.(type) {
377 case *ast.CompositeLit:
378 // []string{"label1", "label2"}
379 return extractStringSlice(e, decls)
380 case *ast.Ident:
381 // Variable reference like 'labels'.
382 if labels, ok := decls.stringSlices[e.Name]; ok {
383 return labels
384 }
385 return nil
386 }
387 return nil
388}
389
390// extractNewDescMetric extracts a metric from a prometheus.NewDesc() call.
391// Pattern: prometheus.NewDesc(name, help, variableLabels, constLabels)

Callers 3

extractNewDescMetricFunction · 0.85
extractOptsMetricFunction · 0.85
extractPromautoMetricFunction · 0.85

Calls 1

extractStringSliceFunction · 0.85

Tested by

no test coverage detected