recorder implementations
This commit is contained in:
@@ -21,6 +21,10 @@ import (
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/provider/wunderground"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/memory"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/noop"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/redis"
|
||||
)
|
||||
|
||||
const defUpdatesToKeep = 120
|
||||
@@ -70,10 +74,22 @@ func (aw *AmbientWeather) Init() *AmbientWeather {
|
||||
}
|
||||
span.SetAttributes(attribute.Int("updatesToKeep", updatesToKeep))
|
||||
|
||||
// TODO: Support other recorders (don't rely on default)
|
||||
aw.weatherRecorder = recorder.NewWeatherRecorder(&recorder.Opts{
|
||||
// Choose weather recorder for grpc / api requests,
|
||||
// default is memory recorder
|
||||
var r recorders.Recorder
|
||||
switch aw.Config.RecorderConfig.Type {
|
||||
case config.TypeMemory:
|
||||
r = &memory.MemoryRecorder{}
|
||||
case config.TypeRedis:
|
||||
r = &redis.RedisRecorder{}
|
||||
case config.TypeNoop:
|
||||
r = &noop.NoopRecorder{}
|
||||
}
|
||||
|
||||
aw.weatherRecorder = recorder.MustNewWeatherRecorder(&recorder.Opts{
|
||||
Ctx: aw.appCtx,
|
||||
KeepLast: updatesToKeep,
|
||||
Recorder: r,
|
||||
})
|
||||
|
||||
aw.l.Trace().Any("awConfig", aw.Config).Send()
|
||||
|
@@ -8,7 +8,8 @@ import (
|
||||
type AmbientLocalExporterConfig struct {
|
||||
MetricPrefix string `yaml:"metricPrefix" default:"weather" env:"AMBIENT_METRIC_PREFIX"`
|
||||
UpdatesToKeep *int `yaml:"updatesToKeep" default:"1" env:"AMBIENT_UPDATES_TO_KEEP"`
|
||||
WeatherStations []WeatherStation `yaml:"weatherStations" env:"weatherStations"` // No env, too complex, not worth the time
|
||||
WeatherStations []WeatherStation `yaml:"weatherStations"` // No env, too complex, not worth the time
|
||||
RecorderConfig *RecorderConfig `yaml:"recorderConfig"`
|
||||
*config.AppConfig // Extends app config
|
||||
}
|
||||
|
||||
|
25
pkg/ambient/config/config_recorder.go
Normal file
25
pkg/ambient/config/config_recorder.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package config
|
||||
|
||||
type RecorderType string
|
||||
|
||||
const (
|
||||
TypeMemory RecorderType = "memory" // Stores weather updates in memory
|
||||
TypeRedis RecorderType = "redis" // Required for replicas > 1
|
||||
TypeNoop RecorderType = "noop" // No-op implementation
|
||||
)
|
||||
|
||||
type RecorderConfig struct {
|
||||
Type RecorderType `yaml:"type" env:"RECORDER_TYPE"` // memory|redis
|
||||
KeepLast int `yaml:"keepLast" env:"RECORDER_KEEP_LAST"`
|
||||
RedisConfig *RedisConfig
|
||||
}
|
||||
|
||||
type RedisConfig struct {
|
||||
RedisHost string `yaml:"redisHost" env:"REDIS_HOST" default:"127.0.0.1"`
|
||||
RedisPort int `yaml:"redisPort" env:"REDIS_PORT" default:"6379"`
|
||||
RedisUser string `yaml:"redisUser" env:"REDIS_USER"`
|
||||
RedisPassword string `yaml:"redisPassword" env:"REDIS_PASSWORD"`
|
||||
RedisDB int `yaml:"redisDB" env:"REDIS_DB" default:"0"`
|
||||
RedisTLS bool `yaml:"redisTLS" env:"REDIS_TLS" default:"false"`
|
||||
RedisTLSInsecure bool `yaml:"redisTLSInsecure" env:"REDIS_TLS_INSECURE" default:"false"`
|
||||
}
|
Reference in New Issue
Block a user