Skip to content

Commit

Permalink
Split durable queue_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Will2817 committed Jun 6, 2019
1 parent b3b9fce commit 432bba2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func TestStreamingSubscriptionsMetricLabels(t *testing.T) {
defer s.Shutdown()

queueName := "some-queue-name"
durableSubscriptionName := "some-druable-name"
durableSubscriptionName := "some-durable-name"
durableGroupSubscriptionName := "some-group-durable-name"

sc, err := stan.Connect(stanClusterName, stanClientName,
Expand Down Expand Up @@ -469,7 +469,8 @@ func TestStreamingSubscriptionsMetricLabels(t *testing.T) {
streamingSunscriptionMetric, labelMaps[subscriptionIndex]["channel"], expectedLabelsNotFound)
}

if labelMaps[subscriptionIndex]["queue_name"] == fmt.Sprintf("%v:%v", durableGroupSubscriptionName, queueName) &&
if labelMaps[subscriptionIndex]["queue_name"] == queueName &&
labelMaps[subscriptionIndex]["durable_name"] == durableGroupSubscriptionName &&
labelMaps[subscriptionIndex]["is_durable"] == "true" {
foundQueuedDurableLabels = true
}
Expand Down
11 changes: 10 additions & 1 deletion collector/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package collector
import (
"net/http"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -226,8 +227,16 @@ func (nc *channelsCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(nc.chanLastSeq, prometheus.GaugeValue, float64(channel.LastSeq), server.ID, channel.Name)

for _, sub := range channel.Subscriptions {

// If this is a durable queue group subscription then split the durable name from the queue name
durableName := sub.DurableName
queueName := sub.QueueName
if sub.IsDurable && queueName != "" {
subStrings := strings.Split(queueName, ":")
durableName, queueName = subStrings[0], subStrings[1]
}
labelValues := []string{server.ID, channel.Name, sub.ClientID, sub.Inbox,
sub.QueueName, strconv.FormatBool(sub.IsDurable), strconv.FormatBool(sub.IsOffline), sub.DurableName}
queueName, strconv.FormatBool(sub.IsDurable), strconv.FormatBool(sub.IsOffline), durableName}
ch <- prometheus.MustNewConstMetric(nc.subsLastSent, prometheus.GaugeValue, float64(sub.LastSent), labelValues...)
ch <- prometheus.MustNewConstMetric(nc.subsPendingCount, prometheus.GaugeValue, float64(sub.PendingCount), labelValues...)
ch <- prometheus.MustNewConstMetric(nc.subsMaxInFlight, prometheus.GaugeValue, float64(sub.MaxInflight), labelValues...)
Expand Down

0 comments on commit 432bba2

Please sign in to comment.