avoid vcenter totals pages scanning whole database
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
56
main.go
56
main.go
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
"vctp/db"
|
||||
"vctp/internal/report"
|
||||
"vctp/internal/secrets"
|
||||
"vctp/internal/settings"
|
||||
"vctp/internal/tasks"
|
||||
@@ -42,6 +43,7 @@ func main() {
|
||||
settingsPath := flag.String("settings", "/etc/dtms/vctp.yml", "Path to settings YAML")
|
||||
runInventory := flag.Bool("run-inventory", false, "Run a single inventory snapshot across all configured vCenters and exit")
|
||||
dbCleanup := flag.Bool("db-cleanup", false, "Run a one-time cleanup to drop low-value hourly snapshot indexes and exit")
|
||||
backfillVcenterCache := flag.Bool("backfill-vcenter-cache", false, "Run a one-time backfill for vcenter latest+aggregate cache tables and exit")
|
||||
flag.Parse()
|
||||
|
||||
bootstrapLogger := log.New(log.LevelInfo, log.OutputText)
|
||||
@@ -104,6 +106,60 @@ func main() {
|
||||
logger.Info("completed hourly snapshot index cleanup", "indexes_dropped", dropped)
|
||||
return
|
||||
}
|
||||
if *backfillVcenterCache {
|
||||
logger.Info("starting one-time vcenter cache backfill")
|
||||
if err := report.EnsureSnapshotRegistry(ctx, database); err != nil {
|
||||
logger.Error("failed to ensure snapshot registry", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
hourlyRecords, err := report.ListSnapshots(ctx, database, "hourly")
|
||||
if err != nil {
|
||||
logger.Error("failed to list hourly snapshots from registry", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(hourlyRecords) == 0 {
|
||||
logger.Warn("snapshot registry has no hourly entries; attempting registry migration before cache backfill")
|
||||
stats, err := report.MigrateSnapshotRegistry(ctx, database)
|
||||
if err != nil {
|
||||
logger.Error("failed to migrate snapshot registry before cache backfill", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.Info("snapshot registry migration complete",
|
||||
"hourly_renamed", stats.HourlyRenamed,
|
||||
"hourly_registered", stats.HourlyRegistered,
|
||||
"daily_registered", stats.DailyRegistered,
|
||||
"monthly_registered", stats.MonthlyRegistered,
|
||||
)
|
||||
}
|
||||
|
||||
if err := db.SyncVcenterTotalsFromSnapshots(ctx, database.DB()); err != nil {
|
||||
logger.Error("failed to backfill hourly vcenter totals cache", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
latestSynced, err := db.SyncVcenterLatestTotalsFromHistory(ctx, database.DB())
|
||||
if err != nil {
|
||||
logger.Error("failed to backfill latest vcenter totals cache", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dailySnapshots, dailyRows, dailyErr := db.SyncVcenterAggregateTotalsFromRegistry(ctx, database.DB(), "daily")
|
||||
if dailyErr != nil {
|
||||
logger.Warn("daily vcenter aggregate cache backfill completed with warnings", "error", dailyErr)
|
||||
}
|
||||
monthlySnapshots, monthlyRows, monthlyErr := db.SyncVcenterAggregateTotalsFromRegistry(ctx, database.DB(), "monthly")
|
||||
if monthlyErr != nil {
|
||||
logger.Warn("monthly vcenter aggregate cache backfill completed with warnings", "error", monthlyErr)
|
||||
}
|
||||
|
||||
logger.Info("completed one-time vcenter cache backfill",
|
||||
"latest_rows_synced", latestSynced,
|
||||
"daily_snapshots_refreshed", dailySnapshots,
|
||||
"daily_rows_upserted", dailyRows,
|
||||
"monthly_snapshots_refreshed", monthlySnapshots,
|
||||
"monthly_rows_upserted", monthlyRows,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// Determine bind IP
|
||||
bindIP := strings.TrimSpace(s.Values.Settings.BindIP)
|
||||
|
||||
Reference in New Issue
Block a user