This commit is contained in:
@@ -795,22 +795,37 @@ func SaveTableReport(logger *slog.Logger, Database db.Database, ctx context.Cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addTotalsChartSheet(logger *slog.Logger, database db.Database, ctx context.Context, xlsx *excelize.File, tableName string) {
|
func addTotalsChartSheet(logger *slog.Logger, database db.Database, ctx context.Context, xlsx *excelize.File, tableName string) {
|
||||||
|
if logger == nil {
|
||||||
|
logger = slog.Default()
|
||||||
|
}
|
||||||
if strings.HasPrefix(tableName, "inventory_daily_summary_") {
|
if strings.HasPrefix(tableName, "inventory_daily_summary_") {
|
||||||
suffix := strings.TrimPrefix(tableName, "inventory_daily_summary_")
|
suffix := strings.TrimPrefix(tableName, "inventory_daily_summary_")
|
||||||
dayStart, err := time.ParseInLocation("20060102", suffix, time.Local)
|
dayStart, err := time.ParseInLocation("20060102", suffix, time.Local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Debug("hourly totals skip: invalid daily summary suffix", "table", tableName, "suffix", suffix, "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dayEnd := dayStart.AddDate(0, 0, 1)
|
dayEnd := dayStart.AddDate(0, 0, 1)
|
||||||
if err := EnsureSnapshotRegistry(ctx, database); err != nil {
|
if err := EnsureSnapshotRegistry(ctx, database); err != nil {
|
||||||
|
logger.Debug("hourly totals skip: snapshot registry unavailable", "table", tableName, "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
records, err := SnapshotRecordsWithFallback(ctx, database, "hourly", "inventory_hourly_", "epoch", dayStart, dayEnd.Add(2*time.Hour))
|
records, err := SnapshotRecordsWithFallback(ctx, database, "hourly", "inventory_hourly_", "epoch", dayStart, dayEnd.Add(2*time.Hour))
|
||||||
if err != nil || len(records) == 0 {
|
if err != nil {
|
||||||
|
logger.Debug("hourly totals skip: failed to load hourly snapshots", "table", tableName, "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(records) == 0 {
|
||||||
|
logger.Debug("hourly totals skip: no hourly snapshots found", "table", tableName, "window_start", dayStart, "window_end", dayEnd)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
points, err := buildHourlyTotals(ctx, logger, database.DB(), records, dayStart, dayEnd)
|
points, err := buildHourlyTotals(ctx, logger, database.DB(), records, dayStart, dayEnd)
|
||||||
if err != nil || len(points) == 0 {
|
if err != nil {
|
||||||
|
logger.Debug("hourly totals skip: build failed", "table", tableName, "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(points) == 0 {
|
||||||
|
logger.Debug("hourly totals skip: no hourly totals points", "table", tableName, "window_start", dayStart, "window_end", dayEnd)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeTotalsChart(logger, xlsx, "Hourly Totals", points)
|
writeTotalsChart(logger, xlsx, "Hourly Totals", points)
|
||||||
@@ -821,18 +836,30 @@ func addTotalsChartSheet(logger *slog.Logger, database db.Database, ctx context.
|
|||||||
suffix := strings.TrimPrefix(tableName, "inventory_monthly_summary_")
|
suffix := strings.TrimPrefix(tableName, "inventory_monthly_summary_")
|
||||||
monthStart, err := time.ParseInLocation("200601", suffix, time.Local)
|
monthStart, err := time.ParseInLocation("200601", suffix, time.Local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Debug("daily totals skip: invalid monthly summary suffix", "table", tableName, "suffix", suffix, "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
monthEnd := monthStart.AddDate(0, 1, 0)
|
monthEnd := monthStart.AddDate(0, 1, 0)
|
||||||
if err := EnsureSnapshotRegistry(ctx, database); err != nil {
|
if err := EnsureSnapshotRegistry(ctx, database); err != nil {
|
||||||
|
logger.Debug("daily totals skip: snapshot registry unavailable", "table", tableName, "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
records, err := SnapshotRecordsWithFallback(ctx, database, "daily", "inventory_daily_summary_", "20060102", monthStart, monthEnd)
|
records, err := SnapshotRecordsWithFallback(ctx, database, "daily", "inventory_daily_summary_", "20060102", monthStart, monthEnd)
|
||||||
if err != nil || len(records) == 0 {
|
if err != nil {
|
||||||
|
logger.Debug("daily totals skip: failed to load daily snapshots", "table", tableName, "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(records) == 0 {
|
||||||
|
logger.Debug("daily totals skip: no daily snapshots found", "table", tableName, "window_start", monthStart, "window_end", monthEnd)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
points, err := buildDailyTotals(ctx, database.DB(), records, true)
|
points, err := buildDailyTotals(ctx, database.DB(), records, true)
|
||||||
if err != nil || len(points) == 0 {
|
if err != nil {
|
||||||
|
logger.Debug("daily totals skip: build failed", "table", tableName, "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(points) == 0 {
|
||||||
|
logger.Debug("daily totals skip: no daily totals points", "table", tableName, "window_start", monthStart, "window_end", monthEnd)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeTotalsChart(logger, xlsx, "Daily Totals", points)
|
writeTotalsChart(logger, xlsx, "Daily Totals", points)
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ func (c *CronTask) RunVcenterSnapshotHourly(ctx context.Context, logger *slog.Lo
|
|||||||
rowCount, err := db.TableRowCount(ctx, dbConn, tableName)
|
rowCount, err := db.TableRowCount(ctx, dbConn, tableName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Logger.Warn("unable to count hourly snapshot rows", "error", err, "table", tableName)
|
c.Logger.Warn("unable to count hourly snapshot rows", "error", err, "table", tableName)
|
||||||
|
rowCount = -1
|
||||||
}
|
}
|
||||||
if err := report.RegisterSnapshot(ctx, c.Database, "hourly", tableName, startTime, rowCount); err != nil {
|
if err := report.RegisterSnapshot(ctx, c.Database, "hourly", tableName, startTime, rowCount); err != nil {
|
||||||
c.Logger.Warn("failed to register hourly snapshot", "error", err, "table", tableName)
|
c.Logger.Warn("failed to register hourly snapshot", "error", err, "table", tableName)
|
||||||
|
|||||||
Reference in New Issue
Block a user