Skip to content

Commit

Permalink
Fix topic name on metrics tags (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
helder-junior authored Nov 12, 2024
1 parent eeeb708 commit 1ef4644
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (a *App) metricsReporterInterceptor(
a.log.WithField("route", info.FullMethod).Infof("Unexpected request type %T", t)
}

topic := events[0].Topic
topic := fmt.Sprintf("%s%s", a.config.GetString("kafka.producer.topicPrefix"), events[0].Topic)
metrics.APIPayloadSize.WithLabelValues(
topic).Observe(float64(payloadSize))

Expand Down
5 changes: 3 additions & 2 deletions server/sender/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ func (k *KafkaSender) SendEvent(
topic := event.GetTopic()
partition, offset, err := k.producer.Produce(ctx, topic, buf.Bytes())

topicFullName := fmt.Sprintf("%s%s", k.config.GetString("kafka.producer.topicPrefix"), topic)
kafkaStatus := "ok"
if err != nil {
kafkaStatus = "error"
l.WithError(err).Error("error producing event to kafka")
metrics.KafkaRequestLatency.WithLabelValues(kafkaStatus, topic).Observe(float64(time.Since(startTime).Milliseconds()))
metrics.KafkaRequestLatency.WithLabelValues(kafkaStatus, topicFullName).Observe(float64(time.Since(startTime).Milliseconds()))
return err
}
metrics.KafkaRequestLatency.WithLabelValues(kafkaStatus, topic).Observe(float64(time.Since(startTime).Milliseconds()))
metrics.KafkaRequestLatency.WithLabelValues(kafkaStatus, topicFullName).Observe(float64(time.Since(startTime).Milliseconds()))
l.WithFields(map[string]interface{}{
"partition": partition,
"offset": offset,
Expand Down

0 comments on commit 1ef4644

Please sign in to comment.