forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package media
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// ReconcileMetadata combines bounded database inventory operations for the operator workflow.
|
||||
type ReconcileMetadata interface {
|
||||
Inventory
|
||||
OrphanMetadata
|
||||
}
|
||||
|
||||
// ReconcileObjects combines object inspection and listing for the operator workflow.
|
||||
type ReconcileObjects interface {
|
||||
ObjectInventory
|
||||
OrphanObjects
|
||||
}
|
||||
|
||||
// RunReconciliation emits one bounded result per page and stops on any uncertain dependency outcome.
|
||||
func RunReconciliation(ctx context.Context, metadata ReconcileMetadata, objects ReconcileObjects, output io.Writer, apply bool) error {
|
||||
encoder := json.NewEncoder(output)
|
||||
after := uuid.Nil
|
||||
for {
|
||||
result, err := Reconcile(ctx, metadata, objects, after, time.Hour, apply)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := encoder.Encode(result); err != nil {
|
||||
return err
|
||||
}
|
||||
if result.Scanned < 1000 {
|
||||
break
|
||||
}
|
||||
after = result.Next
|
||||
}
|
||||
key := ""
|
||||
for {
|
||||
result, err := ReconcileOrphans(ctx, metadata, objects, key, time.Hour, apply)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := encoder.Encode(result); err != nil {
|
||||
return err
|
||||
}
|
||||
if result.Scanned < 1000 {
|
||||
return nil
|
||||
}
|
||||
key = result.Next
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user