From c8811a41bd03ab92f7cdd890bac8535c7456282b Mon Sep 17 00:00:00 2001 From: Daniel Ferenci Date: Fri, 31 May 2024 15:58:15 +0200 Subject: [PATCH] introducing project creation time metric --- Makefile | 2 +- api/v1alpha1/zz_generated.deepcopy.go | 1 - .../crd/bases/core.cs.sap.com_projects.yaml | 20 +++++++++++-------- config/rbac/role.yaml | 1 - config/webhook/manifests.yaml | 1 - controllers/project_controller.go | 2 ++ crds/core.cs.sap.com_projects.yaml | 20 +++++++++++-------- internal/metrics/project_metrics.go | 8 ++++++++ 8 files changed, 35 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 59e30fa..ac4de81 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ LISTER_GEN ?= $(shell pwd)/bin/lister-gen ## Tool Versions KUSTOMIZE_VERSION ?= v3.8.7 -CONTROLLER_TOOLS_VERSION ?= v0.9.2 +CONTROLLER_TOOLS_VERSION ?= v0.14.0 CODE_GENERATOR_VERSION ?= v0.23.4 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index da12846..0fa931d 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and project-operator contributors diff --git a/config/crd/bases/core.cs.sap.com_projects.yaml b/config/crd/bases/core.cs.sap.com_projects.yaml index 18484fc..a53f588 100644 --- a/config/crd/bases/core.cs.sap.com_projects.yaml +++ b/config/crd/bases/core.cs.sap.com_projects.yaml @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 - creationTimestamp: null + controller-gen.kubebuilder.io/version: v0.14.0 name: projects.core.cs.sap.com spec: group: core.cs.sap.com @@ -28,14 +27,19 @@ spec: description: Project is the Schema for the projects API. properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources type: string kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds type: string metadata: type: object diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index c3f7110..0e1d04d 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -2,7 +2,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - creationTimestamp: null name: manager-role rules: - apiGroups: diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 117aed7..b500921 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -2,7 +2,6 @@ apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: - creationTimestamp: null name: validating-webhook-configuration webhooks: - admissionReviewVersions: diff --git a/controllers/project_controller.go b/controllers/project_controller.go index e149980..6920a3d 100644 --- a/controllers/project_controller.go +++ b/controllers/project_controller.go @@ -116,10 +116,12 @@ func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re metrics.ProjectTTLSecondsRemaining.WithLabelValues(project.Name).Set(0) metrics.ProjectExpired.WithLabelValues(project.Name).Set(0) } + metrics.ProjectCreationTime.WithLabelValues(project.Name).Set(float64(project.CreationTimestamp.Unix())) } else { metrics.ProjectReconcileErrors.DeleteLabelValues(project.Name) metrics.ProjectTTLSecondsInitial.DeleteLabelValues(project.Name) metrics.ProjectTTLSecondsRemaining.DeleteLabelValues(project.Name) + metrics.ProjectCreationTime.DeleteLabelValues(project.Name) metrics.ProjectExpired.DeleteLabelValues(project.Name) } if skipStatusUpdate { diff --git a/crds/core.cs.sap.com_projects.yaml b/crds/core.cs.sap.com_projects.yaml index 18484fc..a53f588 100644 --- a/crds/core.cs.sap.com_projects.yaml +++ b/crds/core.cs.sap.com_projects.yaml @@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.9.2 - creationTimestamp: null + controller-gen.kubebuilder.io/version: v0.14.0 name: projects.core.cs.sap.com spec: group: core.cs.sap.com @@ -28,14 +27,19 @@ spec: description: Project is the Schema for the projects API. properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources type: string kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds type: string metadata: type: object diff --git a/internal/metrics/project_metrics.go b/internal/metrics/project_metrics.go index a65f8a2..cd263f9 100644 --- a/internal/metrics/project_metrics.go +++ b/internal/metrics/project_metrics.go @@ -33,6 +33,13 @@ var ( }, []string{"project"}, ) + ProjectCreationTime = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "project_creation_time", + Help: "Creation time of the project in epoch seconds. Zero means that the project has not been created yet.", + }, + []string{"project"}, + ) ProjectExpired = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "project_expired", @@ -47,6 +54,7 @@ func init() { ProjectReconcileErrors, ProjectTTLSecondsInitial, ProjectTTLSecondsRemaining, + ProjectCreationTime, ProjectExpired, ) }