Skip to content
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
merged 33 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
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 Feb 21, 2024
cad42f1
server-statefulset: update logic for prometheus annotations (only ena…
natemollica-nm Feb 21, 2024
61d4b2d
datadog: acceptance test working with dd-client api and operator depl…
natemollica-nm Feb 21, 2024
bb068a4
datadog-acceptance: main branch rebase merge conflict cherry-pick
natemollica-nm Mar 12, 2024
8a13734
datadog: acceptance testing update to metric name matching using regex
natemollica-nm Feb 22, 2024
e60a939
datadog: acceptance testing helper update for backoff retry
natemollica-nm Feb 22, 2024
13b7089
datadog: acceptance testing working timeseries query verification udp…
natemollica-nm Feb 22, 2024
59dccfd
datadog: update helpers for /v1/query
natemollica-nm Feb 22, 2024
7a31b1d
server-statefulset.yaml: update to correct release name prepend to co…
natemollica-nm Feb 23, 2024
b14f5db
datadog: acceptance testing consul integration checks working
natemollica-nm Feb 23, 2024
4233e75
server-statefulset: yaml and bats updates for datadog openmetrics and…
natemollica-nm Feb 23, 2024
a49b6cb
PR3685: changelog update
natemollica-nm Feb 23, 2024
4b1dbc1
datadog: openmetrics acceptance test update
natemollica-nm Feb 23, 2024
694e9df
datadog: added OTEL_EXPORTER_OTLP_ENDPOINT to consul telemetry collec…
natemollica-nm Feb 23, 2024
11f4603
otlp: datadog otlp acceptance test updates for telemetry-collector (g…
natemollica-nm Feb 24, 2024
aa495c4
datadog-acceptance: fake-intake fixture addition
natemollica-nm Apr 3, 2024
3b4287c
datadog-acceptance: update _helpers.tpl for consul version sanitizati…
natemollica-nm Apr 3, 2024
9e77ced
datadog-acceptance: update base fixture for fake-intake
natemollica-nm Apr 3, 2024
401b749
datadog-acceptance: add DogstatsD stats enablement (required for curl…
natemollica-nm Apr 3, 2024
51df717
datadog-acceptance: add DogstatsD stats enablement (required for curl…
natemollica-nm Apr 3, 2024
dee86b1
datadog-acceptance: first-round fake-intake testing - works but is in…
natemollica-nm Apr 3, 2024
e79c6ea
datadog-acceptance: datadog framework - remove dd client agent requir…
natemollica-nm Apr 3, 2024
88e8a65
datadog-acceptance: update flags to not require API and APP key (fake…
natemollica-nm Apr 3, 2024
de58b99
datadog-acceptance: go mod updates for uuid downgrade
natemollica-nm Apr 3, 2024
943f4dd
acceptance-test: remove otlp acceptance test -- no fake-intake or age…
natemollica-nm Apr 4, 2024
47eec97
datadog-acceptance: acceptance test lint fixes
natemollica-nm Apr 5, 2024
0bd8838
acceptance-test: update control-plane/cni/main.go l:272 comment with …
natemollica-nm Apr 5, 2024
0f8cd4f
acceptance-test: retry lint fixes
natemollica-nm Apr 5, 2024
69c81d7
acceptance-test: correct telemetry collector URL from grpc:// to http://
natemollica-nm Apr 5, 2024
70f7390
changelog: non-user facing so remove release note for acceptance test…
natemollica-nm Apr 17, 2024
078c2d0
helm_cluster: datadog secret public to private func
natemollica-nm Apr 17, 2024
91abb5d
datadog-accpetance: operator helm override values removed (wasn't usi…
natemollica-nm Apr 17, 2024
55f94fa
datadog-acceptance: flag refactoring and disable flag update
natemollica-nm Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/3685.txt
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
```
3 changes: 3 additions & 0 deletions acceptance/framework/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type TestConfig struct {
EnableEnterprise bool
EnterpriseLicense string

SkipDataDogTests bool
DatadogHelmChartVersion string
Comment on lines +73 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think we can get rid of the skipDataDogTests flag altogether - the datadog tests won't run in CI unless we change the YAML we were looking at yesterday.
  2. I think there is no way to set DatadogHelmChartVersion, so we can just remove it.

Copy link
Contributor

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.

Copy link
Contributor Author

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 🫤


EnableOpenshift bool

EnablePodSecurityPolicies bool
Expand Down
1 change: 0 additions & 1 deletion acceptance/framework/consul/helm_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func (h *HelmCluster) Create(t *testing.T) {
if h.ChartPath != "" {
chartName = h.ChartPath
}

// Retry the install in case previous tests have not finished cleaning up.
retry.RunWith(&retry.Counter{Wait: 2 * time.Second, Count: 30}, t, func(r *retry.R) {
err := helm.InstallE(r, h.helmOptions, chartName, h.releaseName)
Expand Down
190 changes: 190 additions & 0 deletions acceptance/framework/datadog/datadog.go
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{})
})
}
9 changes: 7 additions & 2 deletions acceptance/framework/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type TestFlags struct {

flagEnableOpenshift bool

flagSkipDatadogTests bool

flagEnablePodSecurityPolicies bool

flagEnableCNI bool
Expand Down Expand Up @@ -155,6 +157,9 @@ func (t *TestFlags) init() {
flag.BoolVar(&t.flagDisablePeering, "disable-peering", false,
"If true, the peering tests will not run.")

flag.BoolVar(&t.flagSkipDatadogTests, "skip-datadog", false,
"If true, datadog acceptance tests will not run.")

if t.flagEnterpriseLicense == "" {
t.flagEnterpriseLicense = os.Getenv("CONSUL_ENT_LICENSE")
}
Expand Down Expand Up @@ -198,11 +203,9 @@ func (t *TestFlags) TestConfigFromFlags() *config.TestConfig {
// if the Version is empty consulVersion will be nil
consulVersion, _ := version.NewVersion(t.flagConsulVersion)
consulDataplaneVersion, _ := version.NewVersion(t.flagConsulDataplaneVersion)
//vaultserverVersion, _ := version.NewVersion(t.flagVaultServerVersion)
kubeEnvs := config.NewKubeTestConfigList(t.flagKubeconfigs, t.flagKubecontexts, t.flagKubeNamespaces)

c := &config.TestConfig{

EnableEnterprise: t.flagEnableEnterprise,
EnterpriseLicense: t.flagEnterpriseLicense,

Expand All @@ -211,6 +214,8 @@ func (t *TestFlags) TestConfigFromFlags() *config.TestConfig {

EnableOpenshift: t.flagEnableOpenshift,

SkipDataDogTests: t.flagSkipDatadogTests,

EnablePodSecurityPolicies: t.flagEnablePodSecurityPolicies,

EnableCNI: t.flagEnableCNI,
Expand Down
Loading
Loading