MCPcopy Index your code
hub / github.com/coder/coder / extractMetricFromCall

Function extractMetricFromCall

scripts/metricsdocgen/scanner/scanner.go:685–702  ·  view source on GitHub ↗

extractMetricFromCall attempts to extract a Metric from a function call expression. It returns the metric and true if successful, or an empty metric and false if the call is not a metric registration. Supported patterns: - prometheus.NewDesc() calls - prometheus.New*() and prometheus.New*Vec() with

(call *ast.CallExpr, decls declarations)

Source from the content-addressed store, hash-verified

683// - prometheus.New*() and prometheus.New*Vec() with *Opts{}
684// - promauto.With(reg).New*() and factory.New*() patterns
685func extractMetricFromCall(call *ast.CallExpr, decls declarations) (Metric, bool) {
686 // Check for prometheus.NewDesc() pattern.
687 if metric, ok := extractNewDescMetric(call, decls); ok {
688 return metric, true
689 }
690
691 // Check for prometheus.New*() and prometheus.New*Vec() patterns.
692 if metric, ok := extractOptsMetric(call, decls); ok {
693 return metric, true
694 }
695
696 // Check for promauto.With(reg).New*() pattern.
697 if metric, ok := extractPromautoMetric(call, decls); ok {
698 return metric, true
699 }
700
701 return Metric{}, false
702}
703
704// String returns the metric in Prometheus text exposition format.
705// Label values are empty strings and metric values are 0 since only

Callers 1

scanFileFunction · 0.85

Calls 3

extractNewDescMetricFunction · 0.85
extractOptsMetricFunction · 0.85
extractPromautoMetricFunction · 0.85

Tested by

no test coverage detected