move recorder to interface
All checks were successful
Build and Publish / check-chart (push) Successful in 36s
Build and Publish / helm-release (push) Has been skipped
Build and Publish / release (push) Successful in 3m8s

This commit is contained in:
2025-03-21 15:54:28 -04:00
parent e9b70fe6e0
commit a5abbbec1f
12 changed files with 256 additions and 120 deletions

View File

@ -9,20 +9,21 @@ import (
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/memory"
)
type WeatherRecorder struct {
updates []*weather.WeatherUpdate
keep int
ctx context.Context
tracer trace.Tracer
meter metric.Meter
recorder recorders.Recorder
ctx context.Context
tracer trace.Tracer
meter metric.Meter
*sync.RWMutex
}
type Opts struct {
Ctx context.Context
Recorder recorders.Recorder // If nil, will use memory recorder
KeepLast int
}
@ -31,12 +32,20 @@ func NewWeatherRecorder(opts *Opts) *WeatherRecorder {
opts.KeepLast = 1
}
if opts.Recorder == nil {
opts.Recorder = &memory.MemoryRecorder{}
}
opts.Recorder.Init(opts.Ctx, &recorders.RecorderOpts{
RetainLast: opts.KeepLast,
BaseCtx: opts.Ctx,
})
return &WeatherRecorder{
updates: make([]*weather.WeatherUpdate, 0, opts.KeepLast),
keep: opts.KeepLast,
ctx: opts.Ctx,
tracer: otel.GetTracer(opts.Ctx, "weatherRecorder"),
meter: otel.GetMeter(opts.Ctx, "weatherRecorder"),
RWMutex: &sync.RWMutex{},
ctx: opts.Ctx,
recorder: opts.Recorder,
tracer: otel.GetTracer(opts.Ctx, "weatherRecorder"),
meter: otel.GetMeter(opts.Ctx, "weatherRecorder"),
RWMutex: &sync.RWMutex{},
}
}