Weather service proxy support
All checks were successful
Build and Publish / release (push) Successful in 3m51s

This commit is contained in:
2025-01-12 17:23:32 -05:00
parent 7fc1fc9b56
commit 19823ea08f
13 changed files with 285 additions and 255 deletions

View File

@ -7,6 +7,8 @@ import (
"github.com/rs/zerolog"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
)
type MetricRecorder struct {
@ -20,15 +22,15 @@ type RecordOpts struct {
IntVal *int
FloatVal *float64
Attributes []attribute.KeyValue
Field WeatherUpdateField
StationInfo *StationInfo
Field string
Station *config.WeatherStation
}
func (r *MetricRecorder) Record(opts *RecordOpts) {
if opts.StationInfo != nil && !opts.keep() {
if opts.Station != nil && !opts.keep() {
r.l.Trace().
Str("field", string(opts.Field)).
Str("station", *opts.StationInfo.Name).
Str("station", opts.Station.Name).
Msg("Metric dropped by station config")
return
} else if opts.Int64Gauge == nil && opts.Float64Gauge == nil {
@ -39,8 +41,8 @@ func (r *MetricRecorder) Record(opts *RecordOpts) {
if opts.Int64Gauge != nil {
if opts.IntVal == nil {
log := r.l.Trace().Str("field", string(opts.Field))
if opts.StationInfo != nil {
log = log.Str("station", *opts.StationInfo.Name)
if opts.Station != nil {
log = log.Str("station", opts.Station.Name)
}
log.Msg("Dropping nil int metric")
return
@ -49,8 +51,8 @@ func (r *MetricRecorder) Record(opts *RecordOpts) {
} else if opts.Float64Gauge != nil {
if opts.FloatVal == nil {
log := r.l.Trace().Str("field", string(opts.Field))
if opts.StationInfo != nil {
log = log.Str("station", *opts.StationInfo.Name)
if opts.Station != nil {
log = log.Str("station", opts.Station.Name)
}
log.Msg("Dropping nil float metric")
return
@ -61,8 +63,8 @@ func (r *MetricRecorder) Record(opts *RecordOpts) {
func (o *RecordOpts) keep() bool {
// If keep fields are given, only check keep fields
if len(o.StationInfo.Keep) > 0 {
for _, f := range o.StationInfo.Keep {
if len(o.Station.KeepMetrics) > 0 {
for _, f := range o.Station.KeepMetrics {
if f == o.Field {
return true
}
@ -70,7 +72,7 @@ func (o *RecordOpts) keep() bool {
return false
}
for _, f := range o.StationInfo.Drop {
for _, f := range o.Station.DropMetrics {
if f == o.Field {
return false
}