Compare commits

..

No commits in common. "44bf293eabf2d28810faa66e78a034ce80604eb9" and "eaf2cf211d196a79961dffe63ddc665f6480e79e" have entirely different histories.

3 changed files with 18 additions and 45 deletions

View File

@ -7,7 +7,6 @@ import (
"context" "context"
"fmt" "fmt"
"net/http" "net/http"
"sync"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel" "gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
"github.com/rs/zerolog" "github.com/rs/zerolog"
@ -121,40 +120,26 @@ func (aw *AmbientWeather) handleProviderRequest(
// Uses a weather update to allow awn to publish to wunderground and // Uses a weather update to allow awn to publish to wunderground and
// visa versa. // visa versa.
if station := update.StationConfig; station != nil { if station := update.StationConfig; station != nil {
// Perform proxy updates in parallel if enabled
var proxyWg sync.WaitGroup
if station.ProxyToAWN { if station.ProxyToAWN {
proxyWg.Add(1) err := aw.awnProvider.ProxyReq(ctx, update)
go func() { if err != nil {
defer proxyWg.Done() zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
err := aw.awnProvider.ProxyReq(ctx, update) return
if err != nil { }
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather") zerolog.Ctx(aw.appCtx).Debug().
return Str("station", station.Name).
} Msg("proxied weather update to awn")
zerolog.Ctx(aw.appCtx).Debug().
Str("station", station.Name).
Msg("proxied weather update to awn")
}()
} }
if station.ProxyToWunderground { if station.ProxyToWunderground {
proxyWg.Add(1) err := aw.wuProvider.ProxyReq(ctx, update)
go func() { if err != nil {
defer proxyWg.Done() zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
err := aw.wuProvider.ProxyReq(ctx, update) return
if err != nil { }
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather") zerolog.Ctx(aw.appCtx).Debug().
return Str("station", station.Name).
} Msg("proxied weather update to wunderground")
zerolog.Ctx(aw.appCtx).Debug().
Str("station", station.Name).
Msg("proxied weather update to wunderground")
}()
} }
proxyWg.Wait()
} }
} }

View File

@ -8,7 +8,6 @@ import (
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel" "gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"github.com/rs/zerolog/log"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
@ -44,18 +43,12 @@ func (awn *AWNProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpd
Get(awnURL) Get(awnURL)
if err != nil { if err != nil {
span.RecordError(err) span.RecordError(err)
span.SetAttributes(
attribute.String("query", resp.Request.QueryParam.Encode()),
attribute.String("body", string(resp.Body())),
)
span.SetStatus(codes.Error, err.Error()) span.SetStatus(codes.Error, err.Error())
log.Err(err).Any("query", resp.Request.PathParams).
Int("statusCode", resp.StatusCode()).
Msg("awn proxy failed")
} }
span.SetAttributes( span.SetAttributes(
attribute.Int("statusCode", resp.StatusCode()), attribute.Int("statusCode", resp.StatusCode()),
attribute.String("body", string(resp.Body())),
) )
return err return err

View File

@ -6,7 +6,6 @@ import (
"net/url" "net/url"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"github.com/rs/zerolog/log"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
"k8s.io/utils/ptr" "k8s.io/utils/ptr"
@ -41,17 +40,13 @@ func (wu *WUProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpdat
span.SetStatus(codes.Error, err.Error()) span.SetStatus(codes.Error, err.Error())
span.SetAttributes( span.SetAttributes(
attribute.String("query", resp.Request.QueryParam.Encode()), attribute.String("query", resp.Request.QueryParam.Encode()),
attribute.String("body", string(resp.Body())),
) )
span.RecordError(err) span.RecordError(err)
log.Err(err).
Int("statusCode", resp.StatusCode()).
Any("query", resp.Request.PathParams).
Msg("wunderground proxy failed")
} }
span.SetAttributes( span.SetAttributes(
attribute.Int("statusCode", resp.StatusCode()), attribute.Int("statusCode", resp.StatusCode()),
attribute.String("body", string(resp.Body())),
) )
return err return err