github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/pkg/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 // The value of "failed-handle-prowjob" is the only case where prow operator 27 // should care 28 errorTypeLabel = "error_type" 29 ) 30 31 var ( 32 // Define all metrics for pubsub subscriptions here. 33 34 // Common 35 messageCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ 36 Name: "prow_pubsub_message_counter", 37 Help: "A counter of the webhooks made to prow.", 38 }, []string{subscriptionLabel}) 39 errorCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ 40 Name: "prow_pubsub_error_counter", 41 Help: "A counter of the webhooks made to prow.", 42 }, []string{subscriptionLabel, errorTypeLabel}) 43 44 // Pull Server 45 ackedMessagesCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ 46 Name: "prow_pubsub_ack_counter", 47 Help: "A counter for message acked made to prow.", 48 }, []string{subscriptionLabel}) 49 nackedMessagesCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ 50 Name: "prow_pubsub_nack_counter", 51 Help: "A counter for message nacked made to prow.", 52 }, []string{subscriptionLabel}) 53 54 // Push Server 55 responseCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ 56 Name: "prow_pubsub_response_codes", 57 Help: "A counter of the different responses server has responded to Push Events with.", 58 }, []string{responseCodeLabel, subscriptionLabel}) 59 ) 60 61 func init() { 62 prometheus.MustRegister(messageCounter) 63 prometheus.MustRegister(responseCounter) 64 prometheus.MustRegister(errorCounter) 65 prometheus.MustRegister(ackedMessagesCounter) 66 prometheus.MustRegister(nackedMessagesCounter) 67 } 68 69 type Metrics struct { 70 // Common 71 MessageCounter *prometheus.CounterVec 72 ErrorCounter *prometheus.CounterVec 73 74 // Pull Server 75 ACKMessageCounter *prometheus.CounterVec 76 NACKMessageCounter *prometheus.CounterVec 77 78 // Push Server 79 ResponseCounter *prometheus.CounterVec 80 } 81 82 func NewMetrics() *Metrics { 83 return &Metrics{ 84 MessageCounter: messageCounter, 85 ResponseCounter: responseCounter, 86 ErrorCounter: errorCounter, 87 ACKMessageCounter: ackedMessagesCounter, 88 NACKMessageCounter: nackedMessagesCounter, 89 } 90 }