This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 3fefe19  Add const client label to metrics (#406)
3fefe19 is described below

commit 3fefe19b860793dc67957ae4509c48a5ed58707a
Author: cckellogg <[email protected]>
AuthorDate: Mon Nov 30 22:36:06 2020 -0700

    Add const client label to metrics (#406)
    
    * Add const client label to metrics
    
    * Remove string format
    
    * Fix formatting
---
 pulsar/consumer_impl.go           | 15 ++++++++------
 pulsar/consumer_partition.go      | 42 +++++++++++++++++++++++----------------
 pulsar/internal/connection.go     | 20 +++++++++++--------
 pulsar/internal/lookup_service.go |  5 +++--
 pulsar/internal/metrics.go        | 24 ++++++++++++++++++++++
 pulsar/internal/rpc_client.go     |  5 +++--
 pulsar/metrics.go                 | 24 ++++++++++++++++++++++
 pulsar/producer_impl.go           | 15 ++++++++------
 pulsar/producer_partition.go      | 39 +++++++++++++++++++++---------------
 9 files changed, 132 insertions(+), 57 deletions(-)

diff --git a/pulsar/consumer_impl.go b/pulsar/consumer_impl.go
index 8ae9161..fc6c0fb 100644
--- a/pulsar/consumer_impl.go
+++ b/pulsar/consumer_impl.go
@@ -36,18 +36,21 @@ import (
 
 var (
        consumersOpened = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_consumers_opened",
-               Help: "Counter of consumers created by the client",
+               Name:        "pulsar_client_consumers_opened",
+               Help:        "Counter of consumers created by the client",
+               ConstLabels: constLabels(),
        })
 
        consumersClosed = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_consumers_closed",
-               Help: "Counter of consumers closed by the client",
+               Name:        "pulsar_client_consumers_closed",
+               Help:        "Counter of consumers closed by the client",
+               ConstLabels: constLabels(),
        })
 
        consumersPartitions = promauto.NewGauge(prometheus.GaugeOpts{
-               Name: "pulsar_client_consumers_partitions_active",
-               Help: "Counter of individual partitions the consumers are 
currently active",
+               Name:        "pulsar_client_consumers_partitions_active",
+               Help:        "Counter of individual partitions the consumers 
are currently active",
+               ConstLabels: constLabels(),
        })
 )
 
diff --git a/pulsar/consumer_partition.go b/pulsar/consumer_partition.go
index 5ec51fb..13888b5 100644
--- a/pulsar/consumer_partition.go
+++ b/pulsar/consumer_partition.go
@@ -36,44 +36,52 @@ import (
 
 var (
        messagesReceived = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_messages_received",
-               Help: "Counter of messages received by the client",
+               Name:        "pulsar_client_messages_received",
+               Help:        "Counter of messages received by the client",
+               ConstLabels: constLabels(),
        })
 
        bytesReceived = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_bytes_received",
-               Help: "Counter of bytes received by the client",
+               Name:        "pulsar_client_bytes_received",
+               Help:        "Counter of bytes received by the client",
+               ConstLabels: constLabels(),
        })
 
        prefetchedMessages = promauto.NewGauge(prometheus.GaugeOpts{
-               Name: "pulsar_client_consumer_prefetched_messages",
-               Help: "Number of messages currently sitting in the consumer 
pre-fetch queue",
+               Name:        "pulsar_client_consumer_prefetched_messages",
+               Help:        "Number of messages currently sitting in the 
consumer pre-fetch queue",
+               ConstLabels: constLabels(),
        })
 
        prefetchedBytes = promauto.NewGauge(prometheus.GaugeOpts{
-               Name: "pulsar_client_consumer_prefetched_bytes",
-               Help: "Total number of bytes currently sitting in the consumer 
pre-fetch queue",
+               Name:        "pulsar_client_consumer_prefetched_bytes",
+               Help:        "Total number of bytes currently sitting in the 
consumer pre-fetch queue",
+               ConstLabels: constLabels(),
        })
 
        acksCounter = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_consumer_acks",
-               Help: "Counter of messages acked by client",
+               Name:        "pulsar_client_consumer_acks",
+               Help:        "Counter of messages acked by client",
+               ConstLabels: constLabels(),
        })
 
        nacksCounter = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_consumer_nacks",
-               Help: "Counter of messages nacked by client",
+               Name:        "pulsar_client_consumer_nacks",
+               Help:        "Counter of messages nacked by client",
+               ConstLabels: constLabels(),
        })
 
        dlqCounter = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_consumer_dlq_messages",
