Update golangci-lint to v2.12.2 with canonical config (#62)
All checks were successful
check / check (push) Successful in 5s
All checks were successful
check / check (push) Successful in 5s
Updates golangci-lint to v2.12.2 everywhere it is pinned and installs the canonical `.golangci.yml`, then remediates every finding the new linter/config surfaces so `make check` is green. ## Version bump - `Dockerfile` lint stage: `golangci/golangci-lint:v2.11.3-alpine` -> `v2.12.2-alpine` (digest-pinned, date comment updated) - `Makefile` `deps` target: `go install` moved from the old v1 module path at `@latest` to the pinned `github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2` - `.golangci.yml` replaced with the canonical config (v2 schema; settings under `linters.settings` so the thresholds actually apply; `default: all` with the standard six disables) - `script/bootstrap` installs golangci-lint via the system package manager and carries no version pin, so it is unchanged - CI (`.gitea/workflows/check.yml`) only runs `script/cibuild`, so it needed no change ## Lint remediation The canonical config surfaced ~3,300 findings across 56k lines. All are fixed, behavior-preserving; incorporates and supersedes the per-package mechanical passes already merged to `main` (refs #61). Highlights: - `err113`: dynamic errors replaced with package sentinels + `%w` wrapping; comparisons via `errors.Is` - `goprintffuncname`: printf-style helpers renamed with an `f` suffix (`ui.Writer` message methods, `cli.ReportErrorf`, `database.Fatalf`) and all call sites updated - `revive` stutter renames: `blob.Handler`, `blob.WithReader`, `blob.ChunkPosition`, `storage.URL`, `storage.Info`; missing doc comments added - `contextcheck`/`noctx`: `context.Context` threaded through `blob.Packer` and the scanner call sites; context-aware `exec`/`sql` variants - `funlen`/`cyclop`/`gocognit`/`dupl`: oversized and duplicated functions split into focused helpers (production and test code) - tests: `t.Parallel()` added where safe (global logger init kept in the serial phase for `-race`), `t.TempDir()`/`t.Helper()` adopted, several suites converted to external test packages - `gosec`: bounded integer conversions, `ReadHeaderTimeout` on the test HTTP server; remaining warnings suppressed per-site with justifications - remaining `nolint` directives are rare, targeted, and each carries a reason (e.g. `nilnil` not-found contract in the repository layer, fx module globals, on-disk snake_case struct tags) - removed the deprecated `log.LogOptions` alias (callers migrated to `log.Options`) `make check` (tests with `-race`, lint, fmt-check) passes. Co-authored-by: sneak <sneak@sneak.berlin> Reviewed-on: #62 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
This commit was merged in pull request #62.
This commit is contained in:
@@ -19,14 +19,41 @@ const (
|
||||
// These updates show current progress, ETA, and the file being processed.
|
||||
SummaryInterval = 10 * time.Second
|
||||
|
||||
// DetailInterval defines how often multi-line detailed status reports are printed.
|
||||
// These reports include comprehensive statistics about files, chunks, blobs, and uploads.
|
||||
// DetailInterval defines how often multi-line detailed status reports are
|
||||
// printed. These reports include comprehensive statistics about files,
|
||||
// chunks, blobs, and uploads.
|
||||
DetailInterval = 60 * time.Second
|
||||
|
||||
// UploadProgressInterval defines how often upload progress messages are logged.
|
||||
UploadProgressInterval = 15 * time.Second
|
||||
)
|
||||
|
||||
const (
|
||||
// bitsPerByte converts byte counts to bit counts for speed display.
|
||||
bitsPerByte = 8
|
||||
|
||||
// percentScale converts a ratio to a percentage.
|
||||
percentScale = 100
|
||||
|
||||
// currentFileMaxLen is the display width used for current-file paths.
|
||||
currentFileMaxLen = 40
|
||||
|
||||
// secondsPerMinute and minutesPerHour are used for duration formatting.
|
||||
secondsPerMinute = 60
|
||||
minutesPerHour = 60
|
||||
|
||||
// Bit-rate thresholds for human-readable upload speed formatting.
|
||||
bitsPerGbit = 1e9
|
||||
bitsPerMbit = 1e6
|
||||
bitsPerKbit = 1e3
|
||||
|
||||
// ellipsis prefixes truncated paths and suffixes shortened hashes.
|
||||
ellipsis = "..."
|
||||
|
||||
// hashPrefixLen is how many hex characters of a blob hash to show in logs.
|
||||
hashPrefixLen = 8
|
||||
)
|
||||
|
||||
// ProgressStats holds atomic counters for progress tracking
|
||||
type ProgressStats struct {
|
||||
FilesScanned atomic.Int64 // Total files seen during scan (includes skipped)
|
||||
@@ -64,7 +91,7 @@ type UploadInfo struct {
|
||||
// ProgressReporter handles periodic progress reporting
|
||||
type ProgressReporter struct {
|
||||
stats *ProgressStats
|
||||
ctx context.Context
|
||||
ctx context.Context //nolint:containedctx // bound at construction
|
||||
cancel context.CancelFunc
|
||||
wg sync.WaitGroup
|
||||
detailTicker *time.Ticker
|
||||
@@ -127,6 +154,161 @@ func (pr *ProgressReporter) SetTotalSize(size int64) {
|
||||
pr.stats.ProcessStartTime.Store(time.Now().UTC())
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
|
||||
func formatDuration(d time.Duration) string {
|
||||
if d < 0 {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
if d < time.Minute {
|
||||
return fmt.Sprintf("%ds", int(d.Seconds()))
|
||||
}
|
||||
|
||||
if d < time.Hour {
|
||||
return fmt.Sprintf("%dm%ds", int(d.Minutes()), int(d.Seconds())%secondsPerMinute)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%dh%dm", int(d.Hours()), int(d.Minutes())%minutesPerHour)
|
||||
}
|
||||
|
||||
func formatPercent(numerator, denominator int64) string {
|
||||
if denominator == 0 {
|
||||
return "0.0%"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.1f%%", float64(numerator)/float64(denominator)*percentScale)
|
||||
}
|
||||
|
||||
func formatRatio(compressed, uncompressed int64) string {
|
||||
if uncompressed == 0 {
|
||||
return "1.00"
|
||||
}
|
||||
|
||||
ratio := float64(compressed) / float64(uncompressed)
|
||||
|
||||
return fmt.Sprintf("%.2f", ratio)
|
||||
}
|
||||
|
||||
func truncatePath(path string, maxLen int) string {
|
||||
if len(path) <= maxLen {
|
||||
return path
|
||||
}
|
||||
// Keep the last maxLen-len(ellipsis) characters and prepend the ellipsis.
|
||||
return ellipsis + path[len(path)-(maxLen-len(ellipsis)):]
|
||||
}
|
||||
|
||||
// safeUint64 converts a non-negative int64 counter to uint64 for display,
|
||||
// clamping negative values to zero.
|
||||
func safeUint64(n int64) uint64 {
|
||||
if n < 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
return uint64(n)
|
||||
}
|
||||
|
||||
// ReportUploadStart marks the beginning of a blob upload
|
||||
func (pr *ProgressReporter) ReportUploadStart(blobHash string, size int64) {
|
||||
info := &UploadInfo{
|
||||
BlobHash: blobHash,
|
||||
Size: size,
|
||||
StartTime: time.Now().UTC(),
|
||||
}
|
||||
pr.stats.CurrentUpload.Store(info)
|
||||
|
||||
// Log the start of upload
|
||||
log.Info("Starting blob upload",
|
||||
"hash", blobHash[:hashPrefixLen]+ellipsis,
|
||||
"size", humanize.Bytes(safeUint64(size)))
|
||||
}
|
||||
|
||||
// ReportUploadComplete marks the completion of a blob upload
|
||||
func (pr *ProgressReporter) ReportUploadComplete(
|
||||
blobHash string, size int64, duration time.Duration,
|
||||
) {
|
||||
// Clear current upload
|
||||
pr.stats.CurrentUpload.Store((*UploadInfo)(nil))
|
||||
|
||||
// Add to total upload duration
|
||||
pr.stats.UploadDurationMs.Add(duration.Milliseconds())
|
||||
|
||||
// Calculate speed
|
||||
if duration < time.Millisecond {
|
||||
duration = time.Millisecond
|
||||
}
|
||||
|
||||
bytesPerSec := float64(size) / duration.Seconds()
|
||||
bitsPerSec := bytesPerSec * bitsPerByte
|
||||
|
||||
// Format speed
|
||||
var speedStr string
|
||||
|
||||
switch {
|
||||
case bitsPerSec >= bitsPerGbit:
|
||||
speedStr = fmt.Sprintf("%.1fGbit/sec", bitsPerSec/bitsPerGbit)
|
||||
case bitsPerSec >= bitsPerMbit:
|
||||
speedStr = fmt.Sprintf("%.0fMbit/sec", bitsPerSec/bitsPerMbit)
|
||||
case bitsPerSec >= bitsPerKbit:
|
||||
speedStr = fmt.Sprintf("%.0fKbit/sec", bitsPerSec/bitsPerKbit)
|
||||
default:
|
||||
speedStr = fmt.Sprintf("%.0fbit/sec", bitsPerSec)
|
||||
}
|
||||
|
||||
log.Info("Blob upload completed",
|
||||
"hash", blobHash[:hashPrefixLen]+ellipsis,
|
||||
"size", humanize.Bytes(safeUint64(size)),
|
||||
"duration", formatDuration(duration),
|
||||
"speed", speedStr)
|
||||
}
|
||||
|
||||
// UpdateChunkingActivity updates the last chunking time
|
||||
func (pr *ProgressReporter) UpdateChunkingActivity() {
|
||||
pr.stats.mu.Lock()
|
||||
pr.stats.lastChunkingTime = time.Now().UTC()
|
||||
pr.stats.mu.Unlock()
|
||||
}
|
||||
|
||||
// ReportUploadProgress reports current upload progress with instantaneous speed
|
||||
func (pr *ProgressReporter) ReportUploadProgress(
|
||||
blobHash string, bytesUploaded, totalSize int64, instantSpeed float64,
|
||||
) {
|
||||
// Update the current upload info with progress
|
||||
uploadInfo, ok := pr.stats.CurrentUpload.Load().(*UploadInfo)
|
||||
if ok && uploadInfo != nil {
|
||||
now := time.Now()
|
||||
|
||||
// Only log at the configured interval
|
||||
if now.Sub(uploadInfo.LastLogTime) >= UploadProgressInterval {
|
||||
// Format speed in bits/second using humanize
|
||||
bitsPerSec := instantSpeed * bitsPerByte
|
||||
speedStr := humanize.SI(bitsPerSec, "bit/sec")
|
||||
|
||||
percent := float64(bytesUploaded) / float64(totalSize) * percentScale
|
||||
|
||||
// Calculate ETA based on current speed
|
||||
etaStr := "unknown"
|
||||
|
||||
if instantSpeed > 0 && bytesUploaded < totalSize {
|
||||
remainingBytes := totalSize - bytesUploaded
|
||||
remainingSeconds := float64(remainingBytes) / instantSpeed
|
||||
eta := time.Duration(remainingSeconds * float64(time.Second))
|
||||
etaStr = formatDuration(eta)
|
||||
}
|
||||
|
||||
log.Info("Blob upload progress",
|
||||
"hash", blobHash[:hashPrefixLen]+ellipsis,
|
||||
"progress", fmt.Sprintf("%.1f%%", percent),
|
||||
"uploaded", humanize.Bytes(safeUint64(bytesUploaded)),
|
||||
"total", humanize.Bytes(safeUint64(totalSize)),
|
||||
"speed", speedStr,
|
||||
"eta", etaStr)
|
||||
|
||||
uploadInfo.LastLogTime = now
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run is the main progress reporting loop
|
||||
func (pr *ProgressReporter) run() {
|
||||
defer pr.wg.Done()
|
||||
@@ -150,7 +332,8 @@ func (pr *ProgressReporter) run() {
|
||||
// printSummaryStatus prints a one-line status update
|
||||
func (pr *ProgressReporter) printSummaryStatus() {
|
||||
// Check if we're currently uploading
|
||||
if uploadInfo, ok := pr.stats.CurrentUpload.Load().(*UploadInfo); ok && uploadInfo != nil {
|
||||
uploadInfo, ok := pr.stats.CurrentUpload.Load().(*UploadInfo)
|
||||
if ok && uploadInfo != nil {
|
||||
// Show upload progress instead
|
||||
pr.printUploadProgress(uploadInfo)
|
||||
|
||||
@@ -172,7 +355,7 @@ func (pr *ProgressReporter) printSummaryStatus() {
|
||||
bytesSkipped := pr.stats.BytesSkipped.Load()
|
||||
bytesProcessed := pr.stats.BytesProcessed.Load()
|
||||
totalSize := pr.stats.TotalSize.Load()
|
||||
currentFile := pr.stats.CurrentFile.Load().(string)
|
||||
currentFile, _ := pr.stats.CurrentFile.Load().(string)
|
||||
|
||||
// Calculate ETA if we have total size and are processing
|
||||
etaStr := ""
|
||||
@@ -201,15 +384,15 @@ func (pr *ProgressReporter) printSummaryStatus() {
|
||||
status := fmt.Sprintf("Snapshot progress: %d/%d files, %s/%s (%.1f%%), %s/s%s",
|
||||
filesProcessed,
|
||||
totalFiles,
|
||||
humanize.Bytes(uint64(bytesProcessed)),
|
||||
humanize.Bytes(uint64(totalSize)),
|
||||
float64(bytesProcessed)/float64(totalSize)*100,
|
||||
humanize.Bytes(safeUint64(bytesProcessed)),
|
||||
humanize.Bytes(safeUint64(totalSize)),
|
||||
float64(bytesProcessed)/float64(totalSize)*percentScale,
|
||||
humanize.Bytes(uint64(rate)),
|
||||
etaStr,
|
||||
)
|
||||
|
||||
if currentFile != "" {
|
||||
status += " | Current: " + truncatePath(currentFile, 40)
|
||||
status += " | Current: " + truncatePath(currentFile, currentFileMaxLen)
|
||||
}
|
||||
|
||||
log.Info(status)
|
||||
@@ -232,7 +415,7 @@ func (pr *ProgressReporter) printDetailedStatus() {
|
||||
blobsCreated := pr.stats.BlobsCreated.Load()
|
||||
blobsUploaded := pr.stats.BlobsUploaded.Load()
|
||||
bytesUploaded := pr.stats.BytesUploaded.Load()
|
||||
currentFile := pr.stats.CurrentFile.Load().(string)
|
||||
currentFile, _ := pr.stats.CurrentFile.Load().(string)
|
||||
|
||||
totalBytes := bytesScanned + bytesSkipped
|
||||
rate := float64(totalBytes) / elapsed.Seconds()
|
||||
@@ -251,11 +434,11 @@ func (pr *ProgressReporter) printDetailedStatus() {
|
||||
remainingBytes := totalSize - bytesProcessed
|
||||
remainingSeconds := float64(remainingBytes) / processRate
|
||||
eta := time.Duration(remainingSeconds * float64(time.Second))
|
||||
percentComplete := float64(bytesProcessed) / float64(totalSize) * 100
|
||||
percentComplete := float64(bytesProcessed) / float64(totalSize) * percentScale
|
||||
log.Info("Overall progress",
|
||||
"percent", fmt.Sprintf("%.1f%%", percentComplete),
|
||||
"processed", humanize.Bytes(uint64(bytesProcessed)),
|
||||
"total", humanize.Bytes(uint64(totalSize)),
|
||||
"processed", humanize.Bytes(safeUint64(bytesProcessed)),
|
||||
"total", humanize.Bytes(safeUint64(totalSize)),
|
||||
"rate", humanize.Bytes(uint64(processRate))+"/s",
|
||||
"eta", formatDuration(eta))
|
||||
}
|
||||
@@ -268,9 +451,9 @@ func (pr *ProgressReporter) printDetailedStatus() {
|
||||
"total", filesScanned,
|
||||
"skip_rate", formatPercent(filesSkipped, filesScanned))
|
||||
log.Info("Data scanned",
|
||||
"new", humanize.Bytes(uint64(bytesScanned)),
|
||||
"skipped", humanize.Bytes(uint64(bytesSkipped)),
|
||||
"total", humanize.Bytes(uint64(totalBytes)),
|
||||
"new", humanize.Bytes(safeUint64(bytesScanned)),
|
||||
"skipped", humanize.Bytes(safeUint64(bytesSkipped)),
|
||||
"total", humanize.Bytes(safeUint64(totalBytes)),
|
||||
"scan_rate", humanize.Bytes(uint64(rate))+"/s")
|
||||
log.Info("Chunks created", "count", chunksCreated)
|
||||
log.Info("Blobs status",
|
||||
@@ -278,7 +461,7 @@ func (pr *ProgressReporter) printDetailedStatus() {
|
||||
"uploaded", blobsUploaded,
|
||||
"pending", blobsCreated-blobsUploaded)
|
||||
log.Info("Total uploaded to remote",
|
||||
"uploaded", humanize.Bytes(uint64(bytesUploaded)),
|
||||
"uploaded", humanize.Bytes(safeUint64(bytesUploaded)),
|
||||
"compression_ratio", formatRatio(bytesUploaded, bytesScanned))
|
||||
|
||||
if currentFile != "" {
|
||||
@@ -288,146 +471,8 @@ func (pr *ProgressReporter) printDetailedStatus() {
|
||||
log.Notice("=============================")
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
|
||||
func formatDuration(d time.Duration) string {
|
||||
if d < 0 {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
if d < time.Minute {
|
||||
return fmt.Sprintf("%ds", int(d.Seconds()))
|
||||
}
|
||||
|
||||
if d < time.Hour {
|
||||
return fmt.Sprintf("%dm%ds", int(d.Minutes()), int(d.Seconds())%60)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%dh%dm", int(d.Hours()), int(d.Minutes())%60)
|
||||
}
|
||||
|
||||
func formatPercent(numerator, denominator int64) string {
|
||||
if denominator == 0 {
|
||||
return "0.0%"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.1f%%", float64(numerator)/float64(denominator)*100)
|
||||
}
|
||||
|
||||
func formatRatio(compressed, uncompressed int64) string {
|
||||
if uncompressed == 0 {
|
||||
return "1.00"
|
||||
}
|
||||
|
||||
ratio := float64(compressed) / float64(uncompressed)
|
||||
|
||||
return fmt.Sprintf("%.2f", ratio)
|
||||
}
|
||||
|
||||
func truncatePath(path string, maxLen int) string {
|
||||
if len(path) <= maxLen {
|
||||
return path
|
||||
}
|
||||
// Keep the last maxLen-3 characters and prepend "..."
|
||||
return "..." + path[len(path)-(maxLen-3):]
|
||||
}
|
||||
|
||||
// printUploadProgress prints upload progress
|
||||
func (pr *ProgressReporter) printUploadProgress(info *UploadInfo) {
|
||||
func (pr *ProgressReporter) printUploadProgress(_ *UploadInfo) {
|
||||
// This function is called repeatedly during upload, not just at start
|
||||
// Don't print anything here - the actual progress is shown by ReportUploadProgress
|
||||
}
|
||||
|
||||
// ReportUploadStart marks the beginning of a blob upload
|
||||
func (pr *ProgressReporter) ReportUploadStart(blobHash string, size int64) {
|
||||
info := &UploadInfo{
|
||||
BlobHash: blobHash,
|
||||
Size: size,
|
||||
StartTime: time.Now().UTC(),
|
||||
}
|
||||
pr.stats.CurrentUpload.Store(info)
|
||||
|
||||
// Log the start of upload
|
||||
log.Info("Starting blob upload",
|
||||
"hash", blobHash[:8]+"...",
|
||||
"size", humanize.Bytes(uint64(size)))
|
||||
}
|
||||
|
||||
// ReportUploadComplete marks the completion of a blob upload
|
||||
func (pr *ProgressReporter) ReportUploadComplete(blobHash string, size int64, duration time.Duration) {
|
||||
// Clear current upload
|
||||
pr.stats.CurrentUpload.Store((*UploadInfo)(nil))
|
||||
|
||||
// Add to total upload duration
|
||||
pr.stats.UploadDurationMs.Add(duration.Milliseconds())
|
||||
|
||||
// Calculate speed
|
||||
if duration < time.Millisecond {
|
||||
duration = time.Millisecond
|
||||
}
|
||||
|
||||
bytesPerSec := float64(size) / duration.Seconds()
|
||||
bitsPerSec := bytesPerSec * 8
|
||||
|
||||
// Format speed
|
||||
var speedStr string
|
||||
if bitsPerSec >= 1e9 {
|
||||
speedStr = fmt.Sprintf("%.1fGbit/sec", bitsPerSec/1e9)
|
||||
} else if bitsPerSec >= 1e6 {
|
||||
speedStr = fmt.Sprintf("%.0fMbit/sec", bitsPerSec/1e6)
|
||||
} else if bitsPerSec >= 1e3 {
|
||||
speedStr = fmt.Sprintf("%.0fKbit/sec", bitsPerSec/1e3)
|
||||
} else {
|
||||
speedStr = fmt.Sprintf("%.0fbit/sec", bitsPerSec)
|
||||
}
|
||||
|
||||
log.Info("Blob upload completed",
|
||||
"hash", blobHash[:8]+"...",
|
||||
"size", humanize.Bytes(uint64(size)),
|
||||
"duration", formatDuration(duration),
|
||||
"speed", speedStr)
|
||||
}
|
||||
|
||||
// UpdateChunkingActivity updates the last chunking time
|
||||
func (pr *ProgressReporter) UpdateChunkingActivity() {
|
||||
pr.stats.mu.Lock()
|
||||
pr.stats.lastChunkingTime = time.Now().UTC()
|
||||
pr.stats.mu.Unlock()
|
||||
}
|
||||
|
||||
// ReportUploadProgress reports current upload progress with instantaneous speed
|
||||
func (pr *ProgressReporter) ReportUploadProgress(blobHash string, bytesUploaded, totalSize int64, instantSpeed float64) {
|
||||
// Update the current upload info with progress
|
||||
if uploadInfo, ok := pr.stats.CurrentUpload.Load().(*UploadInfo); ok && uploadInfo != nil {
|
||||
now := time.Now()
|
||||
|
||||
// Only log at the configured interval
|
||||
if now.Sub(uploadInfo.LastLogTime) >= UploadProgressInterval {
|
||||
// Format speed in bits/second using humanize
|
||||
bitsPerSec := instantSpeed * 8
|
||||
speedStr := humanize.SI(bitsPerSec, "bit/sec")
|
||||
|
||||
percent := float64(bytesUploaded) / float64(totalSize) * 100
|
||||
|
||||
// Calculate ETA based on current speed
|
||||
etaStr := "unknown"
|
||||
|
||||
if instantSpeed > 0 && bytesUploaded < totalSize {
|
||||
remainingBytes := totalSize - bytesUploaded
|
||||
remainingSeconds := float64(remainingBytes) / instantSpeed
|
||||
eta := time.Duration(remainingSeconds * float64(time.Second))
|
||||
etaStr = formatDuration(eta)
|
||||
}
|
||||
|
||||
log.Info("Blob upload progress",
|
||||
"hash", blobHash[:8]+"...",
|
||||
"progress", fmt.Sprintf("%.1f%%", percent),
|
||||
"uploaded", humanize.Bytes(uint64(bytesUploaded)),
|
||||
"total", humanize.Bytes(uint64(totalSize)),
|
||||
"speed", speedStr,
|
||||
"eta", etaStr)
|
||||
|
||||
uploadInfo.LastLogTime = now
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user