From fc99feb71bcb90930c60a2ae0993730d644c79ed Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Thu, 23 Sep 2021 16:21:24 +0530 Subject: [PATCH] Add properties in CR to configure Pipelines Metrics --- .../operator/v1alpha1/tektonpipeline_types.go | 10 ++++++++ .../tektonpipeline/tektonpipeline.go | 2 ++ .../openshift/tektonpipeline/extension.go | 25 +++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/pkg/apis/operator/v1alpha1/tektonpipeline_types.go b/pkg/apis/operator/v1alpha1/tektonpipeline_types.go index 52b9a6b177..a903f75b50 100644 --- a/pkg/apis/operator/v1alpha1/tektonpipeline_types.go +++ b/pkg/apis/operator/v1alpha1/tektonpipeline_types.go @@ -91,6 +91,7 @@ type PipelineProperties struct { EnableCustomTasks *bool `json:"enable-custom-tasks,omitempty"` EnableApiFields string `json:"enable-api-fields,omitempty"` ScopeWhenExpressionsToTask *bool `json:"scope-when-expressions-to-task,omitempty"` + PipelineMetricsProperties `json:",inline"` // +optional OptionalPipelineProperties `json:",inline"` } @@ -105,3 +106,12 @@ type OptionalPipelineProperties struct { DefaultCloudEventsSink string `json:"default-cloud-events-sink,omitempty"` DefaultTaskRunWorkspaceBinding string `json:"default-task-run-workspace-binding,omitempty"` } + +// PipelineMetricsProperties defines the fields which are configurable for +// metrics +type PipelineMetricsProperties struct { + MetricsTaskrunLevel string `json:"metrics.taskrun.level,omitempty"` + MetricsTaskrunDurationType string `json:"metrics.taskrun.duration-type,omitempty"` + MetricsPipelinerunLevel string `json:"metrics.pipelinerun.level,omitempty"` + MetricsPipelinerunDurationType string `json:"metrics.pipelinerun.duration-type,omitempty"` +} diff --git a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go index 6f6d8d9912..127d9fa796 100644 --- a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go +++ b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go @@ -31,6 +31,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" "knative.dev/pkg/logging" + "knative.dev/pkg/metrics" pkgreconciler "knative.dev/pkg/reconciler" ) @@ -314,6 +315,7 @@ func (r *Reconciler) transform(ctx context.Context, manifest *mf.Manifest, comp extra := []mf.Transformer{ common.AddConfigMapValues(featureFlag, pipeline.Spec.PipelineProperties), common.AddConfigMapValues(configDefaults, pipeline.Spec.OptionalPipelineProperties), + common.AddConfigMapValues(metrics.ConfigMapName(), pipeline.Spec.PipelineMetricsProperties), common.ApplyProxySettings, common.DeploymentImages(images), common.InjectLabelOnNamespace(proxyLabel), diff --git a/pkg/reconciler/openshift/tektonpipeline/extension.go b/pkg/reconciler/openshift/tektonpipeline/extension.go index d348ba7a53..2e8a757b1d 100644 --- a/pkg/reconciler/openshift/tektonpipeline/extension.go +++ b/pkg/reconciler/openshift/tektonpipeline/extension.go @@ -41,8 +41,12 @@ const ( DefaultDisableAffinityAssistant = true monitoringLabel = "openshift.io/cluster-monitoring=true" - enableMetricsKey = "enableMetrics" - enableMetricsDefaultValue = "true" + enableMetricsKey = "enableMetrics" + enableMetricsDefaultValue = "true" + DefaultMetricsPipelinerunLevel = "pipeline" + DefaultMetricsTaskrunLevel = "task" + DefaultMetricsPipelierunDurationType = "histogram" + DefaultMetricsTaskrunDurationType = "histogram" ) func OpenShiftExtension(ctx context.Context) common.Extension { @@ -191,6 +195,23 @@ func SetDefault(pipeline *v1alpha1.Pipeline) bool { updated = true } + if pipeline.MetricsPipelinerunDurationType == "" { + pipeline.MetricsPipelinerunDurationType = DefaultMetricsPipelierunDurationType + updated = true + } + if pipeline.MetricsPipelinerunLevel == "" { + pipeline.MetricsPipelinerunLevel = DefaultMetricsPipelinerunLevel + updated = true + } + if pipeline.MetricsTaskrunDurationType == "" { + pipeline.MetricsTaskrunDurationType = DefaultMetricsTaskrunDurationType + updated = true + } + if pipeline.MetricsTaskrunLevel == "" { + pipeline.MetricsTaskrunLevel = DefaultMetricsTaskrunLevel + updated = true + } + return updated }