Skip to content

feat: set default values for diagnostic and envoy metrics when user not sets #1997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13 changes: 5 additions & 8 deletions apis/telemetry/v1alpha1/metricpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ type MetricPipelinePrometheusInput struct {
// Describes whether Prometheus metrics from specific namespaces are selected. System namespaces are disabled by default.
// +optional
Namespaces *NamespaceSelector `json:"namespaces,omitempty"`
// Configures diagnostic metrics scraping
// +optional
// Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default.
DiagnosticMetrics *MetricPipelineIstioInputDiagnosticMetrics `json:"diagnosticMetrics,omitempty"`
}

Expand Down Expand Up @@ -145,19 +144,17 @@ type MetricPipelineIstioInput struct {
// Describes whether istio-proxy metrics from specific namespaces are selected. System namespaces are enabled by default.
// +optional
Namespaces *NamespaceSelector `json:"namespaces,omitempty"`
// Configures diagnostic metrics scraping
// +optional
// Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default.
DiagnosticMetrics *MetricPipelineIstioInputDiagnosticMetrics `json:"diagnosticMetrics,omitempty"`
// EnvoyMetrics defines the configuration for scraping Envoy metrics.
// If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
// +optional
// If enabled, Envoy metrics with prefix `envoy_` are scraped. The envoy metrics are disabled by default.
EnvoyMetrics *EnvoyMetrics `json:"envoyMetrics,omitempty"`
}