-               Help: "Counter of messages sent to Dead letter queue",
+               Name:        "pulsar_client_consumer_dlq_messages",
+               Help:        "Counter of messages sent to Dead letter queue",
+               ConstLabels: constLabels(),
        })
 
        processingTime = promauto.NewHistogram(prometheus.HistogramOpts{
-               Name:    "pulsar_client_consumer_processing_time_seconds",
-               Help:    "Time it takes for application to process messages",
-               Buckets: []float64{.0005, .001, .005, .01, .025, .05, .1, .25, 
.5, 1, 2.5, 5, 10},
+               Name:        "pulsar_client_consumer_processing_time_seconds",
+               Help:        "Time it takes for application to process 
messages",
+               Buckets:     []float64{.0005, .001, .005, .01, .025, .05, .1, 
.25, .5, 1, 2.5, 5, 10},
+               ConstLabels: constLabels(),
        })
 
        lastestMessageID = LatestMessageID()
diff --git a/pulsar/internal/connection.go b/pulsar/internal/connection.go
index d9c124c..51aa829 100644
--- a/pulsar/internal/connection.go
+++ b/pulsar/internal/connection.go
@@ -49,23 +49,27 @@ const (
 
 var (
        connectionsOpened = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_connections_opened",
-               Help: "Counter of connections created by the client",
+               Name:        "pulsar_client_connections_opened",
+               Help:        "Counter of connections created by the client",
+               ConstLabels: constLabels(),
        })
 
        connectionsClosed = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_connections_closed",
-               Help: "Counter of connections closed by the client",
+               Name:        "pulsar_client_connections_closed",
+               Help:        "Counter of connections closed by the client",
+               ConstLabels: constLabels(),
        })
 
        connectionsEstablishmentErrors = 
promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_connections_establishment_errors",
-               Help: "Counter of errors in connections establishment",
+               Name:        "pulsar_client_connections_establishment_errors",
+               Help:        "Counter of errors in connections establishment",
+               ConstLabels: constLabels(),
        })
 
        connectionsHandshakeErrors = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_connections_handshake_errors",
-               Help: "Counter of errors in connections handshake (eg: authz)",
+               Name:        "pulsar_client_connections_handshake_errors",
+               Help:        "Counter of errors in connections handshake (eg: 
authz)",
+               ConstLabels: constLabels(),
        })
 )
 
diff --git a/pulsar/internal/lookup_service.go 
b/pulsar/internal/lookup_service.go
index 00f54ef..b72364b 100644
--- a/pulsar/internal/lookup_service.go
+++ b/pulsar/internal/lookup_service.go
@@ -32,8 +32,9 @@ import (
 
 var (
        lookupRequestsCount = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_lookup_count",
-               Help: "Counter of lookup requests made by the client",
+               Name:        "pulsar_client_lookup_count",
+               Help:        "Counter of lookup requests made by the client",
+               ConstLabels: constLabels(),
        })
 )
 
diff --git a/pulsar/internal/metrics.go b/pulsar/internal/metrics.go
new file mode 100644
index 0000000..ccd706d
--- /dev/null
+++ b/pulsar/internal/metrics.go
@@ -0,0 +1,24 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package internal
+
+func constLabels() map[string]string {
+       return map[string]string{
+               "client": "go",
+       }
+}
diff --git a/pulsar/internal/rpc_client.go b/pulsar/internal/rpc_client.go
index f53c16b..d13cf89 100644
--- a/pulsar/internal/rpc_client.go
+++ b/pulsar/internal/rpc_client.go
@@ -35,8 +35,9 @@ import (
 
 var (
        rpcRequestCount = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_rpc_count",
-               Help: "Counter of RPC requests made by the client",
+               Name:        "pulsar_client_rpc_count",
+               Help:        "Counter of RPC requests made by the client",
+               ConstLabels: constLabels(),
        })
 )
 
