Skip to content

Commit ffdea0d

Browse files
feat: add line count to BrewScanResult and update scanning methods for metrics
1 parent 59ce45e commit ffdea0d

6 files changed

Lines changed: 55 additions & 19 deletions

File tree

internal/detector/brewscan.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (s *BrewScanner) ScanFormulae(ctx context.Context) (model.BrewScanResult, b
5252
Error: errMsg,
5353
ExitCode: exitCode,
5454
ScanDurationMs: duration,
55+
LineCount: lineCount,
5556
}, true
5657
}
5758

@@ -86,5 +87,6 @@ func (s *BrewScanner) ScanCasks(ctx context.Context) (model.BrewScanResult, bool
8687
Error: errMsg,
8788
ExitCode: exitCode,
8889
ScanDurationMs: duration,
90+
LineCount: lineCount,
8991
}, true
9092
}

internal/detector/xcode_extensions_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66

77
func TestParsePluginkitLine(t *testing.T) {
88
tests := []struct {
9-
name string
10-
line string
11-
wantID string
12-
wantVer string
13-
wantPub string
14-
wantName string
15-
wantNil bool
9+
name string
10+
line string
11+
wantID string
12+
wantVer string
13+
wantPub string
14+
wantName string
15+
wantNil bool
1616
}{
1717
{
1818
name: "enabled extension",

internal/executor/mock.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,14 @@ type mockDirEntry struct {
307307
dir bool
308308
}
309309

310-
func (e *mockDirEntry) Name() string { return e.name }
311-
func (e *mockDirEntry) IsDir() bool { return e.dir }
312-
func (e *mockDirEntry) Type() os.FileMode { if e.dir { return os.ModeDir }; return 0 }
313-
func (e *mockDirEntry) Info() (os.FileInfo, error) { return &mockFileInfo{name: e.name, dir: e.dir}, nil }
310+
func (e *mockDirEntry) Name() string { return e.name }
311+
func (e *mockDirEntry) IsDir() bool { return e.dir }
312+
func (e *mockDirEntry) Type() os.FileMode {
313+
if e.dir {
314+
return os.ModeDir
315+
}
316+
return 0
317+
}
318+
func (e *mockDirEntry) Info() (os.FileInfo, error) {
319+
return &mockFileInfo{name: e.name, dir: e.dir}, nil
320+
}

internal/executor/user_aware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func (e *UserAwareExecutor) LookPath(name string) (string, error) {
6767

6868
// --- Pass-through methods ---
6969

70-
func (e *UserAwareExecutor) FileExists(path string) bool { return e.inner.FileExists(path) }
71-
func (e *UserAwareExecutor) DirExists(path string) bool { return e.inner.DirExists(path) }
70+
func (e *UserAwareExecutor) FileExists(path string) bool { return e.inner.FileExists(path) }
71+
func (e *UserAwareExecutor) DirExists(path string) bool { return e.inner.DirExists(path) }
7272
func (e *UserAwareExecutor) ReadFile(path string) ([]byte, error) { return e.inner.ReadFile(path) }
7373
func (e *UserAwareExecutor) ReadDir(path string) ([]os.DirEntry, error) {
7474
return e.inner.ReadDir(path)

internal/model/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ type BrewScanResult struct {
141141
Error string `json:"error"`
142142
ExitCode int `json:"exit_code"`
143143
ScanDurationMs int64 `json:"scan_duration_ms"`
144+
LineCount int `json:"line_count"`
144145
}
145146

146147
// PythonScanResult holds raw Python scan output for enterprise telemetry.

internal/telemetry/telemetry.go

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,14 @@ func Run(exec executor.Executor, log *progress.Logger, cfg *cli.Config) error {
374374
},
375375

376376
PerformanceMetrics: &PerformanceMetrics{
377-
ExtensionsCount: len(extensions),
378-
NodePackagesScanMs: nodeScanMs,
379-
NodeGlobalPkgsCount: len(globalPkgs),
380-
NodeProjectsCount: len(nodeProjects),
377+
ExtensionsCount: len(extensions),
378+
NodePackagesScanMs: nodeScanMs,
379+
NodeGlobalPkgsCount: len(globalPkgs),
380+
NodeProjectsCount: len(nodeProjects),
381+
BrewFormulaeCount: brewFormulaeCount(brewScans),
382+
BrewCasksCount: brewCasksCount(brewScans),
383+
PythonGlobalPkgsCount: len(pythonGlobalPkgs),
384+
PythonProjectsCount: len(pythonProjects),
381385
},
382386
}
383387

@@ -392,6 +396,24 @@ func Run(exec executor.Executor, log *progress.Logger, cfg *cli.Config) error {
392396
return nil
393397
}
394398

399+
func brewFormulaeCount(scans []model.BrewScanResult) int {
400+
for _, s := range scans {
401+
if s.ScanType == "formulae" {
402+
return s.LineCount
403+
}
404+
}
405+
return 0
406+
}
407+
408+
func brewCasksCount(scans []model.BrewScanResult) int {
409+
for _, s := range scans {
410+
if s.ScanType == "casks" {
411+
return s.LineCount
412+
}
413+
}
414+
return 0
415+
}
416+
395417
func uploadToS3(ctx context.Context, log *progress.Logger, payload *Payload) error {
396418
payloadJSON, err := json.Marshal(payload)
397419
if err != nil {
@@ -473,11 +495,15 @@ func uploadToS3(ctx context.Context, log *progress.Logger, payload *Payload) err
473495
// Log retry and backoff
474496
backoff := time.Duration(attempt) * 2 * time.Second
475497
if err != nil {
476-
log.Progress("S3 upload attempt %d/%d failed (%s), retrying in %s...", attempt, maxRetries, elapsed, backoff)
498+
log.Progress("S3 upload attempt %d/%d failed after %s: %v; retrying in %s...", attempt, maxRetries, elapsed, err, backoff)
477499
} else {
478500
log.Progress("S3 upload attempt %d/%d got status %d, retrying in %s...", attempt, maxRetries, putResp.StatusCode, backoff)
479501
}
480-
time.Sleep(backoff)
502+
select {
503+
case <-time.After(backoff):
504+
case <-ctx.Done():
505+
return ctx.Err()
506+
}
481507
}
482508
defer func() { _ = putResp.Body.Close() }()
483509
_, _ = io.Copy(io.Discard, putResp.Body)

0 commit comments

Comments
 (0)