sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/crier/metrics.go (about)

     1  /*
     2  Copyright 2022 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 crier reports finished prowjob status to git providers.
    18  package crier
    19  
    20  import "github.com/prometheus/client_golang/prometheus"
    21  
    22  const (
    23  	ResultError   = "ERROR"
    24  	ResultSuccess = "SUCCESS"
    25  )
    26  
    27  // Prometheus Metrics
    28  var (
    29  	crierMetrics = struct {
    30  		latency *prometheus.HistogramVec
    31  		// Count success/failures of reporting attempts.
    32  		reportingResults *prometheus.CounterVec
    33  	}{
    34  		latency: prometheus.NewHistogramVec(prometheus.HistogramOpts{
    35  			Name:    "crier_report_latency",
    36  			Help:    "Histogram of time spent reporting, calculated by the time difference between job completion and end of reporting.",
    37  			Buckets: []float64{1, 10, 20, 30, 60, 120, 180, 300, 600, 1200, 1800, 2700, 3600, 5400, 7200},
    38  		}, []string{
    39  			"reporter",
    40  		}),
    41  		reportingResults: prometheus.NewCounterVec(prometheus.CounterOpts{
    42  			Name: "crier_reporting_results",
    43  			Help: "Count of successful and failed reporting attempts by reporter.",
    44  		}, []string{
    45  			"reporter",
    46  			"result",
    47  		}),
    48  	}
    49  )
    50  
    51  func init() {
    52  	prometheus.MustRegister(crierMetrics.latency)
    53  	prometheus.MustRegister(crierMetrics.reportingResults)
    54  }