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 23, 2021
1 parent b0e7662 commit fc99feb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
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"`
}
2 changes: 2 additions & 0 deletions pkg/reconciler/kubernetes/tektonpipeline/tektonpipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

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(metrics.ConfigMapName(), pipeline.Spec.PipelineMetricsProperties),
common.ApplyProxySettings,
common.DeploymentImages(images),
common.InjectLabelOnNamespace(proxyLabel),
Expand Down
25 changes: 23 additions & 2 deletions pkg/reconciler/openshift/tektonpipeline/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit fc99feb

Please sign in to comment.