Skip to content

Commit

Permalink
chore(metrics): merge two metric collection settings into one
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Oct 31, 2024
1 parent 32ddd6c commit a850b9f
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 189 deletions.
13 changes: 3 additions & 10 deletions api/dash0monitoring/v1alpha1/operator_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,11 @@ type Dash0OperatorConfigurationSpec struct {
// +kubebuilder:default={enabled: true}
SelfMonitoring SelfMonitoring `json:"selfMonitoring,omitempty"`

// If enabled, the operator will configure its OpenTelemetry collector to collect node, pod, container, and volume
// metrics from the Kubernetes API server on all nodes via the kubeletstats receiver. This setting is optional, it
// defaults to true.
// If enabled, the operator will collect Kubernetes infrastructure metrics. This setting is optional, it defaults
// to true.
//
// +kubebuilder:default=true
NodeLevelMetricsCollectionEnabled *bool `json:"nodeLevelMetricsCollectionEnabled,omitempty"`

// If enabled, the operator will configure its OpenTelemetry collector to collect cluster-level Kubernetes metrics
// from the Kubernetes API server via the k8sclusterreceiver. This setting is optional, it defaults to true.
//
// +kubebuilder:default=true
ClusterMetricsCollectionEnabled *bool `json:"clusterMetricsCollectionEnabled,omitempty"`
KubernetesInfrastructureMetricsCollectionEnabled *bool `json:"kubernetesInfrastructureMetricsCollectionEnabled,omitempty"`
}

// SelfMonitoring describes how the operator will report telemetry about its working to the backend.
Expand Down
9 changes: 2 additions & 7 deletions api/dash0monitoring/v1alpha1/zz_generated.deepcopy.go

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

