-
Notifications
You must be signed in to change notification settings - Fork 326
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
Datadog Integration Acceptance Tests / Bug fixes #3685
Merged
natemollica-nm
merged 33 commits into
main
from
natemollica-nm/datadog-acceptance-testing
Apr 19, 2024
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
8e09172
datadog: acceptance tests - initial commit (not fully working yet)
natemollica-nm cad42f1
server-statefulset: update logic for prometheus annotations (only ena…
natemollica-nm 61d4b2d
datadog: acceptance test working with dd-client api and operator depl…
natemollica-nm bb068a4
datadog-acceptance: main branch rebase merge conflict cherry-pick
natemollica-nm 8a13734
datadog: acceptance testing update to metric name matching using regex
natemollica-nm e60a939
datadog: acceptance testing helper update for backoff retry
natemollica-nm 13b7089
datadog: acceptance testing working timeseries query verification udp…
natemollica-nm 59dccfd
datadog: update helpers for /v1/query
natemollica-nm 7a31b1d
server-statefulset.yaml: update to correct release name prepend to co…
natemollica-nm b14f5db
datadog: acceptance testing consul integration checks working
natemollica-nm 4233e75
server-statefulset: yaml and bats updates for datadog openmetrics and…
natemollica-nm a49b6cb
PR3685: changelog update
natemollica-nm 4b1dbc1
datadog: openmetrics acceptance test update
natemollica-nm 694e9df
datadog: added OTEL_EXPORTER_OTLP_ENDPOINT to consul telemetry collec…
natemollica-nm 11f4603
otlp: datadog otlp acceptance test updates for telemetry-collector (g…
natemollica-nm aa495c4
datadog-acceptance: fake-intake fixture addition
natemollica-nm 3b4287c
datadog-acceptance: update _helpers.tpl for consul version sanitizati…
natemollica-nm 9e77ced
datadog-acceptance: update base fixture for fake-intake
natemollica-nm 401b749
datadog-acceptance: add DogstatsD stats enablement (required for curl…
natemollica-nm 51df717
datadog-acceptance: add DogstatsD stats enablement (required for curl…
natemollica-nm dee86b1
datadog-acceptance: first-round fake-intake testing - works but is in…
natemollica-nm e79c6ea
datadog-acceptance: datadog framework - remove dd client agent requir…
natemollica-nm 88e8a65
datadog-acceptance: update flags to not require API and APP key (fake…
natemollica-nm de58b99
datadog-acceptance: go mod updates for uuid downgrade
natemollica-nm 943f4dd
acceptance-test: remove otlp acceptance test -- no fake-intake or age…
natemollica-nm 47eec97
datadog-acceptance: acceptance test lint fixes
natemollica-nm 0bd8838
acceptance-test: update control-plane/cni/main.go l:272 comment with …
natemollica-nm 0f8cd4f
acceptance-test: retry lint fixes
natemollica-nm 69c81d7
acceptance-test: correct telemetry collector URL from grpc:// to http://
natemollica-nm 70f7390
changelog: non-user facing so remove release note for acceptance test…
natemollica-nm 078c2d0
helm_cluster: datadog secret public to private func
natemollica-nm 91abb5d
datadog-accpetance: operator helm override values removed (wasn't usi…
natemollica-nm 55f94fa
datadog-acceptance: flag refactoring and disable flag update
natemollica-nm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
```release-note:bug | ||
helm: corrected datadog openmetrics and consul-checks consul server URLs set during automation to use full consul deployment release name | ||
``` | ||
```release-note:bug | ||
helm: bug fix for `prometheus.io` annotation omission while using datadog integration with openmetrics/prometheus and consul integration checks | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
package datadog | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/consul-k8s/acceptance/framework/k8s" | ||
"github.com/hashicorp/consul/sdk/testutil/retry" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
"time" | ||
|
||
"github.com/hashicorp/consul-k8s/acceptance/framework/config" | ||
"github.com/hashicorp/consul-k8s/acceptance/framework/helpers" | ||
"github.com/hashicorp/consul-k8s/acceptance/framework/logger" | ||
|
||
"github.com/gruntwork-io/terratest/modules/helm" | ||
terratestk8s "github.com/gruntwork-io/terratest/modules/k8s" | ||
terratestLogger "github.com/gruntwork-io/terratest/modules/logger" | ||
"github.com/hashicorp/consul-k8s/acceptance/framework/environment" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
const ( | ||
releaseLabel = "app.kubernetes.io/name" | ||
OperatorReleaseName = "datadog-operator" | ||
DefaultHelmChartVersion = "1.4.0" | ||
datadogSecretName = "datadog-secret" | ||
datadogAPIKey = "api-key" | ||
datadogAppKey = "app-key" | ||
datadogFakeAPIKey = "DD_FAKEAPIKEY" | ||
datadogFakeAPPKey = "DD_FAKEAPPKEY" | ||
) | ||
|
||
type DatadogCluster struct { | ||
ctx environment.TestContext | ||
|
||
helmOptions *helm.Options | ||
releaseName string | ||
|
||
kubectlOptions *terratestk8s.KubectlOptions | ||
|
||
kubernetesClient kubernetes.Interface | ||
|
||
noCleanupOnFailure bool | ||
noCleanup bool | ||
debugDirectory string | ||
logger terratestLogger.TestLogger | ||
} | ||
|
||
// releaseLabelSelector returns label selector that selects all pods | ||
// from a Datadog installation. | ||
func (d *DatadogCluster) releaseLabelSelector() string { | ||
return fmt.Sprintf("%s=%s", releaseLabel, d.releaseName) | ||
} | ||
|
||
func NewDatadogCluster(t *testing.T, ctx environment.TestContext, cfg *config.TestConfig, releaseName string, releaseNamespace string, helmValues map[string]string) *DatadogCluster { | ||
logger := terratestLogger.New(logger.TestLogger{}) | ||
|
||
configureNamespace(t, ctx.KubernetesClient(t), cfg, releaseNamespace) | ||
|
||
createOrUpdateDatadogSecret(t, ctx.KubernetesClient(t), cfg, releaseNamespace) | ||
|
||
kopts := ctx.KubectlOptionsForNamespace(releaseNamespace) | ||
|
||
values := defaultHelmValues() | ||
|
||
ddHelmChartVersion := DefaultHelmChartVersion | ||
if cfg.DatadogHelmChartVersion != "" { | ||
ddHelmChartVersion = cfg.DatadogHelmChartVersion | ||
} | ||
|
||
helpers.MergeMaps(values, helmValues) | ||
datadogHelmOpts := &helm.Options{ | ||
SetValues: values, | ||
KubectlOptions: kopts, | ||
Logger: logger, | ||
Version: ddHelmChartVersion, | ||
} | ||
|
||
helm.AddRepo(t, datadogHelmOpts, "datadog", "https://helm.datadoghq.com") | ||
// Ignoring the error from `helm repo update` as it could fail due to stale cache or unreachable servers and we're | ||
// asserting a chart version on Install which would fail in an obvious way should this not succeed. | ||
_, err := helm.RunHelmCommandAndGetOutputE(t, &helm.Options{}, "repo", "update") | ||
if err != nil { | ||
logger.Logf(t, "Unable to update helm repository, proceeding anyway: %s.", err) | ||
} | ||
|
||
return &DatadogCluster{ | ||
ctx: ctx, | ||
helmOptions: datadogHelmOpts, | ||
kubectlOptions: kopts, | ||
kubernetesClient: ctx.KubernetesClient(t), | ||
noCleanupOnFailure: cfg.NoCleanupOnFailure, | ||
noCleanup: cfg.NoCleanup, | ||
debugDirectory: cfg.DebugDirectory, | ||
logger: logger, | ||
releaseName: releaseName, | ||
} | ||
} | ||
|
||
func (d *DatadogCluster) Create(t *testing.T) { | ||
t.Helper() | ||
|
||
helpers.Cleanup(t, d.noCleanupOnFailure, d.noCleanup, func() { | ||
d.Destroy(t) | ||
}) | ||
|
||
helm.Install(t, d.helmOptions, "datadog/datadog-operator", d.releaseName) | ||
// Wait for the datadog-operator to become ready | ||
k8s.WaitForAllPodsToBeReady(t, d.kubernetesClient, d.helmOptions.KubectlOptions.Namespace, d.releaseLabelSelector()) | ||
} | ||
|
||
func (d *DatadogCluster) Destroy(t *testing.T) { | ||
t.Helper() | ||
|
||
k8s.WritePodsDebugInfoIfFailed(t, d.kubectlOptions, d.debugDirectory, d.releaseLabelSelector()) | ||
// Ignore the error returned by the helm delete here so that we can | ||
// always idempotent clean up resources in the cluster. | ||
_ = helm.DeleteE(t, d.helmOptions, d.releaseName, true) | ||
} | ||
|
||
func defaultHelmValues() map[string]string { | ||
return map[string]string{ | ||
"replicaCount": "1", | ||
"image.tag": DefaultHelmChartVersion, | ||
"image.repository": "gcr.io/datadoghq/operator", | ||
} | ||
} | ||
|
||
func configureNamespace(t *testing.T, client kubernetes.Interface, cfg *config.TestConfig, namespace string) { | ||
ctx := context.Background() | ||
|
||
ns := &corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: namespace, | ||
Labels: map[string]string{}, | ||
}, | ||
} | ||
if cfg.EnableRestrictedPSAEnforcement { | ||
ns.ObjectMeta.Labels["pod-security.kubernetes.io/enforce"] = "restricted" | ||
ns.ObjectMeta.Labels["pod-security.kubernetes.io/enforce-version"] = "latest" | ||
} | ||
|
||
_, createErr := client.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{}) | ||
if createErr == nil { | ||
logger.Logf(t, "Created namespace %s", namespace) | ||
return | ||
} | ||
|
||
_, updateErr := client.CoreV1().Namespaces().Update(ctx, ns, metav1.UpdateOptions{}) | ||
if updateErr == nil { | ||
logger.Logf(t, "Updated namespace %s", namespace) | ||
return | ||
} | ||
|
||
require.Failf(t, "Failed to create or update namespace", "Namespace=%s, CreateError=%s, UpdateError=%s", namespace, createErr, updateErr) | ||
} | ||
|
||
func createOrUpdateDatadogSecret(t *testing.T, client kubernetes.Interface, cfg *config.TestConfig, namespace string) { | ||
secretMap := map[string]string{ | ||
datadogAPIKey: datadogFakeAPIKey, | ||
datadogAppKey: datadogFakeAPPKey, | ||
} | ||
createMultiKeyK8sSecret(t, client, cfg, namespace, datadogSecretName, secretMap) | ||
} | ||
|
||
func createMultiKeyK8sSecret(t *testing.T, client kubernetes.Interface, cfg *config.TestConfig, namespace, secretName string, secretMap map[string]string) { | ||
retry.RunWith(&retry.Counter{Wait: 2 * time.Second, Count: 15}, t, func(r *retry.R) { | ||
_, err := client.CoreV1().Secrets(namespace).Get(context.Background(), secretName, metav1.GetOptions{}) | ||
if errors.IsNotFound(err) { | ||
_, err := client.CoreV1().Secrets(namespace).Create(context.Background(), &corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: secretName, | ||
}, | ||
StringData: secretMap, | ||
Type: corev1.SecretTypeOpaque, | ||
}, metav1.CreateOptions{}) | ||
require.NoError(r, err) | ||
} else { | ||
require.NoError(r, err) | ||
} | ||
}) | ||
|
||
helpers.Cleanup(t, cfg.NoCleanupOnFailure, cfg.NoCleanup, func() { | ||
_ = client.CoreV1().Secrets(namespace).Delete(context.Background(), secretName, metav1.DeleteOptions{}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
skipDataDogTests
flag altogether - the datadog tests won't run in CI unless we change the YAML we were looking at yesterday.DatadogHelmChartVersion
, so we can just remove it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮💨 my bad, I didn't realize automerge was set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, that's my bad. Sorry 🫤