k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/scheduler/metrics/profile_metrics.go (about) 1 /* 2 Copyright 2020 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 metrics 18 19 // This file contains helpers for metrics that are associated to a profile. 20 21 var ( 22 ScheduledResult = "scheduled" 23 UnschedulableResult = "unschedulable" 24 ErrorResult = "error" 25 ) 26 27 // PodScheduled can records a successful scheduling attempt and the duration 28 // since `start`. 29 func PodScheduled(profile string, duration float64) { 30 observeScheduleAttemptAndLatency(ScheduledResult, profile, duration) 31 } 32 33 // PodUnschedulable can records a scheduling attempt for an unschedulable pod 34 // and the duration since `start`. 35 func PodUnschedulable(profile string, duration float64) { 36 observeScheduleAttemptAndLatency(UnschedulableResult, profile, duration) 37 } 38 39 // PodScheduleError can records a scheduling attempt that had an error and the 40 // duration since `start`. 41 func PodScheduleError(profile string, duration float64) { 42 observeScheduleAttemptAndLatency(ErrorResult, profile, duration) 43 } 44 45 func observeScheduleAttemptAndLatency(result, profile string, duration float64) { 46 schedulingLatency.WithLabelValues(result, profile).Observe(duration) 47 scheduleAttempts.WithLabelValues(result, profile).Inc() 48 }