24 changes: 8 additions & 16 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ func main() {
var operatorConfigurationSecretRefKey string
var operatorConfigurationApiEndpoint string
var operatorConfigurationSelfMonitoringEnabled bool
var operatorConfigurationNodeLevelMetricsCollectionEnabled bool
var operatorConfigurationClusterMetricsCollectionEnabled bool
var operatorConfigurationKubernetesInfrastructureMetricsCollectionEnabled bool
var isUninstrumentAll bool
var metricsAddr string
var enableLeaderElection bool
Expand Down Expand Up @@ -179,18 +178,11 @@ func main() {
"operator-configuration-endpoint is not set.",
)
flag.BoolVar(
&operatorConfigurationNodeLevelMetricsCollectionEnabled,
"operator-configuration-node-level-metrics-collection-enabled",
&operatorConfigurationKubernetesInfrastructureMetricsCollectionEnabled,
"operator-configuration-kubernetes-infrastructure-metrics-collection-enabled",
true,
"Whether to set nodeLevelMetricsCollectionEnabled on the operator configuration resource; will be ignored if "+
"operator-configuration-endpoint is not set.")
flag.BoolVar(
&operatorConfigurationClusterMetricsCollectionEnabled,
"operator-configuration-cluster-metrics-collection-enabled",
true,
"Whether to set clusterMetricsCollectionEnabled on the operator configuration resource; will be ignored if "+
"operator-configuration-endpoint is not set.",
)
"Whether to set kubernetesInfrastructureMetricsCollectionEnabled on the operator configuration resource; "+
"will be ignored if operator-configuration-endpoint is not set.")
flag.StringVar(
&metricsAddr,
"metrics-bind-address",
Expand Down Expand Up @@ -303,9 +295,9 @@ func main() {
Name: operatorConfigurationSecretRefName,
Key: operatorConfigurationSecretRefKey,
},
SelfMonitoringEnabled: operatorConfigurationSelfMonitoringEnabled,
NodeLevelMetricsCollectionEnabled: operatorConfigurationNodeLevelMetricsCollectionEnabled,
ClusterMetricsCollectionEnabled: operatorConfigurationClusterMetricsCollectionEnabled,
SelfMonitoringEnabled: operatorConfigurationSelfMonitoringEnabled,
//nolint:lll
KubernetesInfrastructureMetricsCollectionEnabled: operatorConfigurationKubernetesInfrastructureMetricsCollectionEnabled,
}
if len(operatorConfigurationApiEndpoint) > 0 {
operatorConfiguration.ApiEndpoint = operatorConfigurationApiEndpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ spec:
description: Dash0OperatorConfigurationSpec describes cluster-wide configuration
settings for the Dash0 Kubernetes operator.
properties:
clusterMetricsCollectionEnabled:
default: true
description: |-
If enabled, the operator will configure its OpenTelemetry collector to collect cluster-level Kubernetes metrics
from the Kubernetes API server via the k8sclusterreceiver. This setting is optional, it defaults to true.
type: boolean
export:
description: |-
The configuration of the default observability backend to which telemetry data will be sent by the operator, as
Expand Down Expand Up @@ -185,12 +179,11 @@ spec:
- endpoint
type: object
type: object
nodeLevelMetricsCollectionEnabled:
kubernetesInfrastructureMetricsCollectionEnabled:
default: true
description: |-
If enabled, the operator will configure its OpenTelemetry collector to collect node, pod, container, and volume
metrics from the Kubernetes API server on all nodes via the kubeletstats receiver. This setting is optional, it
defaults to true.
If enabled, the operator will collect Kubernetes infrastructure metrics. This setting is optional, it defaults
to true.
type: boolean
selfMonitoring:
default:
Expand Down
7 changes: 2 additions & 5 deletions helm-chart/dash0-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ Here is a list of configuration options for this resource:
If enabled, the operator will collect self-monitoring telemetry and send it to the Dash0 Insights dataset of the
configured Dash0 backend.
This setting is optional, it defaults to true.
* `spec.nodeLevelMetricsCollectionEnabled`: If enabled, the operator will configure its OpenTelemetry collector to
collect node, pod, container, and volume metrics from the Kubernetes API server on all nodes via the `kubeletstats`
receiver. This setting is optional, it defaults to true.
* `spec.clusterMetricsCollectionEnabled`: If enabled, the operator will configure its OpenTelemetry collector to collect
cluster-level Kubernetes metrics from the Kubernetes API server via the `k8sclusterreceiver`.
* `spec.kubernetesInfrastructureMetricsCollectionEnabled`: If enabled, the operator will collect Kubernetes
infrastructure metrics.
This setting is optional, it defaults to true.

After providing the required values (at least `endpoint` and `authorization`), save the file and apply the resource to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ spec:
description: Dash0OperatorConfigurationSpec describes cluster-wide configuration
settings for the Dash0 Kubernetes operator.
properties:
clusterMetricsCollectionEnabled:
default: true
description: |-
If enabled, the operator will configure its OpenTelemetry collector to collect cluster-level Kubernetes metrics
from the Kubernetes API server via the k8sclusterreceiver. This setting is optional, it defaults to true.
type: boolean
export:
description: |-
The configuration of the default observability backend to which telemetry data will be sent by the operator, as
Expand Down Expand Up @@ -185,12 +179,11 @@ spec:
- endpoint
type: object
type: object
nodeLevelMetricsCollectionEnabled:
kubernetesInfrastructureMetricsCollectionEnabled:
default: true
description: |-
If enabled, the operator will configure its OpenTelemetry collector to collect node, pod, container, and volume
metrics from the Kubernetes API server on all nodes via the kubeletstats receiver. This setting is optional, it
defaults to true.
If enabled, the operator will collect Kubernetes infrastructure metrics. This setting is optional, it defaults
to true.
type: boolean
selfMonitoring:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ spec:
- --operator-configuration-api-endpoint={{ .Values.operator.dash0Export.apiEndpoint }}
{{- end }}
- --operator-configuration-self-monitoring-enabled={{ .Values.operator.selfMonitoringEnabled }}
- --operator-configuration-node-level-metrics-collection-enabled={{ .Values.operator.nodeLevelMetricsCollectionEnabled }}
- --operator-configuration-cluster-metrics-collection-enabled={{ .Values.operator.clusterMetricsCollectionEnabled }}
- --operator-configuration-kubernetes-infrastructure-metrics-collection-enabled={{ .Values.operator.kubernetesInfrastructureMetricsCollectionEnabled }}
{{- end }}
env:
- name: DASH0_OPERATOR_NAMESPACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ custom resource definition should match snapshot:
spec:
description: Dash0OperatorConfigurationSpec describes cluster-wide configuration settings for the Dash0 Kubernetes operator.
properties:
clusterMetricsCollectionEnabled:
default: true
description: |-
If enabled, the operator will configure its OpenTelemetry collector to collect cluster-level Kubernetes metrics
from the Kubernetes API server via the k8sclusterreceiver. This setting is optional, it defaults to true.
type: boolean
export:
description: |-
The configuration of the default observability backend to which telemetry data will be sent by the operator, as
Expand Down Expand Up @@ -171,12 +165,11 @@ custom resource definition should match snapshot:
- endpoint
type: object
type: object
nodeLevelMetricsCollectionEnabled:
kubernetesInfrastructureMetricsCollectionEnabled:
default: true
description: |-
If enabled, the operator will configure its OpenTelemetry collector to collect node, pod, container, and volume
metrics from the Kubernetes API server on all nodes via the kubeletstats receiver. This setting is optional, it
defaults to true.
If enabled, the operator will collect Kubernetes infrastructure metrics. This setting is optional, it defaults
to true.
type: boolean
selfMonitoring:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,7 @@ tests:
value: --operator-configuration-self-monitoring-enabled=true
- equal:
path: spec.template.spec.containers[0].args[7]
value: --operator-configuration-node-level-metrics-collection-enabled=true
- equal:
path: spec.template.spec.containers[0].args[8]
value: --operator-configuration-cluster-metrics-collection-enabled=true
value: --operator-configuration-kubernetes-infrastructure-metrics-collection-enabled=true

- it: should add args for creating an operator configuration resource with a secretRef to the deployment
documentSelector:
Expand Down Expand Up @@ -294,8 +291,14 @@ tests:
- equal:
path: spec.template.spec.containers[0].args[6]
value: --operator-configuration-api-endpoint=https://api.dash0.com
- equal:
path: spec.template.spec.containers[0].args[7]
value: --operator-configuration-self-monitoring-enabled=true
- equal:
path: spec.template.spec.containers[0].args[8]
value: --operator-configuration-kubernetes-infrastructure-metrics-collection-enabled=true

- it: should disable self-monitoring, node-level and cluster metrics collection
- it: should disable self-monitoring & Kubernetes infrastructure metrics collection
documentSelector:
path: metadata.name
value: dash0-operator-controller
Expand All @@ -307,8 +310,7 @@ tests:
token: "very-secret-dash0-auth-token"
apiEndpoint: https://api.dash0.com
selfMonitoringEnabled: false
nodeLevelMetricsCollectionEnabled: false
clusterMetricsCollectionEnabled: false
kubernetesInfrastructureMetricsCollectionEnabled: false
asserts:
- equal:
path: spec.template.spec.containers[0].args[3]
Expand All @@ -324,10 +326,7 @@ tests:
value: --operator-configuration-self-monitoring-enabled=false
- equal:
path: spec.template.spec.containers[0].args[7]
value: --operator-configuration-node-level-metrics-collection-enabled=false
- equal:
path: spec.template.spec.containers[0].args[8]
value: --operator-configuration-cluster-metrics-collection-enabled=false
value: --operator-configuration-kubernetes-infrastructure-metrics-collection-enabled=false

- it: should render the "dash0.com/cert-digest" label
documentSelector:
Expand Down
15 changes: 3 additions & 12 deletions helm-chart/dash0-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,12 @@ operator:
# resource will be created by the Helm chart then.
selfMonitoringEnabled: true

# An opt-out for collecting node-level metrics. If set to false, the operator will not configure its OpenTelemetry
# collector to collect node, pod, container, and volume metrics from the Kubernetes API server on all nodes via the
# kubeletstats receiver. This setting is optional, it defaults to true.
# An opt-out for collecting kubernetes infrastructure metrics. If set to false, the operator will not collect
# Kubernetes infrastructure metrics. This setting is optional, it defaults to true.
#
# This setting has no effect if operator.dash0Export.enabled is false, as no Dash0OperatorConfiguration
# resource will be created by the Helm chart then.
nodeLevelMetricsCollectionEnabled: true

# An opt-out for collecting cluster metrics. If set to false, the operator will not configure its OpenTelemetry
# collector to collect cluster-level Kubernetes metrics from the Kubernetes API server via the k8sclusterreceiver.
# This setting is optional, it defaults to true.
#
# This setting has no effect if operator.dash0Export.enabled is false, as no Dash0OperatorConfiguration
# resource will be created by the Helm chart then.
clusterMetricsCollectionEnabled: true
kubernetesInfrastructureMetricsCollectionEnabled: true

# number of replica for the controller manager deployment
replicaCount: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
)

