Skip to content

Commit

Permalink
test(e2e): restructure tests according to required setup
Browse files Browse the repository at this point in the history
Group e2e test cases by whether they need a deployed operator (or
deploy it as part of the test case), etc. This speeds up the e2e tests
because we do not have to deploy and undeploy the operator and the
monitoring resource as often.

Also, deploy the monitoring resource without export settings for most
test cases, let the operator configuration resource determine the export
at that is the current intended usage.
  • Loading branch information
basti1302 committed Feb 28, 2025
1 parent cc6723d commit 41f3cd1
Show file tree
Hide file tree
Showing 10 changed files with 858 additions and 901 deletions.
2 changes: 1 addition & 1 deletion test-resources/node.js/express/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (process.env.TRIGGER_SELF_AND_EXIT) {
process.exit(1);
}

for (let i = 0; i < 120; i++) {
for (let i = 0; i < 20; i++) {
await fetch(`http://localhost:${port}/dash0-k8s-operator-test?id=${testId}`);
await delay(500);
}
Expand Down
58 changes: 44 additions & 14 deletions test/e2e/dash0_monitoring_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ var (
dash0MonitoringResourceSource string
dash0MonitoringResourceTemplate *template.Template

defaultDash0MonitoringValues = dash0MonitoringValues{
dash0MonitoringValuesDefault = dash0MonitoringValues{
InstrumentWorkloads: dash0v1alpha1.All,
}

dash0MonitoringValuesWithExport = dash0MonitoringValues{
InstrumentWorkloads: dash0v1alpha1.All,
Endpoint: defaultEndpoint,
Token: defaultToken,
InstrumentWorkloads: dash0v1alpha1.All,
}
)

Expand All @@ -65,7 +69,6 @@ func deployDash0MonitoringResource(
namespace string,
dash0MonitoringValues dash0MonitoringValues,
operatorNamespace string,
operatorHelmChart string,
) {
renderedResourceFileName := renderDash0MonitoringResourceTemplate(dash0MonitoringValues)
defer func() {
Expand Down Expand Up @@ -95,18 +98,39 @@ func deployDash0MonitoringResource(
)
Expect(err).ToNot(HaveOccurred())

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

if dash0MonitoringValues.Endpoint != "" {
// Deploying the Dash0 monitoring with an export will trigger creating the OpenTelemetry collector resources,
// assuming there is no operator configuration resource with an export.
waitForCollectorToStart(operatorNamespace, operatorHelmChart)
}
}

func updateEndpointOfDash0MonitoringResource(
namespace string,
newEndpoint string,
) {
updateDash0MonitoringResource(
namespace,
fmt.Sprintf("{\"spec\":{\"export\":{\"dash0\":{\"endpoint\":\"%s\"}}}}", newEndpoint),
)
func waitForMonitoringResourceToBecomeAvailable(namespace string) {
By("waiting for the Dash0 monitoring resource to become available")
Eventually(func(g Gomega) {
g.Expect(
runAndIgnoreOutput(exec.Command(
"kubectl",
"get",
"--namespace",
namespace,
"dash0monitorings.operator.dash0.com/dash0-monitoring-resource-e2e",
))).To(Succeed())
}, 60*time.Second, 1*time.Second).Should(Succeed())
Expect(
runAndIgnoreOutput(exec.Command(
"kubectl",
"wait",
"--namespace",
namespace,
"dash0monitorings.operator.dash0.com/dash0-monitoring-resource-e2e",
"--for",
"condition=Available",
"--timeout",
"30s",
))).To(Succeed())
}

func updateInstrumentWorkloadsModeOfDash0MonitoringResource(
Expand All @@ -115,7 +139,13 @@ func updateInstrumentWorkloadsModeOfDash0MonitoringResource(
) {
updateDash0MonitoringResource(
namespace,
fmt.Sprintf("{\"spec\":{\"instrumentWorkloads\":\"%s\"}}", instrumentWorkloadsMode),
fmt.Sprintf(`
{
"spec": {
"instrumentWorkloads": "%s"
}
}
`, instrumentWorkloadsMode),
)
}

Expand Down
26 changes: 19 additions & 7 deletions test/e2e/dash0_operator_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ var (
//go:embed dash0operatorconfiguration.e2e.yaml.template
dash0OperatorConfigurationResourceSource string
dash0OperatorConfigurationResourceTemplate *template.Template

defaultDash0OperatorConfigurationValues = dash0OperatorConfigurationValues{
SelfMonitoringEnabled: true,
Endpoint: defaultEndpoint,
Token: defaultToken,
}
)

func renderDash0OperatorConfigurationResourceTemplate(
Expand Down Expand Up @@ -75,6 +69,8 @@ func renderDash0OperatorConfigurationResourceTemplate(

func deployDash0OperatorConfigurationResource(
dash0OperatorConfigurationValues dash0OperatorConfigurationValues,
operatorNamespace string,
operatorHelmChart string,
) {
renderedResourceFileName := renderDash0OperatorConfigurationResourceTemplate(dash0OperatorConfigurationValues)
defer func() {
Expand All @@ -90,6 +86,12 @@ func deployDash0OperatorConfigurationResource(
"-f",
renderedResourceFileName,
))).To(Succeed())

if dash0OperatorConfigurationValues.Endpoint != "" {
// Deploying the Dash0 operator configuration resource with an export will trigger creating the default
// OpenTelemetry collector instance.
waitForCollectorToStart(operatorNamespace, operatorHelmChart)
}
}

func waitForAutoOperatorConfigurationResourceToBecomeAvailable() {
Expand Down Expand Up @@ -118,7 +120,17 @@ func updateEndpointOfDash0OperatorConfigurationResource(
newEndpoint string,
) {
updateDash0OperatorConfigurationResource(
fmt.Sprintf("{\"spec\":{\"export\":{\"dash0\":{\"endpoint\":\"%s\"}}}}", newEndpoint),
fmt.Sprintf(`
{
"spec": {
"export": {
"dash0": {
"endpoint": "%s"
}
}
}
}
`, newEndpoint),
)
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/dash0operatorconfiguration.e2e.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ metadata:
spec:
selfMonitoring:
enabled: {{ .SelfMonitoringEnabled }}
{{- if .Endpoint }}
export:
dash0:
endpoint: {{ .Endpoint }}
authorization:
token: {{ .Token }}
{{- end }}
clusterName: {{ .ClusterName }}
Loading

0 comments on commit 41f3cd1

Please sign in to comment.