Skip to content

Commit

Permalink
Add status to the log entry for publisher errors
Browse files Browse the repository at this point in the history
Having the status code as a separate field makes it easier to work with
in Loki.

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
  • Loading branch information
mem committed Mar 27, 2023
1 parent 64b8bab commit cde31b5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/pusher/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (p *Publisher) publish(ctx context.Context, payload Payload) {
if len(payload.Streams()) > 0 {
if n, err := p.pushEvents(ctx, client.Events, payload.Streams()); err != nil {
httpStatusCode, hasStatusCode := prom.GetHttpStatusCode(err)
logger.Error().Err(err).Msg("publish events")
logger.Error().Err(err).Int("status", httpStatusCode).Msg("publish events")
p.errorCounter.WithLabelValues("logs", regionStr, tenantStr, strconv.Itoa(httpStatusCode)).Inc()
if hasStatusCode && httpStatusCode == http.StatusUnauthorized {
// Retry to get a new client, credentials might be stale.
Expand All @@ -175,7 +175,7 @@ func (p *Publisher) publish(ctx context.Context, payload Payload) {
if len(payload.Metrics()) > 0 {
if n, err := p.pushMetrics(ctx, client.Metrics, payload.Metrics()); err != nil {
httpStatusCode, hasStatusCode := prom.GetHttpStatusCode(err)
logger.Error().Err(err).Msg("publish metrics")
logger.Error().Err(err).Int("status", httpStatusCode).Msg("publish metrics")
p.errorCounter.WithLabelValues("metrics", regionStr, tenantStr, strconv.Itoa(httpStatusCode)).Inc()
if hasStatusCode && httpStatusCode == http.StatusUnauthorized {
// Retry to get a new client, credentials might be stale.
Expand Down

0 comments on commit cde31b5

Please sign in to comment.