better handle skipped inventories
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1086,21 +1086,36 @@ func (c *CronTask) captureHourlySnapshotForVcenter(ctx context.Context, startTim
|
||||
c.Logger.Warn("failed to locate previous hourly snapshot for deletion comparison", "error", prevTableErr, "url", url)
|
||||
}
|
||||
|
||||
prevSnapshotTime := int64(0)
|
||||
if prevTableName != "" {
|
||||
if suffix := strings.TrimPrefix(prevTableName, "inventory_hourly_"); suffix != prevTableName {
|
||||
if ts, err := strconv.ParseInt(suffix, 10, 64); err == nil {
|
||||
prevSnapshotTime = ts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if prevTableName != "" {
|
||||
moreMissing := c.markMissingFromPrevious(ctx, dbConn, prevTableName, url, startTime, presentSnapshots, presentByUuid, presentByName, inventoryByVmID, inventoryByUuid, inventoryByName)
|
||||
missingCount += moreMissing
|
||||
newCount = countNewFromPrevious(ctx, dbConn, prevTableName, url, presentSnapshots)
|
||||
if newCount > 0 {
|
||||
newRows := listNewFromPrevious(ctx, dbConn, prevTableName, url, presentSnapshots)
|
||||
names := make([]string, 0, len(newRows))
|
||||
for _, r := range newRows {
|
||||
if r.Name != "" {
|
||||
names = append(names, r.Name)
|
||||
} else if r.VmId.Valid {
|
||||
names = append(names, r.VmId.String)
|
||||
// Guard against gaps: if previous snapshot is much older than expected, skip "new" detection to avoid false positives when an hourly run was missed.
|
||||
snapshotPeriod := durationFromSeconds(c.Settings.Values.Settings.VcenterInventorySnapshotSeconds, time.Hour).Seconds()
|
||||
if prevSnapshotTime > 0 && startTime.Unix()-prevSnapshotTime > int64(snapshotPeriod*2) {
|
||||
c.Logger.Info("skipping new-VM detection due to gap between snapshots", "prev_table", prevTableName, "prev_snapshot_unix", prevSnapshotTime, "current_snapshot_unix", startTime.Unix())
|
||||
} else {
|
||||
newCount = countNewFromPrevious(ctx, dbConn, prevTableName, url, presentSnapshots)
|
||||
if newCount > 0 {
|
||||
newRows := listNewFromPrevious(ctx, dbConn, prevTableName, url, presentSnapshots)
|
||||
names := make([]string, 0, len(newRows))
|
||||
for _, r := range newRows {
|
||||
if r.Name != "" {
|
||||
names = append(names, r.Name)
|
||||
} else if r.VmId.Valid {
|
||||
names = append(names, r.VmId.String)
|
||||
}
|
||||
}
|
||||
c.Logger.Info("new VMs since previous snapshot", "prev_table", prevTableName, "count", newCount, "names", names)
|
||||
}
|
||||
c.Logger.Info("new VMs since previous snapshot", "prev_table", prevTableName, "count", newCount, "names", names)
|
||||
}
|
||||
c.Logger.Debug("compared with previous snapshot", "prev_table", prevTableName, "new_since_prev", newCount, "missing_since_prev", missingCount)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user