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)
| 373 | // - []string{"label1", "label2"}: ["label1", "label2"] (inline literal) |
| 374 | // - myLabels: resolved value of myLabels variable (variable reference) |
| 375 | func 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) |
no test coverage detected