Skip to content

Commit

Permalink
Add properties in CR to configure Pipelines Metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
khrm committed Sep 24, 2021
1 parent b0e7662 commit fed1636
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/TektonConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down Expand Up @@ -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
```
Expand Down
36 changes: 31 additions & 5 deletions docs/TektonPipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,19 +57,19 @@ You can install this component using [TektonConfig](./TektonConfig.md) by choosi

- `disable-creds-init` (Default: `false`)

Setting this flag to "true" will prevent Tekton scanning attached service accounts and injecting any credentials it
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
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
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).
Expand Down Expand Up @@ -99,8 +103,30 @@ You can install this component using [TektonConfig](./TektonConfig.md) by choosi

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 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
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonpipeline_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
}

}
6 changes: 6 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonpipeline_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func Test_SetDefaults_PipelineProperties(t *testing.T) {
EnableCustomTasks: ptr.Bool(false),
EnableApiFields: ApiFieldStable,
ScopeWhenExpressionsToTask: ptr.Bool(false),
PipelineMetricsProperties{
MetricsPipelinerunDurationType: DefaultMetricsPipelierunDurationType,
MetricsPipelinerunLevel: DefaultMetricsPipelinerunLevel,
MetricsTaskrunDurationType: DefaultMetricsTaskrunDurationType,
MetricsTaskrunLevel: DefaultMetricsTaskrunLevel,
},
}

tp.SetDefaults(context.TODO())
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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"`
}
17 changes: 17 additions & 0 deletions pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
// Pipelines ConfigMap
featureFlag = "feature-flags"
configDefaults = "config-defaults"
configMetrics = "config-observability"

proxyLabel = "operator.tekton.dev/disable-proxy=true"

Expand Down Expand Up @@ -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),
Expand Down
17 changes: 17 additions & 0 deletions pkg/reconciler/openshift/tektonpipeline/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit fed1636

Please # to comment.