From 1c43c299524fbaf3eb02504b76fb5183fa129ef1 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 20 Oct 2022 14:26:24 +0200 Subject: [PATCH 1/5] feat(operator): Use Async Gauges for active KLC Entities Signed-off-by: Florian Bacher --- operator/api/v1alpha1/common/common.go | 30 +++-- .../controllers/keptnappversion/controller.go | 27 +++- .../controllers/keptnevaluation/controller.go | 27 +++- operator/controllers/keptntask/controller.go | 27 +++- .../keptnworkloadinstance/controller.go | 27 +++- operator/main.go | 119 +++++++++++++----- 6 files changed, 199 insertions(+), 58 deletions(-) diff --git a/operator/api/v1alpha1/common/common.go b/operator/api/v1alpha1/common/common.go index 72cce82d25..b7492a1086 100644 --- a/operator/api/v1alpha1/common/common.go +++ b/operator/api/v1alpha1/common/common.go @@ -2,6 +2,7 @@ package common import ( "fmt" + "go.opentelemetry.io/otel/metric/instrument/asyncint64" "math/rand" "go.opentelemetry.io/otel/attribute" @@ -111,18 +112,18 @@ const PreDeploymentEvaluationCheckType CheckType = "pre-eval" const PostDeploymentEvaluationCheckType CheckType = "post-eval" type KeptnMeters struct { - TaskCount syncint64.Counter - TaskDuration syncfloat64.Histogram - TaskActive syncint64.UpDownCounter - DeploymentCount syncint64.Counter - DeploymentDuration syncfloat64.Histogram - DeploymentActive syncint64.UpDownCounter - AppCount syncint64.Counter - AppDuration syncfloat64.Histogram - AppActive syncint64.UpDownCounter - EvaluationCount syncint64.Counter - EvaluationDuration syncfloat64.Histogram - EvaluationActive syncint64.UpDownCounter + TaskCount syncint64.Counter + TaskDuration syncfloat64.Histogram + TaskActive asyncint64.Gauge + DeploymentCount syncint64.Counter + DeploymentDuration syncfloat64.Histogram + DeploymentActiveGauge asyncint64.Gauge + AppCount syncint64.Counter + AppDuration syncfloat64.Histogram + AppActive asyncint64.Gauge + EvaluationCount syncint64.Counter + EvaluationDuration syncfloat64.Histogram + EvaluationActive asyncint64.Gauge } const ( @@ -151,3 +152,8 @@ func GenerateEvaluationName(checkType CheckType, evalName string) string { randomId := rand.Intn(99_999-10_000) + 10000 return fmt.Sprintf("%s-%s-%d", checkType, TruncateString(evalName, 27), randomId) } + +type GaugeValue struct { + Value int64 + Attributes []attribute.KeyValue +} diff --git a/operator/controllers/keptnappversion/controller.go b/operator/controllers/keptnappversion/controller.go index 998d1ba9fb..a3812fde60 100644 --- a/operator/controllers/keptnappversion/controller.go +++ b/operator/controllers/keptnappversion/controller.go @@ -81,8 +81,6 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ } if !appVersion.IsStartTimeSet() { - // metrics: increment active app counter - r.Meters.AppActive.Add(ctx, 1, appVersion.GetActiveMetricsAttributes()...) appVersion.SetStartTime() } @@ -145,8 +143,6 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ // AppVersion is completed at this place if !appVersion.IsEndTimeSet() { - // metrics: decrement active app counter - r.Meters.AppActive.Add(ctx, -1, appVersion.GetActiveMetricsAttributes()...) appVersion.Status.CurrentPhase = common.PhaseCompleted.ShortName appVersion.SetEndTime() } @@ -207,3 +203,26 @@ func (r *KeptnAppVersionReconciler) handlePhase(ctx context.Context, appVersion } return ctrl.Result{Requeue: true, RequeueAfter: 5 * time.Second}, nil } + +func (r *KeptnAppVersionReconciler) GetActiveApps(ctx context.Context) ([]common.GaugeValue, error) { + appInstances := &klcv1alpha1.KeptnAppVersionList{} + err := r.List(ctx, appInstances) + if err != nil { + return nil, fmt.Errorf("could not retrieve app versions: %w", err) + } + + res := []common.GaugeValue{} + + for _, appInstance := range appInstances.Items { + gaugeValue := int64(0) + if !appInstance.IsEndTimeSet() { + gaugeValue = int64(1) + } + res = append(res, common.GaugeValue{ + Value: gaugeValue, + Attributes: appInstance.GetActiveMetricsAttributes(), + }) + } + + return res, nil +} diff --git a/operator/controllers/keptnevaluation/controller.go b/operator/controllers/keptnevaluation/controller.go index 5a826f0d87..11cde8ca16 100644 --- a/operator/controllers/keptnevaluation/controller.go +++ b/operator/controllers/keptnevaluation/controller.go @@ -95,8 +95,6 @@ func (r *KeptnEvaluationReconciler) Reconcile(ctx context.Context, req ctrl.Requ semconv.AddAttributeFromEvaluation(span, *evaluation) if !evaluation.IsStartTimeSet() { - // metrics: increment active evaluation counter - r.Meters.EvaluationActive.Add(ctx, 1, evaluation.GetActiveMetricsAttributes()...) evaluation.SetStartTime() } @@ -183,8 +181,6 @@ func (r *KeptnEvaluationReconciler) updateFinishedEvaluationMetrics(ctx context. r.recordEvent("Normal", evaluation, string(evaluation.Status.OverallStatus), "the evaluation has "+string(evaluation.Status.OverallStatus)) if !evaluation.IsEndTimeSet() { - // metrics: decrement active evaluation counter - r.Meters.EvaluationActive.Add(ctx, -1, evaluation.GetActiveMetricsAttributes()...) evaluation.SetEndTime() } @@ -329,3 +325,26 @@ func (r *KeptnEvaluationReconciler) checkValue(objective klcv1alpha1.Objective, func (r *KeptnEvaluationReconciler) recordEvent(eventType string, evaluation *klcv1alpha1.KeptnEvaluation, shortReason string, longReason string) { r.Recorder.Event(evaluation, eventType, shortReason, fmt.Sprintf("%s / Namespace: %s, Name: %s, WorkloadVersion: %s ", longReason, evaluation.Namespace, evaluation.Name, evaluation.Spec.WorkloadVersion)) } + +func (r *KeptnEvaluationReconciler) GetActiveEvaluations(ctx context.Context) ([]common.GaugeValue, error) { + evaluations := &klcv1alpha1.KeptnEvaluationList{} + err := r.List(ctx, evaluations) + if err != nil { + return nil, fmt.Errorf("could not retrieve workload instances: %w", err) + } + + res := []common.GaugeValue{} + + for _, evaluation := range evaluations.Items { + gaugeValue := int64(0) + if !evaluation.IsEndTimeSet() { + gaugeValue = int64(1) + } + res = append(res, common.GaugeValue{ + Value: gaugeValue, + Attributes: evaluation.GetActiveMetricsAttributes(), + }) + } + + return res, nil +} diff --git a/operator/controllers/keptntask/controller.go b/operator/controllers/keptntask/controller.go index 07d56efa90..698e38cf5a 100644 --- a/operator/controllers/keptntask/controller.go +++ b/operator/controllers/keptntask/controller.go @@ -78,8 +78,6 @@ func (r *KeptnTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( semconv.AddAttributeFromTask(span, *task) if !task.IsStartTimeSet() { - // metrics: increment active task counter - r.Meters.TaskActive.Add(ctx, 1, task.GetActiveMetricsAttributes()...) task.SetStartTime() } @@ -119,8 +117,6 @@ func (r *KeptnTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( // Task is completed at this place if !task.IsEndTimeSet() { - // metrics: decrement active task counter - r.Meters.TaskActive.Add(ctx, -1, task.GetActiveMetricsAttributes()...) task.SetEndTime() } @@ -175,3 +171,26 @@ func (r *KeptnTaskReconciler) JobExists(ctx context.Context, task klcv1alpha1.Ke return false, nil } + +func (r *KeptnTaskReconciler) GetActiveTasks(ctx context.Context) ([]common.GaugeValue, error) { + tasks := &klcv1alpha1.KeptnTaskList{} + err := r.List(ctx, tasks) + if err != nil { + return nil, fmt.Errorf("could not retrieve workload instances: %w", err) + } + + res := []common.GaugeValue{} + + for _, task := range tasks.Items { + gaugeValue := int64(0) + if !task.IsEndTimeSet() { + gaugeValue = int64(1) + } + res = append(res, common.GaugeValue{ + Value: gaugeValue, + Attributes: task.GetActiveMetricsAttributes(), + }) + } + + return res, nil +} diff --git a/operator/controllers/keptnworkloadinstance/controller.go b/operator/controllers/keptnworkloadinstance/controller.go index 5ac02cc5b6..c6dafc2bf4 100644 --- a/operator/controllers/keptnworkloadinstance/controller.go +++ b/operator/controllers/keptnworkloadinstance/controller.go @@ -97,8 +97,6 @@ func (r *KeptnWorkloadInstanceReconciler) Reconcile(ctx context.Context, req ctr semconv.AddAttributeFromWorkloadInstance(span, *workloadInstance) if !workloadInstance.IsStartTimeSet() { - // metrics: increment active deployment counter - r.Meters.DeploymentActive.Add(ctx, 1, workloadInstance.GetActiveMetricsAttributes()...) workloadInstance.SetStartTime() } @@ -173,8 +171,6 @@ func (r *KeptnWorkloadInstanceReconciler) Reconcile(ctx context.Context, req ctr // WorkloadInstance is completed at this place if !workloadInstance.IsEndTimeSet() { - // metrics: decrement active deployment counter - r.Meters.DeploymentActive.Add(ctx, -1, workloadInstance.GetActiveMetricsAttributes()...) workloadInstance.Status.CurrentPhase = common.PhaseCompleted.ShortName workloadInstance.SetEndTime() } @@ -200,6 +196,29 @@ func (r *KeptnWorkloadInstanceReconciler) Reconcile(ctx context.Context, req ctr return ctrl.Result{}, nil } +func (r *KeptnWorkloadInstanceReconciler) GetActiveDeployments(ctx context.Context) ([]common.GaugeValue, error) { + workloadInstances := &klcv1alpha1.KeptnWorkloadInstanceList{} + err := r.List(ctx, workloadInstances) + if err != nil { + return nil, fmt.Errorf("could not retrieve workload instances: %w", err) + } + + res := []common.GaugeValue{} + + for _, workloadInstance := range workloadInstances.Items { + gaugeValue := int64(0) + if !workloadInstance.IsEndTimeSet() { + gaugeValue = int64(1) + } + res = append(res, common.GaugeValue{ + Value: gaugeValue, + Attributes: workloadInstance.GetActiveMetricsAttributes(), + }) + } + + return res, nil +} + func (r *KeptnWorkloadInstanceReconciler) handlePhase(ctx context.Context, workloadInstance *klcv1alpha1.KeptnWorkloadInstance, phase common.KeptnPhaseType, span trace.Span, phaseFailed func() bool, reconcilePhase func() (common.KeptnState, error)) (ctrl.Result, error) { r.Log.Info(phase.LongName + " not finished") oldPhase := workloadInstance.Status.CurrentPhase diff --git a/operator/main.go b/operator/main.go index 70bdc039cf..7612c9e5dd 100644 --- a/operator/main.go +++ b/operator/main.go @@ -123,7 +123,7 @@ func main() { if err != nil { setupLog.Error(err, "unable to start OTel") } - deploymentActive, err := meter.SyncInt64().UpDownCounter("keptn.deployment.active", instrument.WithDescription("a simple counter of active deployments for Keptn deployment")) + deploymentActiveGauge, err := meter.AsyncInt64().Gauge("keptn.deployment.active", instrument.WithDescription("a gauge keeping track of the currently active tasks for a Keptn deployment")) if err != nil { setupLog.Error(err, "unable to start OTel") } @@ -135,7 +135,7 @@ func main() { if err != nil { setupLog.Error(err, "unable to start OTel") } - taskActive, err := meter.SyncInt64().UpDownCounter("keptn.task.active", instrument.WithDescription("a simple counter of active tasks for Keptn tasks")) + taskActiveGauge, err := meter.AsyncInt64().Gauge("keptn.task.active", instrument.WithDescription("a simple counter of active Keptn tasks")) if err != nil { setupLog.Error(err, "unable to start OTel") } @@ -147,7 +147,7 @@ func main() { if err != nil { setupLog.Error(err, "unable to start OTel") } - appActive, err := meter.SyncInt64().UpDownCounter("keptn.app.active", instrument.WithDescription("a simple counter of active apps for Keptn apps")) + appActiveGauge, err := meter.AsyncInt64().Gauge("keptn.app.active", instrument.WithDescription("a simple counter of active apps for Keptn apps")) if err != nil { setupLog.Error(err, "unable to start OTel") } @@ -159,24 +159,24 @@ func main() { if err != nil { setupLog.Error(err, "unable to start OTel") } - evaluationActive, err := meter.SyncInt64().UpDownCounter("keptn.evaluation.active", instrument.WithDescription("a simple counter of active apps for Keptn evaluation for Evaluations")) + evaluationActiveGauge, err := meter.AsyncInt64().Gauge("keptn.evaluation.active", instrument.WithDescription("a simple counter of active apps for Keptn evaluation for Evaluations")) if err != nil { setupLog.Error(err, "unable to start OTel") } meters := common.KeptnMeters{ - TaskCount: taskCount, - TaskDuration: taskDuration, - TaskActive: taskActive, - DeploymentCount: deploymentCount, - DeploymentDuration: deploymentDuration, - DeploymentActive: deploymentActive, - AppCount: appCount, - AppDuration: appDuration, - AppActive: appActive, - EvaluationCount: evaluationCount, - EvaluationDuration: evaluationDuration, - EvaluationActive: evaluationActive, + TaskCount: taskCount, + TaskDuration: taskDuration, + TaskActive: taskActiveGauge, + DeploymentCount: deploymentCount, + DeploymentDuration: deploymentDuration, + DeploymentActiveGauge: deploymentActiveGauge, + AppCount: appCount, + AppDuration: appDuration, + AppActive: appActiveGauge, + EvaluationCount: evaluationCount, + EvaluationDuration: evaluationDuration, + EvaluationActive: evaluationActiveGauge, } // Start the prometheus HTTP server and pass the exporter Collector to it @@ -245,81 +245,140 @@ func main() { Log: ctrl.Log.WithName("Mutating Webhook"), }}) } - if err = (&keptntask.KeptnTaskReconciler{ + taskReconciler := &keptntask.KeptnTaskReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Log: ctrl.Log.WithName("KeptnTask Controller"), Recorder: mgr.GetEventRecorderFor("keptntask-controller"), Meters: meters, Tracer: otel.Tracer("keptn/operator/task"), - }).SetupWithManager(mgr); err != nil { + } + if err = (taskReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnTask") os.Exit(1) } - if err = (&keptntaskdefinition.KeptnTaskDefinitionReconciler{ + + taskDefinitionReconciler := &keptntaskdefinition.KeptnTaskDefinitionReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Log: ctrl.Log.WithName("KeptnTaskDefinition Controller"), Recorder: mgr.GetEventRecorderFor("keptntaskdefinition-controller"), - }).SetupWithManager(mgr); err != nil { + } + if err = (taskDefinitionReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnTaskDefinition") os.Exit(1) } - if err = (&keptnapp.KeptnAppReconciler{ + + appReconciler := &keptnapp.KeptnAppReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Log: ctrl.Log.WithName("KeptnApp Controller"), Recorder: mgr.GetEventRecorderFor("keptnapp-controller"), Tracer: otel.Tracer("keptn/operator/app"), - }).SetupWithManager(mgr); err != nil { + } + if err = (appReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnApp") os.Exit(1) } - if err = (&keptnworkload.KeptnWorkloadReconciler{ + + workloadReconciler := &keptnworkload.KeptnWorkloadReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Log: ctrl.Log.WithName("KeptnWorkload Controller"), Recorder: mgr.GetEventRecorderFor("keptnworkload-controller"), Tracer: otel.Tracer("keptn/operator/workload"), - }).SetupWithManager(mgr); err != nil { + } + if err = (workloadReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnWorkload") os.Exit(1) } - if err = (&keptnworkloadinstance.KeptnWorkloadInstanceReconciler{ + + workloadInstanceReconciler := &keptnworkloadinstance.KeptnWorkloadInstanceReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Log: ctrl.Log.WithName("KeptnWorkloadInstance Controller"), Recorder: mgr.GetEventRecorderFor("keptnworkloadinstance-controller"), Meters: meters, Tracer: otel.Tracer("keptn/operator/workloadinstance"), - }).SetupWithManager(mgr); err != nil { + } + if err = (workloadInstanceReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnWorkloadInstance") os.Exit(1) } - if err = (&keptnappversion.KeptnAppVersionReconciler{ + + appVersionReconciler := &keptnappversion.KeptnAppVersionReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Log: ctrl.Log.WithName("KeptnAppVersion Controller"), Recorder: mgr.GetEventRecorderFor("keptnappversion-controller"), Tracer: otel.Tracer("keptn/operator/appversion"), Meters: meters, - }).SetupWithManager(mgr); err != nil { + } + if err = (appVersionReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnAppVersion") os.Exit(1) } - if err = (&keptnevaluation.KeptnEvaluationReconciler{ + + evaluationReconciler := &keptnevaluation.KeptnEvaluationReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Log: ctrl.Log.WithName("KeptnEvaluation Controller"), Recorder: mgr.GetEventRecorderFor("keptnevaluation-controller"), Tracer: otel.Tracer("keptn/operator/evaluation"), Meters: meters, - }).SetupWithManager(mgr); err != nil { + } + if err = (evaluationReconciler).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "KeptnEvaluation") os.Exit(1) } //+kubebuilder:scaffold:builder + err = meter.RegisterCallback( + []instrument.Asynchronous{ + deploymentActiveGauge, + taskActiveGauge, + appActiveGauge, + evaluationActiveGauge, + }, + func(ctx context.Context) { + activeDeployments, err := workloadInstanceReconciler.GetActiveDeployments(ctx) + if err != nil { + setupLog.Error(err, "unable to gather active deployments") + } + for _, val := range activeDeployments { + deploymentActiveGauge.Observe(ctx, val.Value, val.Attributes...) + } + + activeApps, err := appVersionReconciler.GetActiveApps(ctx) + if err != nil { + setupLog.Error(err, "unable to gather active apps") + } + for _, val := range activeApps { + appActiveGauge.Observe(ctx, val.Value, val.Attributes...) + } + + activeTasks, err := taskReconciler.GetActiveTasks(ctx) + if err != nil { + setupLog.Error(err, "unable to gather active tasks") + } + for _, val := range activeTasks { + taskActiveGauge.Observe(ctx, val.Value, val.Attributes...) + } + + activeEvaluations, err := evaluationReconciler.GetActiveEvaluations(ctx) + if err != nil { + setupLog.Error(err, "unable to gather active evaluations") + } + for _, val := range activeEvaluations { + evaluationActiveGauge.Observe(ctx, val.Value, val.Attributes...) + } + + }) + if err != nil { + fmt.Println("Failed to register callback") + panic(err) + } + if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { setupLog.Error(err, "unable to set up health check") os.Exit(1) From f2a7dba4bf7260b66eb5cfde110b984908b33400 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 20 Oct 2022 14:44:43 +0200 Subject: [PATCH 2/5] remove gauge metrics from central metrics object Signed-off-by: Florian Bacher --- operator/api/v1alpha1/common/common.go | 21 ++++++++------------- operator/main.go | 20 ++++++++------------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/operator/api/v1alpha1/common/common.go b/operator/api/v1alpha1/common/common.go index b7492a1086..1c9436a51a 100644 --- a/operator/api/v1alpha1/common/common.go +++ b/operator/api/v1alpha1/common/common.go @@ -2,7 +2,6 @@ package common import ( "fmt" - "go.opentelemetry.io/otel/metric/instrument/asyncint64" "math/rand" "go.opentelemetry.io/otel/attribute" @@ -112,18 +111,14 @@ const PreDeploymentEvaluationCheckType CheckType = "pre-eval" const PostDeploymentEvaluationCheckType CheckType = "post-eval" type KeptnMeters struct { - TaskCount syncint64.Counter - TaskDuration syncfloat64.Histogram - TaskActive asyncint64.Gauge - DeploymentCount syncint64.Counter - DeploymentDuration syncfloat64.Histogram - DeploymentActiveGauge asyncint64.Gauge - AppCount syncint64.Counter - AppDuration syncfloat64.Histogram - AppActive asyncint64.Gauge - EvaluationCount syncint64.Counter - EvaluationDuration syncfloat64.Histogram - EvaluationActive asyncint64.Gauge + TaskCount syncint64.Counter + TaskDuration syncfloat64.Histogram + DeploymentCount syncint64.Counter + DeploymentDuration syncfloat64.Histogram + AppCount syncint64.Counter + AppDuration syncfloat64.Histogram + EvaluationCount syncint64.Counter + EvaluationDuration syncfloat64.Histogram } const ( diff --git a/operator/main.go b/operator/main.go index 7612c9e5dd..603706b1bc 100644 --- a/operator/main.go +++ b/operator/main.go @@ -165,18 +165,14 @@ func main() { } meters := common.KeptnMeters{ - TaskCount: taskCount, - TaskDuration: taskDuration, - TaskActive: taskActiveGauge, - DeploymentCount: deploymentCount, - DeploymentDuration: deploymentDuration, - DeploymentActiveGauge: deploymentActiveGauge, - AppCount: appCount, - AppDuration: appDuration, - AppActive: appActiveGauge, - EvaluationCount: evaluationCount, - EvaluationDuration: evaluationDuration, - EvaluationActive: evaluationActiveGauge, + TaskCount: taskCount, + TaskDuration: taskDuration, + DeploymentCount: deploymentCount, + DeploymentDuration: deploymentDuration, + AppCount: appCount, + AppDuration: appDuration, + EvaluationCount: evaluationCount, + EvaluationDuration: evaluationDuration, } // Start the prometheus HTTP server and pass the exporter Collector to it From 2f29775bc8ea79c58312e9b6e66c45c98d8c9804 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 20 Oct 2022 15:29:39 +0200 Subject: [PATCH 3/5] adapt metrics descriptions Signed-off-by: Florian Bacher --- operator/main.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/operator/main.go b/operator/main.go index 603706b1bc..cac3f8e1c6 100644 --- a/operator/main.go +++ b/operator/main.go @@ -115,51 +115,51 @@ func main() { exporter := otelprom.New() provider := metric.NewMeterProvider(metric.WithReader(exporter)) meter := provider.Meter("keptn/task") - deploymentCount, err := meter.SyncInt64().Counter("keptn.deployment.count", instrument.WithDescription("a simple counter for Keptn deployment")) + deploymentCount, err := meter.SyncInt64().Counter("keptn.deployment.count", instrument.WithDescription("a simple counter for Keptn Deployments")) if err != nil { setupLog.Error(err, "unable to start OTel") } - deploymentDuration, err := meter.SyncFloat64().Histogram("keptn.deployment.duration", instrument.WithDescription("a histogram of duration for Keptn deployment"), instrument.WithUnit(unit.Unit("s"))) + deploymentDuration, err := meter.SyncFloat64().Histogram("keptn.deployment.duration", instrument.WithDescription("a histogram of duration for Keptn Deployments"), instrument.WithUnit(unit.Unit("s"))) if err != nil { setupLog.Error(err, "unable to start OTel") } - deploymentActiveGauge, err := meter.AsyncInt64().Gauge("keptn.deployment.active", instrument.WithDescription("a gauge keeping track of the currently active tasks for a Keptn deployment")) + deploymentActiveGauge, err := meter.AsyncInt64().Gauge("keptn.deployment.active", instrument.WithDescription("a gauge keeping track of the currently active Keptn Tasks")) if err != nil { setupLog.Error(err, "unable to start OTel") } - taskCount, err := meter.SyncInt64().Counter("keptn.task.count", instrument.WithDescription("a simple counter for Keptn tasks")) + taskCount, err := meter.SyncInt64().Counter("keptn.task.count", instrument.WithDescription("a simple counter for Keptn Tasks")) if err != nil { setupLog.Error(err, "unable to start OTel") } - taskDuration, err := meter.SyncFloat64().Histogram("keptn.task.duration", instrument.WithDescription("a histogram of duration for Keptn tasks"), instrument.WithUnit(unit.Unit("s"))) + taskDuration, err := meter.SyncFloat64().Histogram("keptn.task.duration", instrument.WithDescription("a histogram of duration for Keptn Tasks"), instrument.WithUnit(unit.Unit("s"))) if err != nil { setupLog.Error(err, "unable to start OTel") } - taskActiveGauge, err := meter.AsyncInt64().Gauge("keptn.task.active", instrument.WithDescription("a simple counter of active Keptn tasks")) + taskActiveGauge, err := meter.AsyncInt64().Gauge("keptn.task.active", instrument.WithDescription("a simple counter of active Keptn Tasks")) if err != nil { setupLog.Error(err, "unable to start OTel") } - appCount, err := meter.SyncInt64().Counter("keptn.app.count", instrument.WithDescription("a simple counter for Keptn apps")) + appCount, err := meter.SyncInt64().Counter("keptn.app.count", instrument.WithDescription("a simple counter for Keptn Apps")) if err != nil { setupLog.Error(err, "unable to start OTel") } - appDuration, err := meter.SyncFloat64().Histogram("keptn.app.duration", instrument.WithDescription("a histogram of duration for Keptn apps"), instrument.WithUnit(unit.Unit("s"))) + appDuration, err := meter.SyncFloat64().Histogram("keptn.app.duration", instrument.WithDescription("a histogram of duration for Keptn Apps"), instrument.WithUnit(unit.Unit("s"))) if err != nil { setupLog.Error(err, "unable to start OTel") } - appActiveGauge, err := meter.AsyncInt64().Gauge("keptn.app.active", instrument.WithDescription("a simple counter of active apps for Keptn apps")) + appActiveGauge, err := meter.AsyncInt64().Gauge("keptn.app.active", instrument.WithDescription("a simple counter of active Keptn Apps")) if err != nil { setupLog.Error(err, "unable to start OTel") } - evaluationCount, err := meter.SyncInt64().Counter("keptn.evaluation.count", instrument.WithDescription("a simple counter for Keptn evaluation for Evaluations")) + evaluationCount, err := meter.SyncInt64().Counter("keptn.evaluation.count", instrument.WithDescription("a simple counter for Keptn Evaluations")) if err != nil { setupLog.Error(err, "unable to start OTel") } - evaluationDuration, err := meter.SyncFloat64().Histogram("keptn.evaluation.duration", instrument.WithDescription("a histogram of duration for Keptn evaluation for Evaluations"), instrument.WithUnit(unit.Unit("s"))) + evaluationDuration, err := meter.SyncFloat64().Histogram("keptn.evaluation.duration", instrument.WithDescription("a histogram of duration for Keptn Evaluations"), instrument.WithUnit(unit.Unit("s"))) if err != nil { setupLog.Error(err, "unable to start OTel") } - evaluationActiveGauge, err := meter.AsyncInt64().Gauge("keptn.evaluation.active", instrument.WithDescription("a simple counter of active apps for Keptn evaluation for Evaluations")) + evaluationActiveGauge, err := meter.AsyncInt64().Gauge("keptn.evaluation.active", instrument.WithDescription("a simple counter of active Keptn Evaluations")) if err != nil { setupLog.Error(err, "unable to start OTel") } From a47d0a362ed72db06cdb9ba7261bcbe1201ff60a Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 20 Oct 2022 15:39:54 +0200 Subject: [PATCH 4/5] pr review Signed-off-by: Florian Bacher --- operator/controllers/keptnappversion/controller.go | 4 +--- operator/controllers/keptnevaluation/controller.go | 8 ++------ operator/controllers/keptntask/controller.go | 9 ++------- operator/controllers/keptnworkloadinstance/controller.go | 4 +--- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/operator/controllers/keptnappversion/controller.go b/operator/controllers/keptnappversion/controller.go index a3812fde60..d78f90388b 100644 --- a/operator/controllers/keptnappversion/controller.go +++ b/operator/controllers/keptnappversion/controller.go @@ -80,9 +80,7 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ return reconcile.Result{}, fmt.Errorf("could not fetch KeptnappVersion: %+v", err) } - if !appVersion.IsStartTimeSet() { - appVersion.SetStartTime() - } + appVersion.SetStartTime() traceContextCarrier := propagation.MapCarrier(appVersion.Annotations) ctx = otel.GetTextMapPropagator().Extract(ctx, traceContextCarrier) diff --git a/operator/controllers/keptnevaluation/controller.go b/operator/controllers/keptnevaluation/controller.go index 11cde8ca16..9a17ac3af8 100644 --- a/operator/controllers/keptnevaluation/controller.go +++ b/operator/controllers/keptnevaluation/controller.go @@ -94,9 +94,7 @@ func (r *KeptnEvaluationReconciler) Reconcile(ctx context.Context, req ctrl.Requ semconv.AddAttributeFromEvaluation(span, *evaluation) - if !evaluation.IsStartTimeSet() { - evaluation.SetStartTime() - } + evaluation.SetStartTime() if evaluation.Status.RetryCount >= evaluation.Spec.Retries { r.recordEvent("Warning", evaluation, "ReconcileTimeOut", "retryCount exceeded") @@ -180,9 +178,7 @@ func (r *KeptnEvaluationReconciler) Reconcile(ctx context.Context, req ctrl.Requ func (r *KeptnEvaluationReconciler) updateFinishedEvaluationMetrics(ctx context.Context, evaluation *klcv1alpha1.KeptnEvaluation, span trace.Span) error { r.recordEvent("Normal", evaluation, string(evaluation.Status.OverallStatus), "the evaluation has "+string(evaluation.Status.OverallStatus)) - if !evaluation.IsEndTimeSet() { - evaluation.SetEndTime() - } + evaluation.SetEndTime() err := r.Client.Status().Update(ctx, evaluation) if err != nil { diff --git a/operator/controllers/keptntask/controller.go b/operator/controllers/keptntask/controller.go index 698e38cf5a..3bc7beef35 100644 --- a/operator/controllers/keptntask/controller.go +++ b/operator/controllers/keptntask/controller.go @@ -77,9 +77,7 @@ func (r *KeptnTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( semconv.AddAttributeFromTask(span, *task) - if !task.IsStartTimeSet() { - task.SetStartTime() - } + task.SetStartTime() err := r.Client.Status().Update(ctx, task) if err != nil { @@ -115,10 +113,7 @@ func (r *KeptnTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( r.Log.Info("Finished Reconciling KeptnTask") // Task is completed at this place - - if !task.IsEndTimeSet() { - task.SetEndTime() - } + task.SetEndTime() err = r.Client.Status().Update(ctx, task) if err != nil { diff --git a/operator/controllers/keptnworkloadinstance/controller.go b/operator/controllers/keptnworkloadinstance/controller.go index c6dafc2bf4..3047e2fcb8 100644 --- a/operator/controllers/keptnworkloadinstance/controller.go +++ b/operator/controllers/keptnworkloadinstance/controller.go @@ -96,9 +96,7 @@ func (r *KeptnWorkloadInstanceReconciler) Reconcile(ctx context.Context, req ctr semconv.AddAttributeFromWorkloadInstance(span, *workloadInstance) - if !workloadInstance.IsStartTimeSet() { - workloadInstance.SetStartTime() - } + workloadInstance.SetStartTime() //Wait for pre-evaluation checks of App phase := common.PhaseAppPreEvaluation From 64cd8c2fc0a1327f69b45e95bc4e444055de91fd Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Thu, 20 Oct 2022 15:43:39 +0200 Subject: [PATCH 5/5] pr review Signed-off-by: Florian Bacher --- operator/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator/main.go b/operator/main.go index cac3f8e1c6..aed6d8b037 100644 --- a/operator/main.go +++ b/operator/main.go @@ -123,7 +123,7 @@ func main() { if err != nil { setupLog.Error(err, "unable to start OTel") } - deploymentActiveGauge, err := meter.AsyncInt64().Gauge("keptn.deployment.active", instrument.WithDescription("a gauge keeping track of the currently active Keptn Tasks")) + deploymentActiveGauge, err := meter.AsyncInt64().Gauge("keptn.deployment.active", instrument.WithDescription("a gauge keeping track of the currently active Keptn Deployments")) if err != nil { setupLog.Error(err, "unable to start OTel") }