sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/jenkins/metrics.go (about) 1 /* 2 Copyright 2017 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 jenkins 18 19 import "github.com/prometheus/client_golang/prometheus" 20 21 var ( 22 requests = prometheus.NewCounterVec(prometheus.CounterOpts{ 23 Name: "jenkins_requests", 24 Help: "Number of Jenkins requests made from prow.", 25 }, []string{ 26 // http verb of the request 27 "verb", 28 // path of the request 29 "handler", 30 // http status code of the request 31 "code", 32 }) 33 requestRetries = prometheus.NewCounter(prometheus.CounterOpts{ 34 Name: "jenkins_request_retries", 35 Help: "Number of Jenkins request retries made from prow.", 36 }) 37 requestLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 38 Name: "jenkins_request_latency", 39 Help: "Time for a request to roundtrip between prow and Jenkins.", 40 Buckets: prometheus.DefBuckets, 41 }, []string{ 42 // http verb of the request 43 "verb", 44 // path of the request 45 "handler", 46 }) 47 resyncPeriod = prometheus.NewHistogram(prometheus.HistogramOpts{ 48 Name: "resync_period_seconds", 49 Help: "Time the controller takes to complete one reconciliation loop.", 50 Buckets: prometheus.ExponentialBuckets(1, 3, 5), 51 }) 52 ) 53 54 func init() { 55 prometheus.MustRegister(requests) 56 prometheus.MustRegister(requestRetries) 57 prometheus.MustRegister(requestLatency) 58 prometheus.MustRegister(resyncPeriod) 59 } 60 61 // ClientMetrics is a set of metrics gathered by the Jenkins client. 62 type ClientMetrics struct { 63 Requests *prometheus.CounterVec 64 RequestRetries prometheus.Counter 65 RequestLatency *prometheus.HistogramVec 66 } 67 68 // Metrics is a set of metrics gathered by the Jenkins operator. 69 // It includes client metrics and metrics related to the controller loop. 70 type Metrics struct { 71 ClientMetrics *ClientMetrics 72 ResyncPeriod prometheus.Histogram 73 } 74 75 // NewMetrics creates a new set of metrics for the Jenkins operator. 76 func NewMetrics() *Metrics { 77 return &Metrics{ 78 ClientMetrics: &ClientMetrics{ 79 Requests: requests, 80 RequestRetries: requestRetries, 81 RequestLatency: requestLatency, 82 }, 83 ResyncPeriod: resyncPeriod, 84 } 85 }