sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/githubeventserver/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 githubeventserver 18 19 import ( 20 "github.com/prometheus/client_golang/prometheus" 21 22 "sigs.k8s.io/prow/pkg/plugins" 23 ) 24 25 var ( 26 // Define all metrics for webhooks here. 27 webhookCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ 28 Name: "prow_webhook_counter", 29 Help: "A counter of the webhooks made to prow.", 30 }, []string{"event_type"}) 31 responseCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ 32 Name: "prow_webhook_response_codes", 33 Help: "A counter of the different responses hook has responded to webhooks with.", 34 }, []string{"response_code"}) 35 pluginHandleDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 36 Name: "prow_plugin_handle_duration_seconds", 37 Help: "How long Prow took to handle an event by plugin, event type and action.", 38 Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 20, 40, 80, 160, 320, 640}, 39 }, []string{"event_type", "action", "plugin", "took_action"}) 40 pluginHandleErrors = prometheus.NewCounterVec(prometheus.CounterOpts{ 41 Name: "prow_plugin_handle_errors", 42 Help: "Prow errors handling an event by plugin, event type and action.", 43 }, []string{"event_type", "action", "plugin", "took_action"}) 44 ) 45 46 func init() { 47 prometheus.MustRegister(webhookCounter) 48 prometheus.MustRegister(responseCounter) 49 prometheus.MustRegister(pluginHandleDuration) 50 prometheus.MustRegister(pluginHandleErrors) 51 } 52 53 // Metrics is a set of metrics gathered by hook. 54 type Metrics struct { 55 WebhookCounter *prometheus.CounterVec 56 ResponseCounter *prometheus.CounterVec 57 PluginHandleDuration *prometheus.HistogramVec 58 PluginHandleErrors *prometheus.CounterVec 59 *plugins.Metrics 60 } 61 62 // PluginMetrics is a set of metrics that are gathered by plugins. 63 // It is up the consumers of these metrics to ensure that they 64 // update the values in a thread-safe manner. 65 type PluginMetrics struct { 66 ConfigMapGauges *prometheus.GaugeVec 67 } 68 69 // NewMetrics creates a new set of metrics for the hook server. 70 func NewMetrics() *Metrics { 71 return &Metrics{ 72 WebhookCounter: webhookCounter, 73 ResponseCounter: responseCounter, 74 PluginHandleDuration: pluginHandleDuration, 75 PluginHandleErrors: pluginHandleErrors, 76 Metrics: plugins.NewMetrics(), 77 } 78 }