Skip to content

Commit

Permalink
chore(crd): make export attribute optional in monitoring resource
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Sep 13, 2024
1 parent 719a282 commit de608af
Show file tree
Hide file tree
Showing 19 changed files with 214 additions and 204 deletions.
17 changes: 11 additions & 6 deletions api/dash0monitoring/v1alpha1/dash0monitoring_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ const (
// Dash0MonitoringSpec describes the details of monitoring a single Kubernetes namespace with Dash0 and sending
// telemetry to an observability backend.
type Dash0MonitoringSpec struct {
// The configuration of the observability backend to which telemetry data will be sent. This property is mandatory.
// This can either be Dash0 or another OTLP-compatible backend. You can also combine up to three exporters (i.e.
// Dash0 plus gRPC plus HTTP). This allows sending the same data to two or three targets simultaneously. At least
// one exporter has to be defined.
// The configuration of the observability backend to which telemetry data will be sent. This property is optional.
// If not set, the operator will use the default export configuration from the cluster-wide
// Dash0OperatorConfiguration resource, if present. If no Dash0OperatorConfiguration resource has been created for
// the cluster, or if the Dash0OperatorConfiguration resource does not have at least one export defined, creating a
// Dash0Monitoring resource without export settings will result in an error.
//
// +kubebuilder:validation:Required
Export `json:"export"`
// The export can either be Dash0 or another OTLP-compatible backend. You can also combine up to three exporters
// (i.e. Dash0 plus gRPC plus HTTP). This allows sending the same data to two or three targets simultaneously. When
// the export setting is present, it has to contain at least one exporter.
//
// +kubebuilder:validation:Optional
Export *Export `json:"export"`

// Global opt-out for workload instrumentation for the target namespace. There are three possible settings: `all`,
// `created-and-updated` and `none`. By default, the setting `all` is assumed.
Expand Down
6 changes: 5 additions & 1 deletion api/dash0monitoring/v1alpha1/zz_generated.deepcopy.go

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

16 changes: 10 additions & 6 deletions config/crd/bases/operator.dash0.com_dash0monitorings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ spec:
properties:
export:
description: |-
The configuration of the observability backend to which telemetry data will be sent. This property is mandatory.
This can either be Dash0 or another OTLP-compatible backend. You can also combine up to three exporters (i.e.
Dash0 plus gRPC plus HTTP). This allows sending the same data to two or three targets simultaneously. At least
one exporter has to be defined.
The configuration of the observability backend to which telemetry data will be sent. This property is optional.
If not set, the operator will use the default export configuration from the cluster-wide
Dash0OperatorConfiguration resource, if present. If no Dash0OperatorConfiguration resource has been created for
the cluster, or if the Dash0OperatorConfiguration resource does not have at least one export defined, creating a
Dash0Monitoring resource without export settings will result in an error.
The export can either be Dash0 or another OTLP-compatible backend. You can also combine up to three exporters
(i.e. Dash0 plus gRPC plus HTTP). This allows sending the same data to two or three targets simultaneously. When
the export setting is present, it has to contain at least one exporter.
minProperties: 1
properties:
dash0:
Expand Down Expand Up @@ -207,8 +213,6 @@ spec:
- created-and-updated
- none
type: string
required:
- export
type: object
status:
description: Dash0MonitoringStatus defines the observed state of the Dash0Monitoring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ spec:
properties:
export:
description: |-
The configuration of the observability backend to which telemetry data will be sent. This property is mandatory.
This can either be Dash0 or another OTLP-compatible backend. You can also combine up to three exporters (i.e.
Dash0 plus gRPC plus HTTP). This allows sending the same data to two or three targets simultaneously. At least
one exporter has to be defined.
The configuration of the observability backend to which telemetry data will be sent. This property is optional.
If not set, the operator will use the default export configuration from the cluster-wide
Dash0OperatorConfiguration resource, if present. If no Dash0OperatorConfiguration resource has been created for
the cluster, or if the Dash0OperatorConfiguration resource does not have at least one export defined, creating a
Dash0Monitoring resource without export settings will result in an error.
The export can either be Dash0 or another OTLP-compatible backend. You can also combine up to three exporters
(i.e. Dash0 plus gRPC plus HTTP). This allows sending the same data to two or three targets simultaneously. When
the export setting is present, it has to contain at least one exporter.
minProperties: 1
properties:
dash0:
Expand Down Expand Up @@ -207,8 +213,6 @@ spec:
- created-and-updated
- none
type: string
required:
- export
type: object
status:
description: Dash0MonitoringStatus defines the observed state of the Dash0Monitoring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ custom resource definition should match snapshot:
properties:
export:
description: |-
The configuration of the observability backend to which telemetry data will be sent. This property is mandatory.
This can either be Dash0 or another OTLP-compatible backend. You can also combine up to three exporters (i.e.
Dash0 plus gRPC plus HTTP). This allows sending the same data to two or three targets simultaneously. At least
one exporter has to be defined.
The configuration of the observability backend to which telemetry data will be sent. This property is optional.
If not set, the operator will use the default export configuration from the cluster-wide
Dash0OperatorConfiguration resource, if present. If no Dash0OperatorConfiguration resource has been created for
the cluster, or if the Dash0OperatorConfiguration resource does not have at least one export defined, creating a
Dash0Monitoring resource without export settings will result in an error.


The export can either be Dash0 or another OTLP-compatible backend. You can also combine up to three exporters
(i.e. Dash0 plus gRPC plus HTTP). This allows sending the same data to two or three targets simultaneously. When
the export setting is present, it has to contain at least one exporter.
minProperties: 1
properties:
dash0:
Expand Down Expand Up @@ -195,8 +201,6 @@ custom resource definition should match snapshot:
- created-and-updated
- none
type: string
required:
- export
type: object
status:
description: Dash0MonitoringStatus defines the observed state of the Dash0Monitoring monitoring resource.
Expand Down
54 changes: 32 additions & 22 deletions internal/backendconnection/backend_connection_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"slices"

"github.com/go-logr/logr"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand All @@ -21,7 +22,6 @@ import (

dash0v1alpha1 "github.com/dash0hq/dash0-operator/api/dash0monitoring/v1alpha1"
"github.com/dash0hq/dash0-operator/internal/backendconnection/otelcolresources"
"github.com/dash0hq/dash0-operator/internal/dash0/selfmonitoring"
"github.com/dash0hq/dash0-operator/internal/dash0/util"
)

Expand Down Expand Up @@ -117,35 +117,20 @@ func (r *BackendConnectionReconciler) Reconcile(
logger := log.FromContext(ctx)
logger.Info("reconciling backend connection resources", "request", request)

allDash0MonitoringResouresInCluster := &dash0v1alpha1.Dash0MonitoringList{}
if err := r.List(
ctx,
allDash0MonitoringResouresInCluster,
&client.ListOptions{},
); err != nil {
logger.Error(err, "Failed to list all Dash0 monitoring resources when reconciling backend connection resources.")
arbitraryMonitoringResource, err := r.findArbitraryMonitoringResource(ctx, &logger)
if err != nil {
return reconcile.Result{}, err
}

if len(allDash0MonitoringResouresInCluster.Items) == 0 {
logger.Info("No Dash0 monitoring resources in cluster, aborting the backend connection resources reconciliation.")
} else if arbitraryMonitoringResource == nil {
return reconcile.Result{}, nil
}

// TODO this needs to be fixed when we start to support sending telemetry to different backends per namespace.
// Ultimately we need to derive one consistent configuration including multiple pipelines and routing across all
// monitored namespaces.
arbitraryMonitoringResource := allDash0MonitoringResouresInCluster.Items[0]

err := r.BackendConnectionManager.EnsureOpenTelemetryCollectorIsDeployedInOperatorNamespace(
if err = r.BackendConnectionManager.EnsureOpenTelemetryCollectorIsDeployedInOperatorNamespace(
ctx,
r.Images,
r.OperatorNamespace,
&arbitraryMonitoringResource,
selfmonitoring.ReadSelfMonitoringConfigurationFromOperatorConfigurationResource(ctx, r.Client, &logger),
arbitraryMonitoringResource,
TriggeredByWatchEvent,
)
if err != nil {
); err != nil {
logger.Error(err, "Failed to create/update backend connection resources.")
return reconcile.Result{}, err
}
Expand All @@ -158,3 +143,28 @@ func (r *BackendConnectionReconciler) Reconcile(

return reconcile.Result{}, nil
}

func (r *BackendConnectionReconciler) findArbitraryMonitoringResource(
ctx context.Context,
logger *logr.Logger,
) (*dash0v1alpha1.Dash0Monitoring, error) {
allDash0MonitoringResouresInCluster := &dash0v1alpha1.Dash0MonitoringList{}
if err := r.List(
ctx,
allDash0MonitoringResouresInCluster,
&client.ListOptions{},
); err != nil {
logger.Error(err, "Failed to list all Dash0 monitoring resources when reconciling backend connection resources.")
return nil, err
}

if len(allDash0MonitoringResouresInCluster.Items) == 0 {
logger.Info("No Dash0 monitoring resources in cluster, aborting the backend connection resources reconciliation.")
return nil, nil
}

// TODO this needs to be fixed when we start to support sending telemetry to different backends per namespace.
// Ultimately we need to derive one consistent configuration including multiple pipelines and routing across all
// monitored namespaces.
return &allDash0MonitoringResouresInCluster.Items[0], nil
}
8 changes: 0 additions & 8 deletions internal/backendconnection/backendconnection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

dash0v1alpha1 "github.com/dash0hq/dash0-operator/api/dash0monitoring/v1alpha1"
"github.com/dash0hq/dash0-operator/internal/backendconnection/otelcolresources"
"github.com/dash0hq/dash0-operator/internal/dash0/selfmonitoring"
"github.com/dash0hq/dash0-operator/internal/dash0/util"
)

Expand All @@ -38,7 +37,6 @@ func (m *BackendConnectionManager) EnsureOpenTelemetryCollectorIsDeployedInOpera
images util.Images,
operatorNamespace string,
monitoringResource *dash0v1alpha1.Dash0Monitoring,
selfMonitoringConfiguration selfmonitoring.SelfMonitoringConfiguration,
trigger BackendConnectionReconcileTrigger,
) error {
logger := log.FromContext(ctx)
Expand Down Expand Up @@ -74,7 +72,6 @@ func (m *BackendConnectionManager) EnsureOpenTelemetryCollectorIsDeployedInOpera
operatorNamespace,
images,
monitoringResource,
selfMonitoringConfiguration,
&logger,
)

Expand All @@ -97,10 +94,8 @@ func (m *BackendConnectionManager) EnsureOpenTelemetryCollectorIsDeployedInOpera

func (m *BackendConnectionManager) RemoveOpenTelemetryCollectorIfNoMonitoringResourceIsLeft(
ctx context.Context,
images util.Images,
operatorNamespace string,
dash0MonitoringResourceToBeDeleted *dash0v1alpha1.Dash0Monitoring,
selfMonitoringConfiguration selfmonitoring.SelfMonitoringConfiguration,
) error {
m.resourcesHaveBeenDeletedByOperator.Store(true)
m.updateInProgress.Store(true)
Expand Down Expand Up @@ -156,9 +151,6 @@ func (m *BackendConnectionManager) RemoveOpenTelemetryCollectorIfNoMonitoringRes
if err = m.OTelColResourceManager.DeleteResources(
ctx,
operatorNamespace,
images,
dash0MonitoringResourceToBeDeleted,
selfMonitoringConfiguration,
&logger,
); err != nil {
logger.Error(
Expand Down
Loading

0 comments on commit de608af

Please sign in to comment.