// MetricPipelineIstioInputDiagnosticMetrics defines the diagnostic metrics configuration section
type MetricPipelineIstioInputDiagnosticMetrics struct {
// If enabled, diagnostic metrics are scraped. The default is `false`.
Enabled bool `json:"enabled,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}

// MetricPipelineOutput defines the output configuration section.
Expand All @@ -175,5 +172,5 @@ type MetricPipelineStatus struct {
// EnvoyMetrics defines the configuration for scraping Envoy metrics.
type EnvoyMetrics struct {
// If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
Enabled bool `json:"enabled,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}
16 changes: 13 additions & 3 deletions apis/telemetry/v1alpha1/zz_generated.deepcopy.go

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

12 changes: 4 additions & 8 deletions apis/telemetry/v1beta1/metricpipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ type MetricPipelinePrometheusInput struct {
// Describes whether Prometheus metrics from specific namespaces are selected. System namespaces are disabled by default.
// +optional
Namespaces *NamespaceSelector `json:"namespaces,omitempty"`
// Configures diagnostic metrics scraping
// +optional
// Configures diagnostic metrics scraping. The diagnostic metrics are Disabled by default.
DiagnosticMetrics *MetricPipelineIstioInputDiagnosticMetrics `json:"diagnosticMetrics,omitempty"`
}

Expand Down Expand Up @@ -145,19 +144,17 @@ type MetricPipelineIstioInput struct {
// Describes whether istio-proxy metrics from specific namespaces are selected. System namespaces are enabled by default.
// +optional
Namespaces *NamespaceSelector `json:"namespaces,omitempty"`
// Configures diagnostic metrics scraping
// +optional
// Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default.
DiagnosticMetrics *MetricPipelineIstioInputDiagnosticMetrics `json:"diagnosticMetrics,omitempty"`
// EnvoyMetrics defines the configuration for scraping Envoy metrics.
// If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
// +optional
// If enabled, Envoy metrics with prefix `envoy_` are scraped. The envoy metrics are disabled by default.
EnvoyMetrics *EnvoyMetrics `json:"envoyMetrics,omitempty"`
}

// MetricPipelineIstioInputDiagnosticMetrics defines the diagnostic metrics configuration section
type MetricPipelineIstioInputDiagnosticMetrics struct {
// If enabled, diagnostic metrics are scraped. The default is `false`.
Enabled bool `json:"enabled,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}

// MetricPipelineOutput defines the output configuration section.
Expand All @@ -175,6 +172,5 @@ type MetricPipelineStatus struct {
// EnvoyMetrics defines the configuration for scraping Envoy metrics.
type EnvoyMetrics struct {
// If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
// +optional
Enabled *bool `json:"enabled,omitempty"`
}
9 changes: 7 additions & 2 deletions apis/telemetry/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ spec:
description: Configures istio-proxy metrics scraping.
properties:
diagnosticMetrics:
description: Configures diagnostic metrics scraping
description: Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default.
properties:
enabled:
description: If enabled, diagnostic metrics are scraped. The default is `false`.
Expand All @@ -77,7 +77,7 @@ spec:
envoyMetrics:
description: |-
EnvoyMetrics defines the configuration for scraping Envoy metrics.
If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
If enabled, Envoy metrics with prefix `envoy_` are scraped. The envoy metrics are disabled by default.
properties:
enabled:
description: If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
Expand Down Expand Up @@ -129,7 +129,7 @@ spec:
description: Configures Prometheus scraping.
properties:
diagnosticMetrics:
description: Configures diagnostic metrics scraping
description: Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default.
properties:
enabled:
description: If enabled, diagnostic metrics are scraped. The default is `false`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ spec:
description: Configures istio-proxy metrics scraping.
properties:
diagnosticMetrics:
description: Configures diagnostic metrics scraping
description: Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default.
properties:
enabled:
description: If enabled, diagnostic metrics are scraped. The default is `false`.
Expand All @@ -77,7 +77,7 @@ spec:
envoyMetrics:
description: |-
EnvoyMetrics defines the configuration for scraping Envoy metrics.
If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
If enabled, Envoy metrics with prefix `envoy_` are scraped. The envoy metrics are disabled by default.
properties:
enabled:
description: If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
Expand Down Expand Up @@ -129,7 +129,7 @@ spec:
description: Configures Prometheus scraping.
properties:
diagnosticMetrics:
description: Configures diagnostic metrics scraping
description: Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default.
properties:
enabled:
description: If enabled, diagnostic metrics are scraped. The default is `false`.
Expand Down Expand Up @@ -610,7 +610,7 @@ spec:
description: Configures istio-proxy metrics scraping.
properties:
diagnosticMetrics:
description: Configures diagnostic metrics scraping
description: Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default.
properties:
enabled:
description: If enabled, diagnostic metrics are scraped. The default is `false`.
Expand All @@ -622,7 +622,7 @@ spec:
envoyMetrics:
description: |-
EnvoyMetrics defines the configuration for scraping Envoy metrics.
If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
If enabled, Envoy metrics with prefix `envoy_` are scraped. The envoy metrics are disabled by default.
properties:
enabled:
description: If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`.
Expand Down Expand Up @@ -674,7 +674,7 @@ spec:
description: Configures Prometheus scraping.
properties:
diagnosticMetrics:
description: Configures diagnostic metrics scraping
description: Configures diagnostic metrics scraping. The diagnostic metrics are Disabled by default.
properties:
enabled:
description: If enabled, diagnostic metrics are scraped. The default is `false`.
Expand Down
6 changes: 3 additions & 3 deletions docs/user/resources/05-metricpipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ For details, see the [MetricPipeline specification file](https://github.com/kyma
| ---- | ----------- | ---- |
| **input** | object | Configures different inputs to send additional metrics to the metric gateway. |
| **input.​istio** | object | Configures istio-proxy metrics scraping. |
| **input.​istio.​diagnosticMetrics** | object | Configures diagnostic metrics scraping |
| **input.​istio.​diagnosticMetrics** | object | Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default. |
| **input.​istio.​diagnosticMetrics.​enabled** | boolean | If enabled, diagnostic metrics are scraped. The default is `false`. |
| **input.​istio.​enabled** | boolean | If enabled, istio-proxy metrics are scraped from Pods that have the istio-proxy sidecar injected. The default is `false`. |
| **input.​istio.​envoyMetrics** | object | EnvoyMetrics defines the configuration for scraping Envoy metrics. If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`. |
| **input.​istio.​envoyMetrics** | object | EnvoyMetrics defines the configuration for scraping Envoy metrics. If enabled, Envoy metrics with prefix `envoy_` are scraped. The envoy metrics are disabled by default. |
| **input.​istio.​envoyMetrics.​enabled** | boolean | If enabled, Envoy metrics with prefix `envoy_` are scraped. The default is `false`. |
| **input.​istio.​namespaces** | object | Describes whether istio-proxy metrics from specific namespaces are selected. System namespaces are enabled by default. |
| **input.​istio.​namespaces.​exclude** | \[\]string | Exclude signals from the specified Namespace names only. |
Expand All @@ -84,7 +84,7 @@ For details, see the [MetricPipeline specification file](https://github.com/kyma
| **input.​otlp.​namespaces.​exclude** | \[\]string | Exclude signals from the specified Namespace names only. |
| **input.​otlp.​namespaces.​include** | \[\]string | Include signals from the specified Namespace names only. |
| **input.​prometheus** | object | Configures Prometheus scraping. |
| **input.​prometheus.​diagnosticMetrics** | object | Configures diagnostic metrics scraping |
| **input.​prometheus.​diagnosticMetrics** | object | Configures diagnostic metrics scraping. The diagnostic metrics are disabled by default. |
| **input.​prometheus.​diagnosticMetrics.​enabled** | boolean | If enabled, diagnostic metrics are scraped. The default is `false`. |
| **input.​prometheus.​enabled** | boolean | If enabled, Services and Pods marked with `prometheus.io/scrape=true` annotation are scraped. The default is `false`. |
| **input.​prometheus.​namespaces** | object | Describes whether Prometheus metrics from specific namespaces are selected. System namespaces are disabled by default. |
Expand Down
6 changes: 3 additions & 3 deletions internal/utils/metricpipeline/metricpipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func IsIstioInputEnabled(input telemetryv1alpha1.MetricPipelineInput) bool {
}

func IsEnvoyMetricsEnabled(input telemetryv1alpha1.MetricPipelineInput) bool {
return input.Istio.EnvoyMetrics != nil && input.Istio.EnvoyMetrics.Enabled
return input.Istio.EnvoyMetrics != nil && input.Istio.EnvoyMetrics.Enabled != nil && *input.Istio.EnvoyMetrics.Enabled
}

func IsPrometheusInputEnabled(input telemetryv1alpha1.MetricPipelineInput) bool {
Expand All @@ -23,11 +23,11 @@ func IsOTLPInputEnabled(input telemetryv1alpha1.MetricPipelineInput) bool {
}

func IsPrometheusDiagnosticInputEnabled(input telemetryv1alpha1.MetricPipelineInput) bool {
return input.Prometheus.DiagnosticMetrics != nil && input.Prometheus.DiagnosticMetrics.Enabled
return input.Prometheus.DiagnosticMetrics != nil && input.Prometheus.DiagnosticMetrics.Enabled != nil && *input.Prometheus.DiagnosticMetrics.Enabled
}

func IsIstioDiagnosticInputEnabled(input telemetryv1alpha1.MetricPipelineInput) bool {
return input.Istio.DiagnosticMetrics != nil && input.Istio.DiagnosticMetrics.Enabled
return input.Istio.DiagnosticMetrics != nil && input.Istio.DiagnosticMetrics.Enabled != nil && *input.Istio.DiagnosticMetrics.Enabled
}

func IsRuntimePodInputEnabled(input telemetryv1alpha1.MetricPipelineInput) bool {
Expand Down
6 changes: 3 additions & 3 deletions internal/utils/test/metric_pipeline_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (b *MetricPipelineBuilder) WithPrometheusInputDiagnosticMetrics(enable bool
b.inPrometheus.DiagnosticMetrics = &telemetryv1alpha1.MetricPipelineIstioInputDiagnosticMetrics{}
}

b.inPrometheus.DiagnosticMetrics.Enabled = enable
b.inPrometheus.DiagnosticMetrics.Enabled = &enable

return b
}
Expand All @@ -178,7 +178,7 @@ func (b *MetricPipelineBuilder) WithIstioInputDiagnosticMetrics(enable bool) *Me
b.inIstio.DiagnosticMetrics = &telemetryv1alpha1.MetricPipelineIstioInputDiagnosticMetrics{}
}

b.inIstio.DiagnosticMetrics.Enabled = enable
b.inIstio.DiagnosticMetrics.Enabled = &enable

return b
}
Expand Down Expand Up @@ -342,7 +342,7 @@ func (b *MetricPipelineBuilder) WithIstioInputEnvoyMetrics(enable bool) *MetricP
b.inIstio.EnvoyMetrics = &telemetryv1alpha1.EnvoyMetrics{}
}

b.inIstio.EnvoyMetrics.Enabled = enable
b.inIstio.EnvoyMetrics.Enabled = &enable

return b
}
20 changes: 20 additions & 0 deletions webhook/metricpipeline/v1alpha1/defaulter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type defaulter struct {
ExcludeNamespaces []string
RuntimeInputResources runtimeInputResourceDefaults
DefaultOTLPOutputProtocol string
DiagnosticMetricsEnabled bool
EnvoyMetricsEnabled bool
}

type runtimeInputResourceDefaults struct {
Expand Down Expand Up @@ -68,6 +70,24 @@ func (md defaulter) applyDefaults(pipeline *telemetryv1alpha1.MetricPipeline) {
if pipeline.Spec.Output.OTLP != nil && pipeline.Spec.Output.OTLP.Protocol == "" {
pipeline.Spec.Output.OTLP.Protocol = md.DefaultOTLPOutputProtocol
}

if metricpipelineutils.IsIstioInputEnabled(pipeline.Spec.Input) && pipeline.Spec.Input.Istio.DiagnosticMetrics == nil {
pipeline.Spec.Input.Istio.DiagnosticMetrics = &telemetryv1alpha1.MetricPipelineIstioInputDiagnosticMetrics{
Enabled: &md.DiagnosticMetricsEnabled,
}
}

if metricpipelineutils.IsIstioInputEnabled(pipeline.Spec.Input) && pipeline.Spec.Input.Istio.EnvoyMetrics == nil {
pipeline.Spec.Input.Istio.EnvoyMetrics = &telemetryv1alpha1.EnvoyMetrics{
Enabled: &md.EnvoyMetricsEnabled,
}
}

if metricpipelineutils.IsPrometheusInputEnabled(pipeline.Spec.Input) && pipeline.Spec.Input.Prometheus.DiagnosticMetrics == nil {
pipeline.Spec.Input.Prometheus.DiagnosticMetrics = &telemetryv1alpha1.MetricPipelineIstioInputDiagnosticMetrics{
Enabled: &md.DiagnosticMetricsEnabled,
}
}
}

func (md defaulter) applyRuntimeInputResourceDefaults(pipeline *telemetryv1alpha1.MetricPipeline) {
Expand Down
Loading
Loading