Skip to content

Commit

Permalink
test(e2e): test creation of operator config resource via Helm values
Browse files Browse the repository at this point in the history
Also: Use a dash0 exporter in e2e tests instead of an http exporter.
  • Loading branch information
basti1302 committed Sep 18, 2024
1 parent 6930991 commit 89a496a
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type OtlpExporter struct {
Endpoint string
Headers []dash0v1alpha1.Header
Encoding string
Insecure bool
}

var (
Expand Down Expand Up @@ -126,11 +127,13 @@ func ConvertExportSettingsToExporterList(export dash0v1alpha1.Export) ([]OtlpExp
Value: d0.Dataset,
})
}
exporters = append(exporters, OtlpExporter{
dash0Exporter := OtlpExporter{
Name: "otlp/dash0",
Endpoint: export.Dash0.Endpoint,
Headers: headers,
})
}
setGrpcTls(export.Dash0.Endpoint, &dash0Exporter)
exporters = append(exporters, dash0Exporter)
}

if export.Grpc != nil {
Expand All @@ -143,6 +146,7 @@ func ConvertExportSettingsToExporterList(export dash0v1alpha1.Export) ([]OtlpExp
Endpoint: grpc.Endpoint,
Headers: grpc.Headers,
}
setGrpcTls(grpc.Endpoint, &grpcExporter)
if grpc.Headers != nil && len(grpc.Headers) > 0 {
grpcExporter.Headers = grpc.Headers
}
Expand Down Expand Up @@ -182,3 +186,9 @@ func renderCollectorConfiguration(
}
return collectorConfiguration.String(), nil
}

