diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index 29c698252b6..99a4c0048ab 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -235,9 +235,6 @@ func (c *Reconciler) durationAndCountMetrics(ctx context.Context, tr *v1beta1.Ta if err := c.metrics.DurationAndCount(ctx, tr, beforeCondition); err != nil { logger.Warnf("Failed to log the duration and count of taskruns : %v", err) } - if err := c.metrics.CloudEvents(ctx, tr); err != nil { - logger.Warnf("Failed to log the number of cloud events: %v", err) - } } } diff --git a/pkg/taskrunmetrics/metrics.go b/pkg/taskrunmetrics/metrics.go index 7c61d571057..06b0450969d 100644 --- a/pkg/taskrunmetrics/metrics.go +++ b/pkg/taskrunmetrics/metrics.go @@ -59,7 +59,6 @@ var ( runningTRsThrottledByQuotaCountView *view.View runningTRsThrottledByNodeCountView *view.View podLatencyView *view.View - cloudEventsView *view.View trDuration = stats.Float64( "taskrun_duration_seconds", @@ -90,10 +89,6 @@ var ( podLatency = stats.Float64("taskruns_pod_latency", "scheduling latency for the taskruns pods", stats.UnitMilliseconds) - - cloudEvents = stats.Int64("cloudevent_count", - "number of cloud events sent including retries", - stats.UnitDimensionless) ) // Recorder is used to actually record TaskRun metrics @@ -230,12 +225,6 @@ func viewRegister(cfg *config.Metrics) error { Aggregation: view.LastValue(), TagKeys: append([]tag.Key{namespaceTag, podTag}, trunTag...), } - cloudEventsView = &view.View{ - Description: cloudEvents.Description(), - Measure: cloudEvents, - Aggregation: view.Sum(), - TagKeys: append([]tag.Key{statusTag, namespaceTag}, append(trunTag, prunTag...)...), - } return view.Register( trDurationView, prTRDurationView, @@ -244,7 +233,6 @@ func viewRegister(cfg *config.Metrics) error { runningTRsThrottledByQuotaCountView, runningTRsThrottledByNodeCountView, podLatencyView, - cloudEventsView, ) } @@ -257,7 +245,6 @@ func viewUnregister() { runningTRsThrottledByQuotaCountView, runningTRsThrottledByNodeCountView, podLatencyView, - cloudEventsView, ) } @@ -456,42 +443,6 @@ func (r *Recorder) RecordPodLatency(ctx context.Context, pod *corev1.Pod, tr *v1 return nil } -// CloudEvents logs the number of cloud events sent for TaskRun -// returns an error if it fails to log the metrics -func (r *Recorder) CloudEvents(ctx context.Context, tr *v1beta1.TaskRun) error { - r.mutex.Lock() - defer r.mutex.Unlock() - - if !r.initialized { - return fmt.Errorf("ignoring the metrics recording for %s , failed to initialize the metrics recorder", tr.Name) - } - - taskName := anonymous - if tr.Spec.TaskRef != nil { - taskName = tr.Spec.TaskRef.Name - } - - status := "success" - if cond := tr.Status.GetCondition(apis.ConditionSucceeded); cond.Status == corev1.ConditionFalse { - status = "failed" - } - - tags := []tag.Mutator{tag.Insert(namespaceTag, tr.Namespace), tag.Insert(statusTag, status)} - if ok, pipeline, pipelinerun := IsPartOfPipeline(tr); ok { - tags = append(tags, r.insertPipelineTag(pipeline, pipelinerun)...) - } - tags = append(tags, r.insertTaskTag(taskName, tr.Name)...) - - ctx, err := tag.New(ctx, tags...) - if err != nil { - return err - } - - metrics.Record(ctx, cloudEvents.M(sentCloudEvents(tr))) - - return nil -} - // IsPartOfPipeline return true if TaskRun is a part of a Pipeline. // It also return the name of Pipeline and PipelineRun func IsPartOfPipeline(tr *v1beta1.TaskRun) (bool, string, string) { @@ -505,16 +456,6 @@ func IsPartOfPipeline(tr *v1beta1.TaskRun) (bool, string, string) { return false, "", "" } -func sentCloudEvents(tr *v1beta1.TaskRun) int64 { - var sent int64 - for _, event := range tr.Status.CloudEvents { - if event.Status.Condition != v1beta1.CloudEventConditionUnknown { - sent += 1 + int64(event.Status.RetryCount) - } - } - return sent -} - func getScheduledTime(pod *corev1.Pod) metav1.Time { for _, c := range pod.Status.Conditions { if c.Type == corev1.PodScheduled { diff --git a/pkg/taskrunmetrics/metrics_test.go b/pkg/taskrunmetrics/metrics_test.go index 3bfe5c59dca..1a892dbb973 100644 --- a/pkg/taskrunmetrics/metrics_test.go +++ b/pkg/taskrunmetrics/metrics_test.go @@ -76,9 +76,6 @@ func TestUninitializedMetrics(t *testing.T) { if err := metrics.RecordPodLatency(ctx, nil, nil); err == nil { t.Error("Pod Latency recording expected to return error but got nil") } - if err := metrics.CloudEvents(ctx, &v1beta1.TaskRun{}); err == nil { - t.Error("Cloud Events recording expected to return error but got nil") - } } func TestMetricsOnStore(t *testing.T) { @@ -612,160 +609,8 @@ func TestTaskRunIsOfPipelinerun(t *testing.T) { } } -func TestRecordCloudEvents(t *testing.T) { - for _, c := range []struct { - name string - taskRun *v1beta1.TaskRun - expectedTags map[string]string - expectedCount float64 - }{{ - name: "for succeeded task", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "taskrun-1", - Namespace: "ns", - Labels: map[string]string{ - pipeline.PipelineLabelKey: "pipeline-1", - pipeline.PipelineRunLabelKey: "pipelinerun-1", - }, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task-1", - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }}, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: time.Now()}, - CompletionTime: &metav1.Time{Time: time.Now().Add(1 * time.Minute)}, - CloudEvents: []v1beta1.CloudEventDelivery{{ - Target: "http://event_target", - Status: v1beta1.CloudEventDeliveryState{ - Condition: v1beta1.CloudEventConditionSent, - RetryCount: 1, - }, - }}, - }, - }, - }, - expectedTags: map[string]string{ - "pipeline": "pipeline-1", - "pipelinerun": "pipelinerun-1", - "task": "task-1", - "taskrun": "taskrun-1", - "namespace": "ns", - "status": "success", - }, - expectedCount: 2, - }, { - name: "for failed task", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "taskrun-1", - Namespace: "ns", - Labels: map[string]string{ - pipeline.PipelineLabelKey: "pipeline-1", - pipeline.PipelineRunLabelKey: "pipelinerun-1", - }, - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task-1", - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - }}, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: time.Now()}, - CompletionTime: &metav1.Time{Time: time.Now().Add(1 * time.Minute)}, - CloudEvents: []v1beta1.CloudEventDelivery{{ - Target: "http://event_target", - Status: v1beta1.CloudEventDeliveryState{ - Condition: v1beta1.CloudEventConditionFailed, - RetryCount: 2, - }, - }}, - }, - }, - }, - expectedTags: map[string]string{ - "pipeline": "pipeline-1", - "pipelinerun": "pipelinerun-1", - "task": "task-1", - "taskrun": "taskrun-1", - "namespace": "ns", - "status": "failed", - }, - expectedCount: 3, - }, { - name: "for task not part of pipeline", - taskRun: &v1beta1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "taskrun-1", - Namespace: "ns", - }, - Spec: v1beta1.TaskRunSpec{ - TaskRef: &v1beta1.TaskRef{ - Name: "task-1", - }, - }, - Status: v1beta1.TaskRunStatus{ - Status: duckv1.Status{ - Conditions: duckv1.Conditions{apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - }}, - }, - TaskRunStatusFields: v1beta1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: time.Now()}, - CompletionTime: &metav1.Time{Time: time.Now().Add(1 * time.Minute)}, - CloudEvents: []v1beta1.CloudEventDelivery{{ - Target: "http://event_target", - Status: v1beta1.CloudEventDeliveryState{ - Condition: v1beta1.CloudEventConditionSent, - RetryCount: 1, - }, - }}, - }, - }, - }, - expectedTags: map[string]string{ - "task": "task-1", - "taskrun": "taskrun-1", - "namespace": "ns", - "status": "success", - }, - expectedCount: 2, - }} { - t.Run(c.name, func(t *testing.T) { - unregisterMetrics() - ctx := getConfigContext() - metrics, err := NewRecorder(ctx) - if err != nil { - t.Fatalf("NewRecorder: %v", err) - } - - if err := metrics.CloudEvents(ctx, c.taskRun); err != nil { - t.Fatalf("CloudEvents: %v", err) - } - metricstest.CheckSumData(t, "cloudevent_count", c.expectedTags, c.expectedCount) - }) - } -} - func unregisterMetrics() { - metricstest.Unregister("taskrun_duration_seconds", "pipelinerun_taskrun_duration_seconds", "taskrun_count", "running_taskruns_count", "running_taskruns_throttled_by_quota_count", "running_taskruns_throttled_by_node_count", "taskruns_pod_latency", "cloudevent_count") + metricstest.Unregister("taskrun_duration_seconds", "pipelinerun_taskrun_duration_seconds", "taskrun_count", "running_taskruns_count", "running_taskruns_throttled_by_quota_count", "running_taskruns_throttled_by_node_count", "taskruns_pod_latency") // Allow the recorder singleton to be recreated. once = sync.Once{}