Compare commits
2 Commits
eaf2cf211d
...
44bf293eab
Author | SHA1 | Date | |
---|---|---|---|
44bf293eab | |||
f87b35b306 |
@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||
"github.com/rs/zerolog"
|
||||
@ -120,7 +121,13 @@ func (aw *AmbientWeather) handleProviderRequest(
|
||||
// Uses a weather update to allow awn to publish to wunderground and
|
||||
// visa versa.
|
||||
if station := update.StationConfig; station != nil {
|
||||
// Perform proxy updates in parallel if enabled
|
||||
var proxyWg sync.WaitGroup
|
||||
|
||||
if station.ProxyToAWN {
|
||||
proxyWg.Add(1)
|
||||
go func() {
|
||||
defer proxyWg.Done()
|
||||
err := aw.awnProvider.ProxyReq(ctx, update)
|
||||
if err != nil {
|
||||
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
|
||||
@ -129,8 +136,13 @@ func (aw *AmbientWeather) handleProviderRequest(
|
||||
zerolog.Ctx(aw.appCtx).Debug().
|
||||
Str("station", station.Name).
|
||||
Msg("proxied weather update to awn")
|
||||
}()
|
||||
}
|
||||
|
||||
if station.ProxyToWunderground {
|
||||
proxyWg.Add(1)
|
||||
go func() {
|
||||
defer proxyWg.Done()
|
||||
err := aw.wuProvider.ProxyReq(ctx, update)
|
||||
if err != nil {
|
||||
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
|
||||
@ -139,7 +151,10 @@ func (aw *AmbientWeather) handleProviderRequest(
|
||||
zerolog.Ctx(aw.appCtx).Debug().
|
||||
Str("station", station.Name).
|
||||
Msg("proxied weather update to wunderground")
|
||||
}()
|
||||
}
|
||||
|
||||
proxyWg.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
|
||||
@ -43,12 +44,18 @@ func (awn *AWNProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpd
|
||||
Get(awnURL)
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetAttributes(
|
||||
attribute.String("query", resp.Request.QueryParam.Encode()),
|
||||
attribute.String("body", string(resp.Body())),
|
||||
)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
log.Err(err).Any("query", resp.Request.PathParams).
|
||||
Int("statusCode", resp.StatusCode()).
|
||||
Msg("awn proxy failed")
|
||||
}
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.Int("statusCode", resp.StatusCode()),
|
||||
attribute.String("body", string(resp.Body())),
|
||||
)
|
||||
|
||||
return err
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"k8s.io/utils/ptr"
|
||||
@ -40,13 +41,17 @@ func (wu *WUProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpdat
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
span.SetAttributes(
|
||||
attribute.String("query", resp.Request.QueryParam.Encode()),
|
||||
attribute.String("body", string(resp.Body())),
|
||||
)
|
||||
span.RecordError(err)
|
||||
log.Err(err).
|
||||
Int("statusCode", resp.StatusCode()).
|
||||
Any("query", resp.Request.PathParams).
|
||||
Msg("wunderground proxy failed")
|
||||
}
|
||||
|
||||
span.SetAttributes(
|
||||
attribute.Int("statusCode", resp.StatusCode()),
|
||||
attribute.String("body", string(resp.Body())),
|
||||
)
|
||||
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user