Skip to content

Commit

Permalink
applying mpas specific labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Dec 19, 2023
1 parent 033f7c4 commit 65b7c1e
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resources:
- ../rbac
- ../manager
- ../registry
#- ../prometheus
- namespace.yaml
transformers:
- labels.yaml
Expand Down
5 changes: 5 additions & 0 deletions controllers/componentversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions controllers/configuration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions controllers/fluxdeployer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions controllers/localization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
19 changes: 19 additions & 0 deletions controllers/mpas_owned.go
Original file line number Diff line number Diff line change
@@ -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 ""
}
5 changes: 5 additions & 0 deletions controllers/resource_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
54 changes: 49 additions & 5 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ func init() {
SnapshotNumberOfBytesReconciled,
SnapshotReconcileSuccess,
SnapshotReconcileFailed,
MPASProductReconciledStatus,
MPASComponentVersionReconciledStatus,
MPASLocationReconciledStatus,
MPASConfigurationReconciledStatus,
MPASDeployerReconciledStatus,
MPASResourceReconciledStatus,
)
}

Expand Down Expand Up @@ -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,
)

0 comments on commit 65b7c1e

Please sign in to comment.