Skip to content

Commit

Permalink
feat: change metric from counter to gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
yudhasubki committed Dec 15, 2023
1 parent b352c78 commit 1a1e480
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type listenerOption struct {
}

type listenerMetric struct {
totalEnqueue prometheus.Counter
totalConsumedMessage prometheus.Counter
totalEnqueue prometheus.Gauge
}

func newListener[V chan blockio.ResponseMessages](serverCtx context.Context, jobId string, subscriber core.Subscriber, bucket *kv) (*Listener[V], error) {
Expand Down Expand Up @@ -100,7 +100,7 @@ func newListener[V chan blockio.ResponseMessages](serverCtx context.Context, job
onRemove: &atomic.Bool{},
response: make(chan chan eventListener),
metric: &listenerMetric{
totalEnqueue: metric.TotalRequestQueueSubscriber(jobId, subscriber.Name),
totalEnqueue: metric.TotalFlightRequestQueueSubscriber(jobId, subscriber.Name),
totalConsumedMessage: metric.TotalConsumedMessage(jobId, subscriber.Name),
},
}
Expand Down Expand Up @@ -293,6 +293,7 @@ func (listener *Listener[V]) dequeue(id string) {
}
}

go listener.metric.totalEnqueue.Dec()
listener.PriorityQueue.Cond.Broadcast()
}

Expand Down Expand Up @@ -386,6 +387,8 @@ func (listener *Listener[V]) notify(response chan eventListener) {
response <- eventListener{
Kind: deliveryKindEventListener,
}

go listener.metric.totalEnqueue.Dec()
go listener.metric.totalConsumedMessage.Add(float64(len(messages)))
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ var (
})
}

TotalRequestQueueSubscriber = func(topicName, subscriberName string) prometheus.Counter {
return prometheus.NewCounter(prometheus.CounterOpts{
Name: fmt.Sprintf("total_request_queue_topic_%s_subscriber_%s", topicName, subscriberName),
Help: fmt.Sprintf("The current total request queue on topic %s subscriber %s", topicName, subscriberName),
TotalFlightRequestQueueSubscriber = func(topicName, subscriberName string) prometheus.Gauge {
return prometheus.NewGauge(prometheus.GaugeOpts{
Name: fmt.Sprintf("total_flight_request_queue_topic_%s_subscriber_%s", topicName, subscriberName),
Help: fmt.Sprintf("The current total flight request queue on topic %s subscriber %s", topicName, subscriberName),
})
}

Expand Down

0 comments on commit 1a1e480

Please sign in to comment.