Skip to content

Commit

Permalink
fix: correct issue with metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Oct 2, 2024
1 parent 90308f2 commit edbd1f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions internal/client/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,13 @@ func (client *Client) jetstreamSubscribe(h <-chan *Message, streamName string) {
latency := time.Since(publishTime).Seconds()

client.metrics.Latency.With(prometheus.Labels{
"subject": msg.Subject,
"stream": streamName,
"cluster": clusterName,
}).Observe(latency)

client.metrics.SuccessCounter.With(prometheus.Labels{
"subject": msg.Subject,
"type": successfulSubscribe,
"stream": streamName,
"cluster": clusterName,
Expand Down Expand Up @@ -246,10 +248,14 @@ func (client *Client) coreSubscribe(subject string) {
latency := time.Since(publishTime).Seconds()

client.metrics.Latency.With(prometheus.Labels{
"subject": subject,
"stream": "-",
"cluster": clusterName,
}).Observe(latency)

client.metrics.SuccessCounter.With(prometheus.Labels{
"subject": subject,
"stream": "-",
"type": successfulSubscribe,
"cluster": clusterName,
}).Add(1)
Expand All @@ -269,6 +275,7 @@ func (client *Client) corePublish(subject string) {

if err := client.connection.Publish(subject, t); err != nil {
client.metrics.SuccessCounter.With(prometheus.Labels{
"stream": "-",
"subject": subject,
"type": failedPublish,
"cluster": clusterName,
Expand All @@ -284,6 +291,7 @@ func (client *Client) corePublish(subject string) {
}
} else {
client.metrics.SuccessCounter.With(prometheus.Labels{
"stream": "-",
"type": successfulPublish,
"cluster": clusterName,
"subject": subject,
Expand All @@ -305,6 +313,7 @@ func (client *Client) jetstreamPublish(ctx context.Context, subject string, stre

if ack, err := client.jetstream.Publish(ctx, subject, t); err != nil {
client.metrics.SuccessCounter.With(prometheus.Labels{
"subject": subject,
"type": failedPublish,
"stream": streamName,
"cluster": clusterName,
Expand All @@ -320,6 +329,7 @@ func (client *Client) jetstreamPublish(ctx context.Context, subject string, stre
}
} else {
client.metrics.SuccessCounter.With(prometheus.Labels{
"subject": subject,
"type": successfulPublish,
"stream": streamName,
"cluster": clusterName,
Expand Down
4 changes: 2 additions & 2 deletions internal/client/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewMetrics(conn string) Metrics {
"conn": conn,
},
Buckets: latencyBuckets,
}, []string{"stream", "cluster"}),
}, []string{"stream", "cluster", "subject"}),
SuccessCounter: newCounterVec(prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: Subsystem,
Expand All @@ -124,6 +124,6 @@ func NewMetrics(conn string) Metrics {
ConstLabels: prometheus.Labels{
"conn": conn,
},
}, []string{"type", "stream", "cluster"}),
}, []string{"type", "stream", "cluster", "subject"}),
}
}

0 comments on commit edbd1f9

Please sign in to comment.