github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/metrics/release.go (about) 1 /* 2 Copyright 2022. 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 metrics 18 19 import ( 20 "github.com/prometheus/client_golang/prometheus" 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 "sigs.k8s.io/controller-runtime/pkg/metrics" 23 ) 24 25 var ( 26 ReleaseConcurrentTotal = prometheus.NewGaugeVec( 27 prometheus.GaugeOpts{ 28 Name: "release_concurrent_total", 29 Help: "Total number of concurrent release attempts", 30 }, 31 []string{}, 32 ) 33 34 ReleaseConcurrentPostActionsExecutionsTotal = prometheus.NewGaugeVec( 35 prometheus.GaugeOpts{ 36 Name: "release_concurrent_post_actions_executions_total", 37 Help: "Total number of concurrent release post actions executions attempts", 38 }, 39 []string{}, 40 ) 41 42 ReleaseConcurrentProcessingsTotal = prometheus.NewGaugeVec( 43 prometheus.GaugeOpts{ 44 Name: "release_concurrent_processings_total", 45 Help: "Total number of concurrent release processing attempts", 46 }, 47 []string{}, 48 ) 49 50 ReleasePreProcessingDurationSeconds = prometheus.NewHistogramVec( 51 releasePreProcessingDurationSecondsOpts, 52 releasePreProcessingDurationSecondsLabels, 53 ) 54 releasePreProcessingDurationSecondsLabels = []string{ 55 "reason", 56 "target", 57 } 58 releasePreProcessingDurationSecondsOpts = prometheus.HistogramOpts{ 59 Name: "release_pre_processing_duration_seconds", 60 Help: "How long in seconds a Release takes to start processing", 61 Buckets: []float64{5, 10, 15, 30, 45, 60, 90, 120, 180, 240, 300}, 62 } 63 64 ReleaseValidationDurationSeconds = prometheus.NewHistogramVec( 65 releaseValidationDurationSecondsOpts, 66 releaseValidationDurationSecondsLabels, 67 ) 68 releaseValidationDurationSecondsLabels = []string{ 69 "reason", 70 "target", 71 } 72 releaseValidationDurationSecondsOpts = prometheus.HistogramOpts{ 73 Name: "release_validation_duration_seconds", 74 Help: "How long in seconds a Release takes to validate", 75 Buckets: []float64{5, 10, 15, 30, 45, 60, 90, 120, 180, 240, 300}, 76 } 77 78 ReleaseDurationSeconds = prometheus.NewHistogramVec( 79 releaseDurationSecondsOpts, 80 releaseDurationSecondsLabels, 81 ) 82 releaseDurationSecondsLabels = []string{ 83 "post_actions_reason", 84 "processing_reason", 85 "release_reason", 86 "target", 87 "validation_reason", 88 } 89 releaseDurationSecondsOpts = prometheus.HistogramOpts{ 90 Name: "release_duration_seconds", 91 Help: "How long in seconds a Release takes to complete", 92 Buckets: []float64{60, 150, 300, 450, 600, 750, 900, 1050, 1200, 1800, 3600}, 93 } 94 95 ReleasePostActionsExecutionDurationSeconds = prometheus.NewHistogramVec( 96 releasePostActionsExecutionDurationSecondsOpts, 97 releasePostActionsExecutionDurationSecondsLabels, 98 ) 99 releasePostActionsExecutionDurationSecondsLabels = []string{ 100 "reason", 101 } 102 releasePostActionsExecutionDurationSecondsOpts = prometheus.HistogramOpts{ 103 Name: "release_post_actions_execution_duration_seconds", 104 Help: "How long in seconds Release post-actions take to complete", 105 Buckets: []float64{60, 150, 300, 450, 600, 750, 900, 1050, 1200, 1800, 3600}, 106 } 107 108 ReleaseProcessingDurationSeconds = prometheus.NewHistogramVec( 109 releaseProcessingDurationSecondsOpts, 110 releaseProcessingDurationSecondsLabels, 111 ) 112 releaseProcessingDurationSecondsLabels = []string{ 113 "reason", 114 "target", 115 } 116 releaseProcessingDurationSecondsOpts = prometheus.HistogramOpts{ 117 Name: "release_processing_duration_seconds", 118 Help: "How long in seconds a Release processing takes to complete", 119 Buckets: []float64{60, 150, 300, 450, 600, 750, 900, 1050, 1200, 1800, 3600}, 120 } 121 122 ReleaseTotal = prometheus.NewCounterVec( 123 releaseTotalOpts, 124 releaseTotalLabels, 125 ) 126 releaseTotalLabels = []string{ 127 "post_actions_reason", 128 "processing_reason", 129 "release_reason", 130 "target", 131 "validation_reason", 132 } 133 releaseTotalOpts = prometheus.CounterOpts{ 134 Name: "release_total", 135 Help: "Total number of releases reconciled by the operator", 136 } 137 ) 138 139 // RegisterCompletedRelease registers a Release as complete, decreasing the number of concurrent releases, adding a new 140 // observation for the Release duration and increasing the total number of releases. If either the startTime or the 141 // completionTime parameters are nil, no action will be taken. 142 func RegisterCompletedRelease(startTime, completionTime *metav1.Time, 143 postActionsReason, processingReason, releaseReason, target, validationReason string) { 144 if startTime == nil || completionTime == nil { 145 return 146 } 147 148 labels := prometheus.Labels{ 149 "post_actions_reason": postActionsReason, 150 "processing_reason": processingReason, 151 "release_reason": releaseReason, 152 "target": target, 153 "validation_reason": validationReason, 154 } 155 ReleaseConcurrentTotal.WithLabelValues().Dec() 156 ReleaseDurationSeconds. 157 With(labels). 158 Observe(completionTime.Sub(startTime.Time).Seconds()) 159 ReleaseTotal.With(labels).Inc() 160 } 161 162 // RegisterCompletedReleasePostActionsExecuted registers a Release post-actions execution as complete, adding a new 163 // observation for the Release post-actions execution duration and decreasing the number of concurrent executions. 164 // If either the startTime or the completionTime parameters are nil, no action will be taken. 165 func RegisterCompletedReleasePostActionsExecuted(startTime, completionTime *metav1.Time, reason string) { 166 if startTime == nil || completionTime == nil { 167 return 168 } 169 170 ReleasePostActionsExecutionDurationSeconds. 171 With(prometheus.Labels{ 172 "reason": reason, 173 }). 174 Observe(completionTime.Sub(startTime.Time).Seconds()) 175 ReleaseConcurrentPostActionsExecutionsTotal.WithLabelValues().Dec() 176 } 177 178 // RegisterCompletedReleaseProcessing registers a Release processing as complete, adding a new observation for the 179 // Release processing duration and decreasing the number of concurrent processings. If either the startTime or the 180 // completionTime parameters are nil, no action will be taken. 181 func RegisterCompletedReleaseProcessing(startTime, completionTime *metav1.Time, reason, target string) { 182 if startTime == nil || completionTime == nil { 183 return 184 } 185 186 ReleaseProcessingDurationSeconds. 187 With(prometheus.Labels{ 188 "reason": reason, 189 "target": target, 190 }). 191 Observe(completionTime.Sub(startTime.Time).Seconds()) 192 ReleaseConcurrentProcessingsTotal.WithLabelValues().Dec() 193 } 194 195 // RegisterValidatedRelease registers a Release as validated, adding a new observation for the 196 // Release validated seconds. If either the startTime or the validationTime are nil, 197 // no action will be taken. 198 func RegisterValidatedRelease(startTime, validationTime *metav1.Time, reason, target string) { 199 if validationTime == nil || startTime == nil { 200 return 201 } 202 203 ReleaseValidationDurationSeconds. 204 With(prometheus.Labels{ 205 "reason": reason, 206 "target": target, 207 }). 208 Observe(validationTime.Sub(startTime.Time).Seconds()) 209 } 210 211 // RegisterNewRelease register a new Release, increasing the number of concurrent releases. 212 func RegisterNewRelease() { 213 ReleaseConcurrentTotal.WithLabelValues().Inc() 214 } 215 216 // RegisterNewReleaseProcessing registers a new Release processing, adding a new observation for the 217 // Release start processing duration and increasing the number of concurrent processings. If either the 218 // startTime or the processingStartTime are nil, no action will be taken. 219 func RegisterNewReleaseProcessing(startTime, processingStartTime *metav1.Time, reason, target string) { 220 if startTime == nil || processingStartTime == nil { 221 return 222 } 223 224 ReleasePreProcessingDurationSeconds. 225 With(prometheus.Labels{ 226 "reason": reason, 227 "target": target, 228 }). 229 Observe(processingStartTime.Sub(startTime.Time).Seconds()) 230 231 ReleaseConcurrentProcessingsTotal.WithLabelValues().Inc() 232 } 233 234 // RegisterNewReleasePostActionsExecution register a new Release post-actions execution, increasing the number of 235 // concurrent executions. 236 func RegisterNewReleasePostActionsExecution() { 237 ReleaseConcurrentPostActionsExecutionsTotal.WithLabelValues().Inc() 238 } 239 240 func init() { 241 metrics.Registry.MustRegister( 242 ReleaseConcurrentTotal, 243 ReleaseConcurrentProcessingsTotal, 244 ReleaseConcurrentPostActionsExecutionsTotal, 245 ReleasePreProcessingDurationSeconds, 246 ReleaseValidationDurationSeconds, 247 ReleaseDurationSeconds, 248 ReleasePostActionsExecutionDurationSeconds, 249 ReleaseProcessingDurationSeconds, 250 ReleaseTotal, 251 ) 252 }