type collectorConfigurationTemplateValues struct {
Exporters []OtlpExporter
IgnoreLogsFromNamespaces []string
NodeLevelMetricsCollectionEnabled bool
NamespacesWithPrometheusScraping []string
SelfIpReference string
DevelopmentMode bool
Exporters []OtlpExporter
IgnoreLogsFromNamespaces []string
KubernetesInfrastructureMetricsCollectionEnabled bool
NamespacesWithPrometheusScraping []string
SelfIpReference string
DevelopmentMode bool
}

type OtlpExporter struct {
Expand Down Expand Up @@ -101,10 +101,10 @@ func assembleCollectorConfigMap(
// logs will compound in case of log parsing errors
config.Namespace,
},
NodeLevelMetricsCollectionEnabled: config.NodeLevelMetricsCollectionEnabled,
NamespacesWithPrometheusScraping: namespacesWithPrometheusScraping,
SelfIpReference: selfIpReference,
DevelopmentMode: config.DevelopmentMode,
KubernetesInfrastructureMetricsCollectionEnabled: config.KubernetesInfrastructureMetricsCollectionEnabled,
NamespacesWithPrometheusScraping: namespacesWithPrometheusScraping,
SelfIpReference: selfIpReference,
DevelopmentMode: config.DevelopmentMode,
})
if err != nil {
return nil, fmt.Errorf("cannot render the collector configuration template: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,13 @@ var _ = Describe("The OpenTelemetry Collector ConfigMaps", func() {
}, testConfigs)
})

