Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a metric for failure to publish data #280

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions internal/pusher/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Publisher struct {
clients map[int64]*remoteTarget
pushCounter *prometheus.CounterVec
errorCounter *prometheus.CounterVec
failedCounter *prometheus.CounterVec
bytesOut *prometheus.CounterVec
}

Expand All @@ -74,6 +75,17 @@ func NewPublisher(tm *TenantManager, publishCh <-chan Payload, logger zerolog.Lo

promRegisterer.MustRegister(errorCounter)

failedCounter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "push_failed_total",
Help: "Total number of push failed.",
},
[]string{"type", "tenantID"})

promRegisterer.MustRegister(failedCounter)

bytesOut := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Expand All @@ -92,6 +104,7 @@ func NewPublisher(tm *TenantManager, publishCh <-chan Payload, logger zerolog.Lo
logger: logger,
pushCounter: pushCounter,
errorCounter: errorCounter,
failedCounter: failedCounter,
bytesOut: bytesOut,
}
}
Expand All @@ -118,8 +131,8 @@ func (p *Publisher) publish(ctx context.Context, payload Payload) {
for retry := 2; retry > 0; retry-- {
client, err := p.getClient(ctx, tenantID, newClient)
if err != nil {
logger.Error().Err(err).Msg("get client")
p.errorCounter.WithLabelValues("client", tenantStr, "N/A").Inc()
logger.Error().Err(err).Msg("get client failed")
p.failedCounter.WithLabelValues("client", tenantStr).Inc()
return
}

Expand Down Expand Up @@ -168,6 +181,7 @@ func (p *Publisher) publish(ctx context.Context, payload Payload) {
}

// if we are here, we retried and failed
p.failedCounter.WithLabelValues("retry_exhausted", tenantStr).Inc()
logger.Warn().Msg("failed to push payload")
}

Expand Down