From bc207abf45cb2a15ae03ccede0ee9573aa0570c3 Mon Sep 17 00:00:00 2001 From: Raj <54686422+LeelaChacha@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:55:40 +0100 Subject: [PATCH] fix: Revert "feat: Add Manifest Reconcile Duration Metric (#1321)" (#1359) Revert "feat: Add Manifest Reconcile Duration Metric (#1321)" This reverts commit 2b64c7b77d8b58cbc4ce340aef8eb0068dbbd190. --- internal/declarative/v2/reconciler.go | 4 --- internal/pkg/metrics/manifest.go | 36 ++------------------------- pkg/testutils/metrics.go | 28 ++++++--------------- tests/e2e/kyma_metrics_test.go | 10 -------- 4 files changed, 10 insertions(+), 68 deletions(-) diff --git a/internal/declarative/v2/reconciler.go b/internal/declarative/v2/reconciler.go index 75a2ecd321..74ba1227e4 100644 --- a/internal/declarative/v2/reconciler.go +++ b/internal/declarative/v2/reconciler.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "time" apicorev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" @@ -93,9 +92,6 @@ func newResourcesCondition(obj Object) apimetav1.Condition { //nolint:funlen,cyclop,gocognit // Declarative pkg will be removed soon func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - reconcileStart := time.Now() - defer r.Metrics.ObserveReconcileDuration(reconcileStart, req.NamespacedName.Name) - obj, ok := r.prototype.DeepCopyObject().(Object) if !ok { r.Metrics.RecordRequeueReason(metrics.ManifestTypeCast, queue.UnexpectedRequeue) diff --git a/internal/pkg/metrics/manifest.go b/internal/pkg/metrics/manifest.go index 41550b8567..f2563dd153 100644 --- a/internal/pkg/metrics/manifest.go +++ b/internal/pkg/metrics/manifest.go @@ -1,19 +1,10 @@ package metrics -import ( - "time" - - "github.com/prometheus/client_golang/prometheus" - ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics" - - "github.com/kyma-project/lifecycle-manager/pkg/queue" -) +import "github.com/kyma-project/lifecycle-manager/pkg/queue" type ManifestRequeueReason string const ( - MetricReconcileDuration string = "reconcile_duration_seconds" - MetricLabelModule string = "module_name" ManifestTypeCast ManifestRequeueReason = "manifest_type_cast" ManifestRetrieval ManifestRequeueReason = "manifest_retrieval" ManifestInit ManifestRequeueReason = "manifest_initialize" @@ -37,35 +28,12 @@ const ( type ManifestMetrics struct { *SharedMetrics - reconcileDurationHistogram *prometheus.HistogramVec } func NewManifestMetrics(sharedMetrics *SharedMetrics) *ManifestMetrics { - metrics := &ManifestMetrics{ - SharedMetrics: sharedMetrics, - reconcileDurationHistogram: prometheus.NewHistogramVec( - prometheus.HistogramOpts{ - Name: MetricReconcileDuration, - Help: "Histogram of reconcile duration for manifest reconciliation in seconds", - Buckets: []float64{ - 0.005, 0.01, 0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, - 0.7, 0.8, 0.9, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5, 6, 7, 8, 9, 10, 15, 20, - 25, 30, 40, 50, 60, - }, - }, - []string{MetricLabelModule}, - ), - } - ctrlmetrics.Registry.MustRegister(metrics.reconcileDurationHistogram) - return metrics + return &ManifestMetrics{SharedMetrics: sharedMetrics} } func (k *ManifestMetrics) RecordRequeueReason(requeueReason ManifestRequeueReason, requeueType queue.RequeueType) { k.requeueReasonCounter.WithLabelValues(string(requeueReason), string(requeueType)).Inc() } - -func (k *ManifestMetrics) ObserveReconcileDuration(reconcileStart time.Time, moduleName string) { - durationInSeconds := time.Since(reconcileStart).Seconds() - k.reconcileDurationHistogram.WithLabelValues(moduleName). - Observe(durationInSeconds) -} diff --git a/pkg/testutils/metrics.go b/pkg/testutils/metrics.go index 7c89ced147..43b077bfef 100644 --- a/pkg/testutils/metrics.go +++ b/pkg/testutils/metrics.go @@ -12,8 +12,6 @@ import ( "github.com/kyma-project/lifecycle-manager/internal/pkg/metrics" ) -const reMatchCount = `"} (\d+)` - var ErrMetricNotFound = errors.New("metric was not found") func GetKymaStateMetricCount(ctx context.Context, kymaName, state string) (int, error) { @@ -29,7 +27,8 @@ func GetKymaStateMetricCount(ctx context.Context, kymaName, state string) (int, func getKymaStateMetricRegex(kymaName, state string) *regexp.Regexp { return regexp.MustCompile( metrics.MetricKymaState + `{instance_id="[^"]+",kyma_name="` + kymaName + - `",shoot="[^"]+",state="` + state + reMatchCount) + `",shoot="[^"]+",state="` + state + + `"} (\d+)`) } func AssertKymaStateMetricNotFound(ctx context.Context, kymaName, state string) error { @@ -56,7 +55,8 @@ func GetRequeueReasonCount(ctx context.Context, } re := regexp.MustCompile( metrics.MetricRequeueReason + `{requeue_reason="` + requeueReason + - `",requeue_type="` + requeueType + reMatchCount) + `",requeue_type="` + requeueType + + `"}` + ` (\d+)`) return parseCount(re, bodyString) } @@ -69,25 +69,12 @@ func IsManifestRequeueReasonCountIncreased(ctx context.Context, requeueReason, r } re := regexp.MustCompile( metrics.MetricRequeueReason + `{requeue_reason="` + requeueReason + - `",requeue_type="` + requeueType + reMatchCount) + `",requeue_type="` + requeueType + + `"}` + ` (\d+)`) count, err := parseCount(re, bodyString) return count >= 1, err } -func IsManifestReconcileDurationCountNonZero(ctx context.Context, manifestName string) (bool, - error, -) { - bodyString, err := getMetricsBody(ctx) - if err != nil { - return false, err - } - re := regexp.MustCompile( - metrics.MetricReconcileDuration + `_count{` + metrics.MetricLabelModule + - `="` + manifestName + reMatchCount) - count, err := parseCount(re, bodyString) - return count > 0, err -} - func GetModuleStateMetricCount(ctx context.Context, kymaName, moduleName, state string) (int, error) { bodyString, err := getMetricsBody(ctx) if err != nil { @@ -96,7 +83,8 @@ func GetModuleStateMetricCount(ctx context.Context, kymaName, moduleName, state re := regexp.MustCompile( metrics.MetricModuleState + `{instance_id="[^"]+",kyma_name="` + kymaName + `",module_name="` + moduleName + - `",shoot="[^"]+",state="` + state + reMatchCount) + `",shoot="[^"]+",state="` + state + + `"} (\d+)`) return parseCount(re, bodyString) } diff --git a/tests/e2e/kyma_metrics_test.go b/tests/e2e/kyma_metrics_test.go index 4cc26f4ad3..ee6beaf399 100644 --- a/tests/e2e/kyma_metrics_test.go +++ b/tests/e2e/kyma_metrics_test.go @@ -61,16 +61,6 @@ var _ = Describe("Manage Module Metrics", Ordered, func() { Should(BeTrue()) }) - It("Then Related Manifest Duration Metric Is Non Zero", func() { - manifest, err := GetManifest(ctx, controlPlaneClient, kyma.GetName(), kyma.GetNamespace(), module.Name) - Expect(err).ToNot(HaveOccurred()) - - Eventually(IsManifestReconcileDurationCountNonZero). - WithContext(ctx). - WithArguments(manifest.Name). - Should(BeTrue()) - }) - It("When Kyma Module is disabled", func() { Eventually(DisableModule). WithContext(ctx).