diff --git a/docs/TektonConfig.md b/docs/TektonConfig.md index 799d18760f..f8967cc88a 100644 --- a/docs/TektonConfig.md +++ b/docs/TektonConfig.md @@ -32,6 +32,10 @@ The TektonConfig CR provides the following features enable-api-fields: stable enable-custom-tasks: false enable-tekton-oci-bundles: false + metrics.pipelinerun.duration-type: histogram + metrics.pipelinerun.level: pipelinerun + metrics.taskrun.duration-type: histogram + metrics.taskrun.level: taskrun require-git-ssh-secret-known-hosts: false running-in-environment-with-injected-sidecars: true pruner: {} @@ -98,6 +102,10 @@ pipeline: enable-api-fields: stable enable-custom-tasks: false enable-tekton-oci-bundles: false + metrics.pipelinerun.duration-type: histogram + metrics.pipelinerun.level: pipelinerun + metrics.taskrun.duration-type: histogram + metrics.taskrun.level: taskrun require-git-ssh-secret-known-hosts: false running-in-environment-with-injected-sidecars: true ``` diff --git a/docs/TektonPipeline.md b/docs/TektonPipeline.md index 9d335e15ab..91013b5899 100644 --- a/docs/TektonPipeline.md +++ b/docs/TektonPipeline.md @@ -19,6 +19,10 @@ spec: enable-api-fields: stable enable-custom-tasks: false enable-tekton-oci-bundles: false + metrics.pipelinerun.duration-type: histogram + metrics.pipelinerun.level: pipeline + metrics.taskrun.duration-type: histogram + metrics.taskrun.level: task require-git-ssh-secret-known-hosts: false running-in-environment-with-injected-sidecars: true scope-when-expressions-to-task: false @@ -26,68 +30,68 @@ spec: You can install this component using [TektonConfig](./TektonConfig.md) by choosing appropriate `profile`. ### Properties - This fields have default values so even if user have not passed them in CR, operator will add them. User can later change - them as per their need. +This fields have default values so even if user have not passed them in CR, operator will add them. User can later change +them as per their need. - `disable-affinity-assistant` (Default: `false`) - - Setting this flag to "true" will prevent Tekton to create an Affinity Assistant for every TaskRun sharing a PVC workspace. The default behaviour is for Tekton to create Affinity Assistants. - + + Setting this flag to "true" will prevent Tekton to create an Affinity Assistant for every TaskRun sharing a PVC workspace. The default behaviour is for Tekton to create Affinity Assistants. + See more in the workspace documentation about [Affinity Assistant](https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md#affinity-assistant-and-specifying-workspace-order-in-a-pipeline) - or more info [here](https://github.com/tektoncd/pipeline/pull/2630). - + or more info [here](https://github.com/tektoncd/pipeline/pull/2630). + - `disable-home-env-overwrite` (Default: `true`) - + Setting this flag to "false" will allow Tekton to override your Task container's $HOME environment variable. - + See more info [here](https://github.com/tektoncd/pipeline/issues/2013). - `disable-working-directory-overwrite` (Default: `true`) - - Setting this flag to "false" will allow Tekton to override your Task container's working directory. - + + Setting this flag to "false" will allow Tekton to override your Task container's working directory. + See more info [here](https://github.com/tektoncd/pipeline/issues/1836). - `disable-creds-init` (Default: `false`) - - Setting this flag to "true" will prevent Tekton scanning attached service accounts and injecting any credentials it - finds into your Steps. - - The default behaviour currently is for Tekton to search service accounts for secrets matching a specified format and - automatically mount those into your Steps. - + + Setting this flag to "true" will prevent Tekton scanning attached service accounts and injecting any credentials it +finds into your Steps. + + The default behaviour currently is for Tekton to search service accounts for secrets matching a specified format and + automatically mount those into your Steps. + Note: setting this to "true" will prevent PipelineResources from working. See more info [here](https://github.com/tektoncd/pipeline/issues/2791). - `running-in-environment-with-injected-sidecars` (Default: `true`) - - This option should be set to false when Pipelines is running in a cluster that does not use injected sidecars such - as Istio. Setting it to false should decrease the time it takes for a TaskRun to start running. For clusters that use - injected sidecars, setting this option to false can lead to unexpected behavior. - + + This option should be set to false when Pipelines is running in a cluster that does not use injected sidecars such +as Istio. Setting it to false should decrease the time it takes for a TaskRun to start running. For clusters that use +injected sidecars, setting this option to false can lead to unexpected behavior. + See more info [here](https://github.com/tektoncd/pipeline/issues/2080). - `require-git-ssh-secret-known-hosts` (Default: `false`) - Setting this flag to "true" will require that any Git SSH Secret offered to Tekton must have known_hosts included. + Setting this flag to "true" will require that any Git SSH Secret offered to Tekton must have known_hosts included. - See more info [here](https://github.com/tektoncd/pipeline/issues/2981). + See more info [here](https://github.com/tektoncd/pipeline/issues/2981). - `enable-tekton-oci-bundles` (Default: `false`) - - Setting this flag to "true" enables the use of Tekton OCI bundle. This is an experimental feature and thus should - still be considered an alpha feature. - - + + Setting this flag to "true" enables the use of Tekton OCI bundle. This is an experimental feature and thus should +still be considered an alpha feature. + + - `enable-custom-tasks` (Default: `false`) - - Setting this flag to "true" enables the use of custom tasks from within pipelines. This is an experimental feature - and thus should still be considered an alpha feature. + + Setting this flag to "true" enables the use of custom tasks from within pipelines. This is an experimental feature +and thus should still be considered an alpha feature. - `enable-api-fields` (Default: `stable`) @@ -97,54 +101,76 @@ You can install this component using [TektonConfig](./TektonConfig.md) by choosi - `scope-when-expressions-to-task` (Default: `false`) - Setting this flag to "true" scopes when expressions to guard a Task only instead of a Task and its dependent Tasks. + Setting this flag to "true" scopes when expressions to guard a Task only instead of a Task and its dependent Tasks. + +### Metrics Properties +These fields have default values so even if user have not passed them in CR, operator will add them and override the values +configure in pipelines. + +- `metrics.pipelinerun.duration-type` (Default: `histogram`) + + Setting this flag will determine the duration type - gauge or histogram. + +- `metrics.pipelinerun.level` (Default: `pipeline`) + + Setting this flag will determine the level of pipelinerun metrics. + +- `metrics.taskrun.duration-type` (Default: `histogram`) + + Setting this flag will determine the duration type - gauge or histogram. + +- `metrics.taskrun.level` (Default: `task`) + + Setting this flag will determine the level of taskrun metrics. + + ### Optional Properties -This fields doesn't have default values so will be considered only if user passes them. By default Operator won't add -this fields CR and won't configure for pipelines. +This fields doesn't have default values so will be considered only if user passes them. By default Operator won't add +this fields CR and won't configure for pipelines. The Default values for this fields are already set in pipelines are not set by Operator. If user passes some values then those will be set for the particular field. - `default-timeout-minutes` - + default-timeout-minutes contains the default number of minutes to use for TaskRun and PipelineRun, if none is specified. - + `default-timeout-minutes: "60" # 60 minutes` - + - `default-service-account` - + default-service-account contains the default service account name to use for TaskRun and PipelineRun, if none is specified. - + `default-service-account: "default"` - `default-managed-by-label-value` - - default-managed-by-label-value contains the default value given to the "app.kubernetes.io/managed-by" label applied - to all Pods created for TaskRuns. If a user's requested TaskRun specifies another value for this label, the user's - request supersedes. - + + default-managed-by-label-value contains the default value given to the "app.kubernetes.io/managed-by" label applied +to all Pods created for TaskRuns. If a user's requested TaskRun specifies another value for this label, the user's +request supersedes. + `default-managed-by-label-value: "tekton-pipelines"` - `default-pod-template` - + default-pod-template contains the default pod template to use TaskRun and PipelineRun, if none is specified. If a - pod template is specified, the default pod template is ignored. - +pod template is specified, the default pod template is ignored. + - `default-cloud-events-sink` - + default-cloud-events-sink contains the default CloudEvents sink to be used for TaskRun and PipelineRun, when no sink - is specified. Note that right now it is still not possible to set a PipelineRun or TaskRun specific sink, so the - default is the only option available. If no sink is specified, no CloudEvent is generated +is specified. Note that right now it is still not possible to set a PipelineRun or TaskRun specific sink, so the +default is the only option available. If no sink is specified, no CloudEvent is generated - `default-task-run-workspace-binding` - + default-task-run-workspace-binding contains the default workspace configuration provided for any Workspaces that a - Task declares but that a TaskRun does not explicitly provide. +Task declares but that a TaskRun does not explicitly provide. [Pipeline]:https://github.com/tektoncd/pipeline diff --git a/pkg/apis/operator/v1alpha1/tektonpipeline_defaults.go b/pkg/apis/operator/v1alpha1/tektonpipeline_defaults.go index 5e4df23f47..631f98af69 100644 --- a/pkg/apis/operator/v1alpha1/tektonpipeline_defaults.go +++ b/pkg/apis/operator/v1alpha1/tektonpipeline_defaults.go @@ -22,6 +22,13 @@ import ( "knative.dev/pkg/ptr" ) +const ( + DefaultMetricsPipelinerunLevel = "pipeline" + DefaultMetricsTaskrunLevel = "task" + DefaultMetricsPipelierunDurationType = "histogram" + DefaultMetricsTaskrunDurationType = "histogram" +) + func (tp *TektonPipeline) SetDefaults(ctx context.Context) { tp.Spec.PipelineProperties.setDefaults() } @@ -54,4 +61,17 @@ func (p *PipelineProperties) setDefaults() { if p.ScopeWhenExpressionsToTask == nil { p.ScopeWhenExpressionsToTask = ptr.Bool(false) } + if p.MetricsPipelinerunDurationType == "" { + p.MetricsPipelinerunDurationType = DefaultMetricsPipelierunDurationType + } + if p.MetricsPipelinerunLevel == "" { + p.MetricsPipelinerunLevel = DefaultMetricsPipelinerunLevel + } + if p.MetricsTaskrunDurationType == "" { + p.MetricsTaskrunDurationType = DefaultMetricsTaskrunDurationType + } + if p.MetricsTaskrunLevel == "" { + p.MetricsTaskrunLevel = DefaultMetricsTaskrunLevel + } + } diff --git a/pkg/apis/operator/v1alpha1/tektonpipeline_defaults_test.go b/pkg/apis/operator/v1alpha1/tektonpipeline_defaults_test.go index f451a77c47..fd813e7242 100644 --- a/pkg/apis/operator/v1alpha1/tektonpipeline_defaults_test.go +++ b/pkg/apis/operator/v1alpha1/tektonpipeline_defaults_test.go @@ -50,6 +50,12 @@ func Test_SetDefaults_PipelineProperties(t *testing.T) { EnableCustomTasks: ptr.Bool(false), EnableApiFields: ApiFieldStable, ScopeWhenExpressionsToTask: ptr.Bool(false), + PipelineMetricsProperties: PipelineMetricsProperties{ + MetricsPipelinerunDurationType: DefaultMetricsPipelierunDurationType, + MetricsPipelinerunLevel: DefaultMetricsPipelinerunLevel, + MetricsTaskrunDurationType: DefaultMetricsTaskrunDurationType, + MetricsTaskrunLevel: DefaultMetricsTaskrunLevel, + }, } tp.SetDefaults(context.TODO()) 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/apis/operator/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go index 64d249c3a1..02d9f8a1ef 100644 --- a/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go @@ -222,6 +222,22 @@ func (in *Pipeline) DeepCopy() *Pipeline { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PipelineMetricsProperties) DeepCopyInto(out *PipelineMetricsProperties) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineMetricsProperties. +func (in *PipelineMetricsProperties) DeepCopy() *PipelineMetricsProperties { + if in == nil { + return nil + } + out := new(PipelineMetricsProperties) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PipelineProperties) DeepCopyInto(out *PipelineProperties) { *out = *in @@ -270,6 +286,7 @@ func (in *PipelineProperties) DeepCopyInto(out *PipelineProperties) { *out = new(bool) **out = **in } + out.PipelineMetricsProperties = in.PipelineMetricsProperties in.OptionalPipelineProperties.DeepCopyInto(&out.OptionalPipelineProperties) return } diff --git a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go index 6f6d8d9912..87f13d14a7 100644 --- a/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go +++ b/pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go @@ -38,6 +38,7 @@ const ( // Pipelines ConfigMap featureFlag = "feature-flags" configDefaults = "config-defaults" + configMetrics = "config-observability" proxyLabel = "operator.tekton.dev/disable-proxy=true" @@ -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(configMetrics, 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..e49a6aec08 100644 --- a/pkg/reconciler/openshift/tektonpipeline/extension.go +++ b/pkg/reconciler/openshift/tektonpipeline/extension.go @@ -191,6 +191,23 @@ func SetDefault(pipeline *v1alpha1.Pipeline) bool { updated = true } + if pipeline.MetricsPipelinerunDurationType == "" { + pipeline.MetricsPipelinerunDurationType = v1alpha1.DefaultMetricsPipelierunDurationType + updated = true + } + if pipeline.MetricsPipelinerunLevel == "" { + pipeline.MetricsPipelinerunLevel = v1alpha1.DefaultMetricsPipelinerunLevel + updated = true + } + if pipeline.MetricsTaskrunDurationType == "" { + pipeline.MetricsTaskrunDurationType = v1alpha1.DefaultMetricsTaskrunDurationType + updated = true + } + if pipeline.MetricsTaskrunLevel == "" { + pipeline.MetricsTaskrunLevel = v1alpha1.DefaultMetricsTaskrunLevel + updated = true + } + return updated }