diff --git a/pulsar/metrics.go b/pulsar/metrics.go
new file mode 100644
index 0000000..c7b98af
--- /dev/null
+++ b/pulsar/metrics.go
@@ -0,0 +1,24 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package pulsar
+
+func constLabels() map[string]string {
+       return map[string]string{
+               "client": "go",
+       }
+}
diff --git a/pulsar/producer_impl.go b/pulsar/producer_impl.go
index 51ae69e..0c4b286 100644
--- a/pulsar/producer_impl.go
+++ b/pulsar/producer_impl.go
@@ -47,18 +47,21 @@ const (
 
 var (
        producersOpened = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_producers_opened",
-               Help: "Counter of producers created by the client",
+               Name:        "pulsar_client_producers_opened",
+               Help:        "Counter of producers created by the client",
+               ConstLabels: constLabels(),
        })
 
        producersClosed = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_producers_closed",
-               Help: "Counter of producers closed by the client",
+               Name:        "pulsar_client_producers_closed",
+               Help:        "Counter of producers closed by the client",
+               ConstLabels: constLabels(),
        })
 
        producersPartitions = promauto.NewGauge(prometheus.GaugeOpts{
-               Name: "pulsar_client_producers_partitions_active",
-               Help: "Counter of individual partitions the producers are 
currently active",
+               Name:        "pulsar_client_producers_partitions_active",
+               Help:        "Counter of individual partitions the producers 
are currently active",
+               ConstLabels: constLabels(),
        })
 )
 
diff --git a/pulsar/producer_partition.go b/pulsar/producer_partition.go
index bea73aa..09d9eb8 100644
--- a/pulsar/producer_partition.go
+++ b/pulsar/producer_partition.go
@@ -61,40 +61,47 @@ const (
 
 var (
        messagesPublished = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_messages_published",
-               Help: "Counter of messages published by the client",
+               Name:        "pulsar_client_messages_published",
+               Help:        "Counter of messages published by the client",
+               ConstLabels: constLabels(),
        })
 
        bytesPublished = promauto.NewCounter(prometheus.CounterOpts{
-               Name: "pulsar_client_bytes_published",
-               Help: "Counter of messages published by the client",
+               Name:        "pulsar_client_bytes_published",
+               Help:        "Counter of messages published by the client",
+               ConstLabels: constLabels(),
        })
 
        messagesPending = promauto.NewGauge(prometheus.GaugeOpts{
-               Name: "pulsar_client_producer_pending_messages",
-               Help: "Counter of messages pending to be published by the 
client",
+               Name:        "pulsar_client_producer_pending_messages",
+               Help:        "Counter of messages pending to be published by 
the client",
+               ConstLabels: constLabels(),
        })
 
        bytesPending = promauto.NewGauge(prometheus.GaugeOpts{
-               Name: "pulsar_client_producer_pending_bytes",
-               Help: "Counter of bytes pending to be published by the client",
+               Name:        "pulsar_client_producer_pending_bytes",
+               Help:        "Counter of bytes pending to be published by the 
client",
+               ConstLabels: constLabels(),
        })
 
        publishErrors = promauto.NewCounterVec(prometheus.CounterOpts{
-               Name: "pulsar_client_producer_errors",
-               Help: "Counter of publish errors",
+               Name:        "pulsar_client_producer_errors",
+               Help:        "Counter of publish errors",
+               ConstLabels: constLabels(),
        }, []string{"error"})
 
        publishLatency = promauto.NewHistogram(prometheus.HistogramOpts{
-               Name:    "pulsar_client_producer_latency_seconds",
-               Help:    "Publish latency experienced by the client",
-               Buckets: []float64{.0005, .001, .005, .01, .025, .05, .1, .25, 
.5, 1, 2.5, 5, 10},
+               Name:        "pulsar_client_producer_latency_seconds",
+               Help:        "Publish latency experienced by the client",
+               ConstLabels: constLabels(),
+               Buckets:     []float64{.0005, .001, .005, .01, .025, .05, .1, 
.25, .5, 1, 2.5, 5, 10},
        })
 
        publishRPCLatency = promauto.NewHistogram(prometheus.HistogramOpts{
-               Name:    "pulsar_client_producer_rpc_latency_seconds",
-               Help:    "Publish RPC latency experienced internally by the 
client when sending data to receiving an ack",
-               Buckets: []float64{.0005, .001, .005, .01, .025, .05, .1, .25, 
.5, 1, 2.5, 5, 10},
+               Name:        "pulsar_client_producer_rpc_latency_seconds",
+               Help:        "Publish RPC latency experienced internally by the 
client when sending data to receiving an ack",
+               ConstLabels: constLabels(),
+               Buckets:     []float64{.0005, .001, .005, .01, .025, .05, .1, 
.25, .5, 1, 2.5, 5, 10},
        })
 )
 

Reply via email to