github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/pubsub/subscriber/metrics.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package subscriber
    18  
    19  import (
    20  	"github.com/prometheus/client_golang/prometheus"
    21  )
    22  
    23  const (
    24  	responseCodeLabel = "response_code"
    25  	subscriptionLabel = "subscription"
    26  )
    27  
    28  var (
    29  	// Define all metrics for pubsub subscriptions here.
    30  
    31  	// Common
    32  	messageCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    33  		Name: "prow_pubsub_message_counter",
    34  		Help: "A counter of the webhooks made to prow.",
    35  	}, []string{subscriptionLabel})
    36  	errorCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    37  		Name: "prow_pubsub_error_counter",
    38  		Help: "A counter of the webhooks made to prow.",
    39  	}, []string{subscriptionLabel})
    40  
    41  	// Pull Server
    42  	ackedMessagesCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    43  		Name: "prow_pubsub_ack_counter",
    44  		Help: "A counter for message acked made to prow.",
    45  	}, []string{subscriptionLabel})
    46  	nackedMessagesCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    47  		Name: "prow_pubsub_nack_counter",
    48  		Help: "A counter for message nacked made to prow.",
    49  	}, []string{subscriptionLabel})
    50  
    51  	// Push Server
    52  	responseCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
    53  		Name: "prow_pubsub_response_codes",
    54  		Help: "A counter of the different responses server has responded to Push Events with.",
    55  	}, []string{responseCodeLabel, subscriptionLabel})
    56  )
    57  
    58  func init() {
    59  	prometheus.MustRegister(messageCounter)
    60  	prometheus.MustRegister(responseCounter)
    61  	prometheus.MustRegister(errorCounter)
    62  	prometheus.MustRegister(ackedMessagesCounter)
    63  	prometheus.MustRegister(nackedMessagesCounter)
    64  }
    65  
    66  type Metrics struct {
    67  	// Common
    68  	MessageCounter *prometheus.CounterVec
    69  	ErrorCounter   *prometheus.CounterVec
    70  
    71  	// Pull Server
    72  	ACKMessageCounter  *prometheus.CounterVec
    73  	NACKMessageCounter *prometheus.CounterVec
    74  
    75  	// Push Server
    76  	ResponseCounter *prometheus.CounterVec
    77  }
    78  
    79  func NewMetrics() *Metrics {
    80  	return &Metrics{
    81  		MessageCounter:     messageCounter,
    82  		ResponseCounter:    responseCounter,
    83  		ErrorCounter:       errorCounter,
    84  		ACKMessageCounter:  ackedMessagesCounter,
    85  		NACKMessageCounter: nackedMessagesCounter,
    86  	}
    87  }