Describe("should enable/disable node-level metrics collection", func() {
It("should not render the kubeletstats receiver if node-level metrics collection is disabled", func() {
Describe("should enable/disable kubernetes infrastructure metrics collection", func() {
It("should not render the kubeletstats receiver if kubernetes infrastructure metrics collection is disabled", func() {
configMap, err := assembleDaemonSetCollectorConfigMap(&oTelColConfig{
Namespace: namespace,
NamePrefix: namePrefix,
Export: Dash0ExportWithEndpointAndToken(),
NodeLevelMetricsCollectionEnabled: false,
Namespace: namespace,
NamePrefix: namePrefix,
Export: Dash0ExportWithEndpointAndToken(),
KubernetesInfrastructureMetricsCollectionEnabled: false,
}, nil, false)
Expect(err).ToNot(HaveOccurred())
collectorConfig := parseConfigMapContent(configMap)
Expand All @@ -626,12 +626,12 @@ var _ = Describe("The OpenTelemetry Collector ConfigMaps", func() {
Expect(metricsReceivers).ToNot(ContainElement("kubeletstats"))
})

It("should render the kubeletstats receiver if node-level metrics collection is enabled", func() {
It("should render the kubeletstats receiver if kubernetes infrastructure metrics collection is enabled", func() {
configMap, err := assembleDaemonSetCollectorConfigMap(&oTelColConfig{
Namespace: namespace,
NamePrefix: namePrefix,
Export: Dash0ExportWithEndpointAndToken(),
NodeLevelMetricsCollectionEnabled: true,
Namespace: namespace,
NamePrefix: namePrefix,
Export: Dash0ExportWithEndpointAndToken(),
KubernetesInfrastructureMetricsCollectionEnabled: true,
}, nil, false)
Expect(err).ToNot(HaveOccurred())
collectorConfig := parseConfigMapContent(configMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ receivers:
http:
endpoint: "{{ .SelfIpReference }}:4318"

{{- if .NodeLevelMetricsCollectionEnabled }}
{{- if .KubernetesInfrastructureMetricsCollectionEnabled }}
kubeletstats:
auth_type: serviceAccount
collection_interval: 20s
Expand Down Expand Up @@ -396,7 +396,7 @@ service:
metrics/downstream:
receivers:
- otlp
{{- if .NodeLevelMetricsCollectionEnabled }}
{{- if .KubernetesInfrastructureMetricsCollectionEnabled }}
- kubeletstats
{{- end }}
{{- if $hasPrometheusScrapingEnabledForAtLeastOneNamespace }}
Expand Down
Loading

0 comments on commit a850b9f

Please sign in to comment.