forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/observation"
|
||||
)
|
||||
|
||||
// Observer preserves job causality and records bounded processing measurements.
|
||||
type Observer interface {
|
||||
observation.Tracer
|
||||
// Extract restores a durable parent context.
|
||||
Extract(context.Context, string, string) context.Context
|
||||
// Inject serializes the producer's W3C carrier.
|
||||
Inject(context.Context) (string, string)
|
||||
// JobStarted increments current worker occupancy.
|
||||
JobStarted()
|
||||
// JobFinished records a real attempt's outcome and duration.
|
||||
JobFinished(context.Context, time.Duration, error)
|
||||
// Ready records latency from durable acceptance to confirmed publication.
|
||||
Ready(context.Context, time.Time)
|
||||
}
|
||||
|
||||
// WithObserver binds optional telemetry at the composition root.
|
||||
func (w *Worker) WithObserver(observer Observer) *Worker {
|
||||
w.observer = observer
|
||||
return w
|
||||
}
|
||||
|
||||
// publish traces one durable handoff and propagates the producer context to its consumer.
|
||||
func (w *Worker) publish(ctx context.Context, job Job) error {
|
||||
if w.observer == nil {
|
||||
return w.queue.Publish(ctx, job)
|
||||
}
|
||||
ctx = w.observer.Extract(ctx, job.Traceparent, job.Tracestate)
|
||||
ctx, end := w.observer.Start(ctx, "attachment.publish", "producer")
|
||||
job.Traceparent, job.Tracestate = w.observer.Inject(ctx)
|
||||
err := w.queue.Publish(ctx, job)
|
||||
end(err)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user