func setGrpcTls(endpoint string, exporter *OtlpExporter) {
if endpoint == "otlp-sink.otlp-sink.svc.cluster.local:4317" {
exporter.Insecure = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ exporters:
{{- range $i, $exporter := .Exporters }}
{{ $exporter.Name }}:
endpoint: "{{ $exporter.Endpoint }}"
{{ if $exporter.Insecure }}
tls:
insecure: true
{{ end }}
{{- if $exporter.Headers }}
headers:
{{- range $i, $header := $exporter.Headers }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ exporters:
{{- range $i, $exporter := .Exporters }}
{{ $exporter.Name }}:
endpoint: "{{ $exporter.Endpoint }}"
{{ if $exporter.Insecure }}
tls:
insecure: true
{{ end }}
{{- if $exporter.Headers }}
headers:
{{- range $i, $header := $exporter.Headers }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

dash0v1alpha1 "github.com/dash0hq/dash0-operator/api/dash0monitoring/v1alpha1"

"github.com/dash0hq/dash0-operator/internal/dash0/util"
)

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
collectorConfigMapNameQualified = fmt.Sprintf("configmap/%s", collectorConfigMapName)
)

func verifyThatCollectorIsRunning(operatorNamespace string, operatorHelmChart string) {
func waitForCollectorToStart(operatorNamespace string, operatorHelmChart string) {
By("validating that the OpenTelemetry collector has been created and is running as expected")
verifyCollectorIsUp := func(g Gomega) {
// Even though this command comes with its own timeout, we still have to wrap it in an Eventually block, since
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/dash0_monitoring_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
type dash0MonitoringValues struct {
InstrumentWorkloads dash0v1alpha1.InstrumentWorkloadsMode
Endpoint string
Token string
}

const (
dash0MonitoringResourceName = "dash0-monitoring-resource-e2e"
defaultEndpoint = "http://otlp-sink.otlp-sink.svc.cluster.local:4318"
)

var (
Expand All @@ -34,6 +34,7 @@ var (

defaultDash0MonitoringValues = dash0MonitoringValues{
Endpoint: defaultEndpoint,
Token: defaultToken,
InstrumentWorkloads: dash0v1alpha1.All,
}
)
Expand Down Expand Up @@ -69,7 +70,7 @@ func deployDash0MonitoringResource(
}()

By(fmt.Sprintf(
"Deploying the Dash0 monitoring resource to namespace %s with values %v, operator namespace is %s",
"deploying the Dash0 monitoring resource to namespace %s with values %v, operator namespace is %s",
namespace, dash0MonitoringValues, operatorNamespace))
Expect(
runAndIgnoreOutput(exec.Command(
Expand All @@ -82,7 +83,7 @@ func deployDash0MonitoringResource(
))).To(Succeed())

// Deploying the Dash0 monitoring resource will trigger creating the default OpenTelemetry collecor instance.
verifyThatCollectorIsRunning(operatorNamespace, operatorHelmChart)
waitForCollectorToStart(operatorNamespace, operatorHelmChart)
}

func updateEndpointOfDash0MonitoringResource(
Expand Down Expand Up @@ -132,7 +133,7 @@ func truncateExportedTelemetry() {
}

func undeployDash0MonitoringResource(namespace string) {
By(fmt.Sprintf("Removing the Dash0 monitoring resource from namespace %s", namespace))
By(fmt.Sprintf("removing the Dash0 monitoring resource from namespace %s", namespace))
Expect(
runAndIgnoreOutput(exec.Command(
"kubectl",
Expand Down
35 changes: 33 additions & 2 deletions test/e2e/dash0_operator_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"text/template"
"time"

. "github.com/onsi/ginkgo/v2" //nolint:golint,revive
. "github.com/onsi/gomega"
Expand All @@ -18,10 +19,17 @@ import (
type dash0OperatorConfigurationValues struct {
SelfMonitoringEnabled bool
Endpoint string
Token string
}

const (
dash0OperatorConfigurationResourceName = "dash0-operator-configuration-resource-e2e"

defaultEndpoint = "otlp-sink.otlp-sink.svc.cluster.local:4317"

// We only need a non-empty token to pass the validation in startup.auto_operator_configuration_handler.go,
// we do not actually send data to a Dash0 backend so no real token is required.
defaultToken = "dummy-token"
)

var (
Expand All @@ -32,6 +40,7 @@ var (
defaultDash0OperatorConfigurationValues = dash0OperatorConfigurationValues{
SelfMonitoringEnabled: true,
Endpoint: defaultEndpoint,
Token: defaultToken,
}
)

Expand Down Expand Up @@ -67,7 +76,7 @@ func deployDash0OperatorConfigurationResource(
}()

By(fmt.Sprintf(
"Deploying the Dash0 operator configuration resource with values %v", dash0OperatorConfigurationValues))
"deploying the Dash0 operator configuration resource with values %v", dash0OperatorConfigurationValues))
Expect(
runAndIgnoreOutput(exec.Command(
"kubectl",
Expand All @@ -77,8 +86,30 @@ func deployDash0OperatorConfigurationResource(
))).To(Succeed())
}

func waitForAutoOperatorConfigurationResourceToBecomeAvailable() {
By("waiting for the automatically create Dash0 operator configuration resource to become available")
Eventually(func(g Gomega) {
g.Expect(
runAndIgnoreOutput(exec.Command(
"kubectl",
"get",
"dash0operatorconfigurations.operator.dash0.com/dash0-operator-configuration-auto-resource",
))).To(Succeed())
}, 30*time.Second, 1*time.Second).Should(Succeed())
Expect(
runAndIgnoreOutput(exec.Command(
"kubectl",
"wait",
"dash0operatorconfigurations.operator.dash0.com/dash0-operator-configuration-auto-resource",
"--for",
"condition=Available",
"--timeout",
"30s",
))).To(Succeed())
}

func undeployDash0OperatorConfigurationResource() {
By("Removing the Dash0 operator configuration resource")
By("removing the Dash0 operator configuration resource")
Expect(
runAndIgnoreOutput(exec.Command(
"kubectl",
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/dash0monitoring.e2e.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ metadata:
name: dash0-monitoring-resource-e2e
spec:
instrumentWorkloads: {{ .InstrumentWorkloads }}
{{- if .Endpoint }}
{{- if .Endpoint }}
export:
# In the e2e tests we only want to export to the local otlp-sink collector. Since the Dash0 exporter config uses
# gRPC, and gRPC requires a TLS connection, we are configuring the local otlp-sink collector via HTTP instead.
http:
dash0:
endpoint: {{ .Endpoint }}
{{- end }}
authorization:
token: {{ .Token }}
{{- end }}
4 changes: 3 additions & 1 deletion test/e2e/dash0operatorconfiguration.e2e.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ spec:
selfMonitoring:
enabled: {{ .SelfMonitoringEnabled }}
export:
http:
dash0:
endpoint: {{ .Endpoint }}
authorization:
token: {{ .Token }}
Loading

0 comments on commit 89a496a

Please sign in to comment.