fix(lint): resolve errcheck and gosec warnings in vhs backfill tool
CI / test (pull_request) Successful in 2m52s
CI / lint (pull_request) Failing after 1m11s
CI / vulncheck (pull_request) Successful in 56s

This commit is contained in:
2026-05-28 18:50:56 -04:00
parent 10f249a2ae
commit ff85abb2c9
+9 -9
View File
@@ -3,7 +3,7 @@ package main
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"math/rand" "math/rand/v2"
"os" "os"
"time" "time"
@@ -28,7 +28,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
rng := rand.New(rand.NewSource(42)) rng := rand.New(rand.NewPCG(42, 0))
now := time.Now().UTC() now := time.Now().UTC()
if err := backfillHistory(db, rng, now, ids); err != nil { if err := backfillHistory(db, rng, now, ids); err != nil {
@@ -53,7 +53,7 @@ func main() {
} }
var count int var count int
db.QueryRow("SELECT COUNT(*) FROM check_history").Scan(&count) _ = db.QueryRow("SELECT COUNT(*) FROM check_history").Scan(&count)
fmt.Printf("Backfill complete: %d check records\n", count) fmt.Printf("Backfill complete: %d check records\n", count)
var token string var token string
@@ -107,7 +107,7 @@ func backfillHistory(db *sql.DB, rng *rand.Rand, now time.Time, ids map[string]i
if err != nil { if err != nil {
return err return err
} }
defer tx.Rollback() defer func() { _ = tx.Rollback() }()
stmt, err := tx.Prepare("INSERT INTO check_history (site_id, latency_ns, is_up, checked_at) VALUES (?, ?, ?, ?)") stmt, err := tx.Prepare("INSERT INTO check_history (site_id, latency_ns, is_up, checked_at) VALUES (?, ?, ?, ?)")
if err != nil { if err != nil {
@@ -132,9 +132,9 @@ func backfillHistory(db *sql.DB, rng *rand.Rand, now time.Time, ids map[string]i
latencyNs = 0 latencyNs = 0
isUp = false isUp = false
} else { } else {
ms := p.minMs + rng.Intn(p.maxMs-p.minMs) ms := p.minMs + rng.IntN(p.maxMs-p.minMs)
if p.name == "Immich" && i%17 == 0 { if p.name == "Immich" && i%17 == 0 {
ms = 250 + rng.Intn(100) ms = 250 + rng.IntN(100)
} }
latencyNs = int64(ms) * 1_000_000 latencyNs = int64(ms) * 1_000_000
} }
@@ -169,7 +169,7 @@ func backfillStateChanges(db *sql.DB, now time.Time, ids map[string]int) error {
if err != nil { if err != nil {
return err return err
} }
defer tx.Rollback() defer func() { _ = tx.Rollback() }()
stmt, err := tx.Prepare("INSERT INTO state_changes (site_id, from_status, to_status, error_reason, changed_at) VALUES (?, ?, ?, ?, ?)") stmt, err := tx.Prepare("INSERT INTO state_changes (site_id, from_status, to_status, error_reason, changed_at) VALUES (?, ?, ?, ?, ?)")
if err != nil { if err != nil {
@@ -216,7 +216,7 @@ func backfillLogs(db *sql.DB, now time.Time) error {
if err != nil { if err != nil {
return err return err
} }
defer tx.Rollback() defer func() { _ = tx.Rollback() }()
stmt, err := tx.Prepare("INSERT INTO logs (message, created_at) VALUES (?, ?)") stmt, err := tx.Prepare("INSERT INTO logs (message, created_at) VALUES (?, ?)")
if err != nil { if err != nil {
@@ -245,7 +245,7 @@ func backfillMaintenance(db *sql.DB, now time.Time, ids map[string]int) error {
if err != nil { if err != nil {
return err return err
} }
defer tx.Rollback() defer func() { _ = tx.Rollback() }()
stmt, err := tx.Prepare("INSERT INTO maintenance_windows (monitor_id, title, description, type, start_time, end_time, created_by) VALUES (?, ?, ?, ?, ?, ?, ?)") stmt, err := tx.Prepare("INSERT INTO maintenance_windows (monitor_id, title, description, type, start_time, end_time, created_by) VALUES (?, ?, ?, ?, ?, ?, ?)")
if err != nil { if err != nil {