diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 45f5281b..d6fe6579 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -6,6 +6,7 @@ resources: - ../rbac - ../manager - ../registry +#- ../prometheus - namespace.yaml transformers: - labels.yaml diff --git a/controllers/componentversion_controller.go b/controllers/componentversion_controller.go index e6418849..d6817ff6 100644 --- a/controllers/componentversion_controller.go +++ b/controllers/componentversion_controller.go @@ -36,6 +36,7 @@ import ( "github.com/open-component-model/ocm/pkg/contexts/ocm" ocmdesc "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" compdesc "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1" + mh "github.com/open-component-model/pkg/metrics" "github.com/open-component-model/ocm-controller/api/v1alpha1" "github.com/open-component-model/ocm-controller/pkg/component" @@ -363,6 +364,10 @@ func (r *ComponentVersionReconciler) reconcile( metrics.ComponentVersionReconciledTotal.WithLabelValues(cv.GetName(), cv.GetVersion()).Inc() + if product := IsProductOwned(obj); product != "" { + metrics.MPASComponentVersionReconciledStatus.WithLabelValues(product, mh.MPASStatusSuccess).Inc() + } + status.MarkReady(r.EventRecorder, obj, "Applied version: %s", version) return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil diff --git a/controllers/configuration_controller.go b/controllers/configuration_controller.go index d40b7594..de4efedf 100644 --- a/controllers/configuration_controller.go +++ b/controllers/configuration_controller.go @@ -18,6 +18,7 @@ import ( sourcev1 "github.com/fluxcd/source-controller/api/v1" "github.com/open-component-model/ocm-controller/pkg/metrics" "github.com/open-component-model/ocm-controller/pkg/status" + mh "github.com/open-component-model/pkg/metrics" "golang.org/x/exp/slices" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -334,6 +335,10 @@ func (r *ConfigurationReconciler) reconcile( metrics.SnapshotNumberOfBytesReconciled.WithLabelValues(obj.GetSnapshotName(), obj.GetSnapshotDigest(), obj.Spec.SourceRef.Name).Set(float64(size)) metrics.ConfigurationReconcileSuccess.WithLabelValues(obj.Name).Inc() + if product := IsProductOwned(obj); product != "" { + metrics.MPASConfigurationReconciledStatus.WithLabelValues(product, mh.MPASStatusSuccess).Inc() + } + return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil } diff --git a/controllers/fluxdeployer_controller.go b/controllers/fluxdeployer_controller.go index 2a2d22a7..036937d9 100644 --- a/controllers/fluxdeployer_controller.go +++ b/controllers/fluxdeployer_controller.go @@ -12,7 +12,9 @@ import ( "time" helmv1 "github.com/fluxcd/helm-controller/api/v2beta1" + "github.com/open-component-model/ocm-controller/pkg/metrics" "github.com/open-component-model/ocm-controller/pkg/status" + mh "github.com/open-component-model/pkg/metrics" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -218,6 +220,10 @@ func (r *FluxDeployerReconciler) reconcile( msg := fmt.Sprintf("FluxDeployer '%s' is ready", obj.Name) status.MarkReady(r.EventRecorder, obj, msg) + if product := IsProductOwned(obj); product != "" { + metrics.MPASDeployerReconciledStatus.WithLabelValues(product, mh.MPASStatusSuccess).Inc() + } + return ctrl.Result{}, nil } diff --git a/controllers/localization_controller.go b/controllers/localization_controller.go index d084a9e2..855b3f0b 100644 --- a/controllers/localization_controller.go +++ b/controllers/localization_controller.go @@ -19,6 +19,7 @@ import ( "github.com/fluxcd/source-controller/api/v1beta2" "github.com/open-component-model/ocm-controller/pkg/metrics" "github.com/open-component-model/ocm-controller/pkg/status" + mh "github.com/open-component-model/pkg/metrics" "golang.org/x/exp/slices" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -311,6 +312,10 @@ func (r *LocalizationReconciler) reconcile( metrics.SnapshotNumberOfBytesReconciled.WithLabelValues(obj.GetSnapshotName(), obj.GetSnapshotDigest(), obj.Spec.SourceRef.Name).Set(float64(size)) metrics.LocalizationReconcileSuccess.WithLabelValues(obj.Name).Inc() + if product := IsProductOwned(obj); product != "" { + metrics.MPASLocationReconciledStatus.WithLabelValues(product, mh.MPASStatusSuccess).Inc() + } + return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil } diff --git a/controllers/mpas_owned.go b/controllers/mpas_owned.go new file mode 100644 index 00000000..574caaa8 --- /dev/null +++ b/controllers/mpas_owned.go @@ -0,0 +1,19 @@ +package controllers + +import ( + "sigs.k8s.io/controller-runtime/pkg/client" +) + +const productDeploymentKind = "ProductDeployment" + +// IsProductOwned determines if a given Kubernetes objects has a ProductDeployment owner. +// Used to determine if certain metrics labels need to be updated. +func IsProductOwned(obj client.Object) string { + for _, ref := range obj.GetOwnerReferences() { + if ref.Kind == productDeploymentKind { + return ref.Name + } + } + + return "" +} diff --git a/controllers/resource_controller.go b/controllers/resource_controller.go index ac57d7ee..1d5084fc 100644 --- a/controllers/resource_controller.go +++ b/controllers/resource_controller.go @@ -21,6 +21,7 @@ import ( "github.com/open-component-model/ocm-controller/pkg/snapshot" "github.com/open-component-model/ocm-controller/pkg/status" ocmmetav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1" + mh "github.com/open-component-model/pkg/metrics" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -275,6 +276,10 @@ func (r *ResourceReconciler) reconcile( metrics.SnapshotNumberOfBytesReconciled.WithLabelValues(obj.GetSnapshotName(), digest, componentVersion.Name).Set(float64(size)) metrics.ResourceReconcileSuccess.WithLabelValues(obj.Name).Inc() + if product := IsProductOwned(obj); product != "" { + metrics.MPASResourceReconciledStatus.WithLabelValues(product, mh.MPASStatusSuccess).Inc() + } + status.MarkReady(r.EventRecorder, obj, "Applied version: %s", obj.Status.LastAppliedComponentVersion) return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil diff --git a/go.mod b/go.mod index 41d2d4f6..17893c48 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/onsi/gomega v1.30.0 github.com/open-component-model/ocm v0.4.0 github.com/open-component-model/ocm-e2e-framework v0.6.1-0.20230913082321-d7050cc55939 - github.com/open-component-model/pkg/metrics v0.0.0-20231218095050-514b73c0703c + github.com/open-component-model/pkg/metrics v0.0.0-20231219114945-b36ef69e88e8 github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/image-spec v1.1.0-rc5 github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 diff --git a/go.sum b/go.sum index 963f975b..f0d532fa 100644 --- a/go.sum +++ b/go.sum @@ -1652,8 +1652,8 @@ github.com/open-component-model/ocm v0.4.0 h1:S+rPJGoDnSvxhBn3QS2HXURxugTjCM4XWE github.com/open-component-model/ocm v0.4.0/go.mod h1:7RAqaUMmA4BlwW5ZEUBm8amWIb1TL9FhNigNXQ6wiu0= github.com/open-component-model/ocm-e2e-framework v0.6.1-0.20230913082321-d7050cc55939 h1:OnT3xCv7bqu5oFt701occb9dYYa1ow3YhI7A5zu055A= github.com/open-component-model/ocm-e2e-framework v0.6.1-0.20230913082321-d7050cc55939/go.mod h1:+JNqNksMIH03PxJ1LyEFbr+tYD2JZtpNMgumE3Gq1hg= -github.com/open-component-model/pkg/metrics v0.0.0-20231218095050-514b73c0703c h1:65oCzphTR71kLe8l7zSVF7B9uZVS85ad9LnQa1UmnxE= -github.com/open-component-model/pkg/metrics v0.0.0-20231218095050-514b73c0703c/go.mod h1:80SzqzaWEpRC0NE8wks/QAV+QxUrpKIhpk6r0s8qBTQ= +github.com/open-component-model/pkg/metrics v0.0.0-20231219114945-b36ef69e88e8 h1:ETxVHo2yvsi/78EINZLEkmXeBnkBpPhBbCV8QzR8758= +github.com/open-component-model/pkg/metrics v0.0.0-20231219114945-b36ef69e88e8/go.mod h1:80SzqzaWEpRC0NE8wks/QAV+QxUrpKIhpk6r0s8qBTQ= github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be h1:f2PlhC9pm5sqpBZFvnAoKj+KzXRzbjFMA+TqXfJdgho= github.com/opencontainers/go-digest v1.0.1-0.20220411205349-bde1400a84be/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/go-digest/blake3 v0.0.0-20230815154656-802ce17c4f59 h1:PHIYPK2sf+Wfnsy6Sj8oHjLmPpbybrYBjxzSZckHjDQ= diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index b2686fc2..970d5ad1 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -27,7 +27,11 @@ func init() { SnapshotNumberOfBytesReconciled, SnapshotReconcileSuccess, SnapshotReconcileFailed, - MPASProductReconciledStatus, + MPASComponentVersionReconciledStatus, + MPASLocationReconciledStatus, + MPASConfigurationReconciledStatus, + MPASDeployerReconciledStatus, + MPASResourceReconciledStatus, ) } @@ -141,12 +145,52 @@ var SnapshotNumberOfBytesReconciled = mh.MustRegisterGaugeVec( "snapshot", "digest", "component", ) -// MPASProductReconciledStatus updates the status of an MPAS product component. +// MPASComponentVersionReconciledStatus updates the status of an MPAS component version. // [product, status]. -var MPASProductReconciledStatus = mh.MustRegisterCounterVec( +var MPASComponentVersionReconciledStatus = mh.MustRegisterCounterVec( "mpas_system", metricsComponent, - mh.MPASProductInstallationCounterLabel, + mh.MPASProductComponentVersionCounterLabel, "The status of an mpas product.", - "product", "status", + "product", mh.MPASProductInstallationCounterStatusLabel, +) + +// MPASLocationReconciledStatus updates the status of an MPAS component version. +// [product, status]. +var MPASLocationReconciledStatus = mh.MustRegisterCounterVec( + "mpas_system", + metricsComponent, + mh.MPASProductLocalizationCounterLabel, + "The status of an mpas product.", + "product", mh.MPASProductInstallationCounterStatusLabel, +) + +// MPASConfigurationReconciledStatus updates the status of an MPAS component version. +// [product, status]. +var MPASConfigurationReconciledStatus = mh.MustRegisterCounterVec( + "mpas_system", + metricsComponent, + mh.MPASProductConfigurationCounterLabel, + "The status of an mpas product.", + "product", mh.MPASProductInstallationCounterStatusLabel, +) + +// MPASDeployerReconciledStatus updates the status of an MPAS component version. +// [product, status]. +var MPASDeployerReconciledStatus = mh.MustRegisterCounterVec( + "mpas_system", + metricsComponent, + mh.MPASProductDeployerCounterLabel, + "The status of an mpas product.", + "product", mh.MPASProductInstallationCounterStatusLabel, +) + +// MPASResourceReconciledStatus updates the status of an MPAS component version. +// [product, status]. +var MPASResourceReconciledStatus = mh.MustRegisterCounterVec( + "mpas_system", + metricsComponent, + mh.MPASProductResourceCounterLabel, + "The status of an mpas product.", + "product", mh.MPASProductInstallationCounterStatusLabel, )