enhance utilisation of postgres features
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-04-20 10:19:27 +10:00
parent 98e92a8264
commit 8ccf5a7009
28 changed files with 2836 additions and 422 deletions
+62
View File
@@ -55,6 +55,8 @@ func main() {
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")
importSQLite := flag.String("import-sqlite", "", "Import a SQLite database file/DSN into the configured Postgres database and exit")
benchmarkAggregations := flag.Bool("benchmark-aggregations", false, "Run a one-time canonical aggregation benchmark (Go vs SQL) and exit")
benchmarkRuns := flag.Int("benchmark-runs", 3, "Number of benchmark iterations per mode when -benchmark-aggregations is set")
flag.Parse()
bootstrapLogger := log.New(log.LevelInfo, log.OutputText)
@@ -74,6 +76,7 @@ func main() {
log.ToOutput(strings.ToLower(strings.TrimSpace(s.Values.Settings.LogOutput))),
)
s.Logger = logger
db.SetVmHourlyStatsPostgresPartitioningEnabled(boolWithDefault(s.Values.Settings.PostgresVmHourlyPartitioning, false))
logger.Info("vCTP starting", "build_time", buildTime, "sha1_version", sha1ver, "go_version", runtime.Version(), "settings_file", *settingsPath)
warnDeprecatedPollingSettings(logger, s.Values)
@@ -191,6 +194,58 @@ func main() {
)
return
}
if *benchmarkAggregations {
logger.Info("Running one-shot canonical aggregation benchmark",
"runs_per_mode", *benchmarkRuns,
"driver", normalizedDriver,
"scheduled_aggregation_engine", strings.ToLower(strings.TrimSpace(s.Values.Settings.ScheduledAggregationEngine)),
)
ct := &tasks.CronTask{
Logger: logger,
Database: database,
Settings: s,
FirstHourlySnapshotCheck: true,
}
benchReport, err := ct.RunCanonicalAggregationBenchmark(ctx, *benchmarkRuns)
if err != nil {
logger.Error("canonical aggregation benchmark failed", "error", err)
os.Exit(1)
}
if !benchReport.DailyWindowStart.IsZero() {
logger.Info("daily canonical benchmark",
"window_start", benchReport.DailyWindowStart.Format(time.RFC3339),
"window_end", benchReport.DailyWindowEnd.Format(time.RFC3339),
"go_min", benchReport.DailyGo.Min,
"go_median", benchReport.DailyGo.Median,
"go_avg", benchReport.DailyGo.Avg,
"go_max", benchReport.DailyGo.Max,
"go_rows", benchReport.DailyGoRowsWritten,
"sql_min", benchReport.DailySQL.Min,
"sql_median", benchReport.DailySQL.Median,
"sql_avg", benchReport.DailySQL.Avg,
"sql_max", benchReport.DailySQL.Max,
"sql_rows", benchReport.DailySQLRowsWritten,
)
}
if !benchReport.MonthlyWindowStart.IsZero() {
logger.Info("monthly canonical benchmark",
"window_start", benchReport.MonthlyWindowStart.Format(time.RFC3339),
"window_end", benchReport.MonthlyWindowEnd.Format(time.RFC3339),
"go_min", benchReport.MonthlyGo.Min,
"go_median", benchReport.MonthlyGo.Median,
"go_avg", benchReport.MonthlyGo.Avg,
"go_max", benchReport.MonthlyGo.Max,
"go_rows", benchReport.MonthlyGoRowsWritten,
"sql_min", benchReport.MonthlySQL.Min,
"sql_median", benchReport.MonthlySQL.Median,
"sql_avg", benchReport.MonthlySQL.Avg,
"sql_max", benchReport.MonthlySQL.Max,
"sql_rows", benchReport.MonthlySQLRowsWritten,
)
}
logger.Info("Canonical aggregation benchmark complete; exiting")
return
}
// Determine bind IP
bindIP := strings.TrimSpace(s.Values.Settings.BindIP)
@@ -459,6 +514,13 @@ func durationFromSeconds(value int, fallback int) time.Duration {
return time.Second * time.Duration(value)
}
func boolWithDefault(value *bool, fallback bool) bool {
if value == nil {
return fallback
}
return *value
}
func resolveVcenterPassword(logger *slog.Logger, cipher *secrets.Secrets, legacyDecryptKeys [][]byte, raw string) ([]byte, string, error) {
if strings.TrimSpace(raw) == "" {
return nil, "", fmt.Errorf("vcenter password is empty")