generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metrics for admission attempts count and duration
Add role and rolebinding for prometheus to be able to list the services in the kueue-system namespace. Change-Id: I77cf51536ebf53ece9a4ba2d8457dbc3e71d1e8d
- Loading branch information
1 parent
9968361
commit f0d01ea
Showing
7 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,3 @@ spec: | |
- containerPort: 8443 | ||
protocol: TCP | ||
name: https | ||
- name: manager | ||
args: | ||
- "--zap-log-level=2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
resources: | ||
- monitor.yaml | ||
- role.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: prometheus-k8s | ||
namespace: system | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- services | ||
- endpoints | ||
- pods | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- apiGroups: | ||
- extensions | ||
resources: | ||
- ingresses | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- apiGroups: | ||
- networking.k8s.io | ||
resources: | ||
- ingresses | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: prometheus-k8s | ||
namespace: system | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: prometheus-k8s | ||
subjects: | ||
- kind: ServiceAccount | ||
name: prometheus-k8s | ||
namespace: monitoring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package metrics | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics" | ||
) | ||
|
||
type AdmissionResult string | ||
|
||
const ( | ||
subsystemName = "kueue" | ||
|
||
SuccessAdmissionResult AdmissionResult = "success" | ||
InadmissibleAdmissionResult AdmissionResult = "inadmissible" | ||
) | ||
|
||
var ( | ||
admissionAttempts = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Subsystem: subsystemName, | ||
Name: "admission_attempts_total", | ||
Help: "Number of attempts to admit pods, by result. `success` means that at least one workload was admitted, `inadmissible` means that no workload was admitted.", | ||
}, []string{"result"}, | ||
) | ||
|
||
admissionAttemptLatency = prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Subsystem: subsystemName, | ||
Name: "admission_attempt_duration_seconds", | ||
Help: "Latency of an admission attempt", | ||
}, []string{"result"}, | ||
) | ||
) | ||
|
||
func AdmissionAttempt(result AdmissionResult, duration time.Duration) { | ||
admissionAttempts.WithLabelValues(string(result)).Inc() | ||
admissionAttemptLatency.WithLabelValues(string(result)).Observe(duration.Seconds()) | ||
} | ||
|
||
func init() { | ||
metrics.Registry.MustRegister( | ||
admissionAttempts, | ||
admissionAttempts, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters