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

Function scanDirectory

scripts/metricsdocgen/scanner/scanner.go:149–188  ·  view source on GitHub ↗

scanDirectory recursively walks a directory and extracts metrics from all Go files.

(root string)

Source from the content-addressed store, hash-verified

147
148// scanDirectory recursively walks a directory and extracts metrics from all Go files.
149func scanDirectory(root string) ([]Metric, error) {
150 var metrics []Metric
151
152 err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
153 if err != nil {
154 return err
155 }
156
157 // Skip non-Go files.
158 if d.IsDir() || !strings.HasSuffix(path, ".go") {
159 return nil
160 }
161
162 // Skip test files.
163 if strings.HasSuffix(path, "_test.go") {
164 return nil
165 }
166
167 // Skip files listed in skipPaths.
168 for _, sp := range skipPaths {
169 if path == sp {
170 return nil
171 }
172 }
173
174 fileMetrics, err := scanFile(path)
175 if err != nil {
176 return xerrors.Errorf("scanning %s: %w", path, err)
177 }
178
179 if len(fileMetrics) > 0 {
180 logf("scanning %s: found %d metrics", path, len(fileMetrics))
181 }
182 metrics = append(metrics, fileMetrics...)
183
184 return nil
185 })
186
187 return metrics, err
188}
189
190// scanFile parses a single Go file and extracts all Prometheus metric definitions.
191func scanFile(path string) ([]Metric, error) {

Callers 1

scanAllDirsFunction · 0.85

Calls 3

scanFileFunction · 0.85
logfFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected