Skip to content

Commit

Permalink
Add otel test options (#1173)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Earls <[email protected]>
  • Loading branch information
kevinearls authored Sep 9, 2020
1 parent d941663 commit f606719
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 65 deletions.
2 changes: 1 addition & 1 deletion test/e2e/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func getJaegerSimpleProdWithServerUrls(name string, useOtelCollector bool) *v1.J
if useOtelCollector {
logrus.Infof("Using OTEL collector for %s", name)
exampleJaeger.Spec.Collector.Image = otelCollectorImage
exampleJaeger.Spec.Collector.Config = v1.NewFreeForm(getOtelCollectorOptions())
exampleJaeger.Spec.Collector.Config = v1.NewFreeForm(getOtelConfigForHealthCheckPort("14269"))
}

return exampleJaeger
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/self_provisioned_elasticsearch_kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func getJaegerSelfProvisionedESAndKafka(instanceName string, useOtelCollector bo
if useOtelCollector {
logrus.Infof("Using OTEL collector for %s", instanceName)
jaegerInstance.Spec.Collector.Image = otelCollectorImage
jaegerInstance.Spec.Collector.Config = v1.NewFreeForm(getOtelCollectorOptions())
jaegerInstance.Spec.Collector.Config = v1.NewFreeForm(getOtelConfigForHealthCheckPort("14269"))
}

return jaegerInstance
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/self_provisioned_elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func getJaegerSimpleProd(instanceName string, useOtelCollector bool) *v1.Jaeger
if useOtelCollector {
logrus.Infof("Using OTEL collector for %s", instanceName)
exampleJaeger.Spec.Collector.Image = otelCollectorImage
exampleJaeger.Spec.Collector.Config = v1.NewFreeForm(getOtelCollectorOptions())
exampleJaeger.Spec.Collector.Config = v1.NewFreeForm(getOtelConfigForHealthCheckPort("14269"))
}

return exampleJaeger
Expand Down
12 changes: 3 additions & 9 deletions test/e2e/sidecar_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,11 @@ func (suite *SidecarNamespaceTestSuite) TestSidecarNamespace() {
cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}

jaegerInstanceName := "agent-as-sidecar-namespace"
j := getJaegerAgentAsSidecarDefinition(jaegerInstanceName, namespace)
err := fw.Client.Create(goctx.TODO(), j, cleanupOptions)
require.NoError(t, err, "Failed to create jaeger instance")
j := createJaegerAgentAsSidecarInstance(jaegerInstanceName, namespace, testOtelAgent, testOtelAllInOne)
defer undeployJaegerInstance(j)

err = e2eutil.WaitForDeployment(t, fw.KubeClient, namespace, jaegerInstanceName, 1, retryInterval, timeout)
require.NoError(t, err, "Error waiting for Jaeger instance deployment")

dep := getVertxDefinition(map[string]string{})
err = fw.Client.Create(goctx.TODO(), dep, cleanupOptions)
dep := getVertxDefinition(namespace, map[string]string{})
err := fw.Client.Create(goctx.TODO(), dep, cleanupOptions)
require.NoError(t, err, "Failed to create vertx instance")

err = e2eutil.WaitForDeployment(t, fw.KubeClient, namespace, dep.Name, 1, retryInterval, timeout)
Expand All @@ -80,7 +75,6 @@ func (suite *SidecarNamespaceTestSuite) TestSidecarNamespace() {
dep, err = fw.KubeClient.AppsV1().Deployments(namespace).Get(context.Background(), dep.Name, metav1.GetOptions{})
require.NoError(t, err)
hasAgent, _ := inject.HasJaegerAgent(dep)

require.False(t, hasAgent)

nss, err := fw.KubeClient.CoreV1().Namespaces().Get(context.Background(), namespace, metav1.GetOptions{})
Expand Down
79 changes: 48 additions & 31 deletions test/e2e/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http"
"testing"

"github.com/sirupsen/logrus"

framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -65,26 +67,23 @@ func (suite *SidecarTestSuite) AfterTest(suiteName, testName string) {

// Sidecar runs a test with the agent as sidecar
func (suite *SidecarTestSuite) TestSidecar() {

cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}

jaegerInstanceName := "agent-as-sidecar"
j := getJaegerAgentAsSidecarDefinition(jaegerInstanceName, namespace)
undeployJaegerInstance(j)
err := fw.Client.Create(goctx.TODO(), j, cleanupOptions)
require.NoError(t, err, "Failed to create jaeger instance")
firstJaegerInstanceName := "agent-as-sidecar"
firstJaegerInstance := createJaegerAgentAsSidecarInstance(firstJaegerInstanceName, namespace, testOtelAgent, testOtelAllInOne)
defer undeployJaegerInstance(firstJaegerInstance)

err = e2eutil.WaitForDeployment(t, fw.KubeClient, namespace, jaegerInstanceName, 1, retryInterval, timeout)
require.NoError(t, err, "Error waiting for Jaeger instance deployment")
verifyAllInOneImage(firstJaegerInstanceName, namespace, testOtelAllInOne)

dep := getVertxDefinition(map[string]string{inject.Annotation: "true"})
err = fw.Client.Create(goctx.TODO(), dep, cleanupOptions)
vertxDeploymentName := "vertx-create-span-sidecar"
dep := getVertxDefinition(vertxDeploymentName, map[string]string{inject.Annotation: "true"})
err := fw.Client.Create(goctx.TODO(), dep, cleanupOptions)
require.NoError(t, err, "Failed to create vertx instance")
err = e2eutil.WaitForDeployment(t, fw.KubeClient, namespace, vertxDeploymentName, 1, retryInterval, timeout)
// TODO add a check to make sure the sidecar has been injected
require.NoError(t, err, "Failed waiting for"+vertxDeploymentName+" deployment")

err = e2eutil.WaitForDeployment(t, fw.KubeClient, namespace, "vertx-create-span-sidecar", 1, retryInterval, timeout)
require.NoError(t, err, "Failed waiting for vertx-create-span-sidecar deployment")

url, httpClient := getQueryURLAndHTTPClient(jaegerInstanceName, "%s/api/traces?service=order", true)
url, httpClient := getQueryURLAndHTTPClient(firstJaegerInstanceName, "%s/api/traces?service=order", true)
req, err := http.NewRequest(http.MethodGet, url, nil)
require.NoError(t, err, "Failed to create httpRequest")
err = wait.Poll(retryInterval, timeout, func() (done bool, err error) {
Expand All @@ -103,29 +102,25 @@ func (suite *SidecarTestSuite) TestSidecar() {
require.NoError(t, err, "Failed waiting for expected content")

/* Testing other instance */

otherJaegerInstanceName := "agent-as-sidecar2"
j2 := getJaegerAgentAsSidecarDefinition(otherJaegerInstanceName, namespace)
defer undeployJaegerInstance(j2)

err = fw.Client.Create(goctx.TODO(), j2, cleanupOptions)
err = e2eutil.WaitForDeployment(t, fw.KubeClient, namespace, otherJaegerInstanceName, 1, retryInterval, timeout)
require.NoError(t, err, "Error waiting for Jaeger instance deployment")
secondJaegerInstanceName := "agent-as-sidecar2"
secondJaegerInstance := createJaegerAgentAsSidecarInstance(secondJaegerInstanceName, namespace, testOtelAgent, testOtelAllInOne)
defer undeployJaegerInstance(secondJaegerInstance)

persisted := &appsv1.Deployment{}
err = fw.Client.Get(goctx.TODO(), types.NamespacedName{
Name: "vertx-create-span-sidecar",
Name: vertxDeploymentName,
Namespace: namespace,
}, persisted)
require.NoError(t, err, "Error getting jaeger instance")
require.Equal(t, "agent-as-sidecar", persisted.Labels[inject.Label])

err = fw.Client.Delete(goctx.TODO(), j)
err = fw.Client.Delete(goctx.TODO(), firstJaegerInstance)
require.NoError(t, err, "Error deleting instance")
err = e2eutil.WaitForDeletion(t, fw.Client.Client, firstJaegerInstance, retryInterval, timeout)
require.NoError(t, err, "Error waiting for jaeger instance deletion")

url, httpClient = getQueryURLAndHTTPClient(otherJaegerInstanceName, "%s/api/traces?service=order", true)
url, httpClient = getQueryURLAndHTTPClient(secondJaegerInstanceName, "%s/api/traces?service=order", true)
req, err = http.NewRequest(http.MethodGet, url, nil)

err = wait.Poll(retryInterval, timeout, func() (done bool, err error) {
res, err := httpClient.Do(req)
require.NoError(t, err)
Expand All @@ -140,17 +135,18 @@ func (suite *SidecarTestSuite) TestSidecar() {
return len(resp.Data) > 0, nil
})
require.NoError(t, err, "Failed waiting for expected content")
verifyAgentImage(vertxDeploymentName, namespace, testOtelAgent)
}

func getVertxDefinition(annotations map[string]string) *appsv1.Deployment {
selector := map[string]string{"app": "vertx-create-span-sidecar"}
func getVertxDefinition(deploymentName string, annotations map[string]string) *appsv1.Deployment {
selector := map[string]string{"app": deploymentName}
dep := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "vertx-create-span-sidecar",
Name: deploymentName,
Namespace: namespace,
Annotations: annotations,
},
Expand All @@ -165,7 +161,7 @@ func getVertxDefinition(annotations map[string]string) *appsv1.Deployment {
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Image: "jaegertracing/vertx-create-span:operator-e2e-tests",
Name: "vertx-create-span-sidecar",
Name: deploymentName,
Ports: []corev1.ContainerPort{
{
ContainerPort: 8080,
Expand Down Expand Up @@ -197,7 +193,9 @@ func getVertxDefinition(annotations map[string]string) *appsv1.Deployment {
return dep
}

func getJaegerAgentAsSidecarDefinition(name, namespace string) *v1.Jaeger {
func createJaegerAgentAsSidecarInstance(name, namespace string, useOtelAgent, useOtelAllInOne bool) *v1.Jaeger {
cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}

j := &v1.Jaeger{
TypeMeta: metav1.TypeMeta{
Kind: "Jaeger",
Expand Down Expand Up @@ -225,5 +223,24 @@ func getJaegerAgentAsSidecarDefinition(name, namespace string) *v1.Jaeger {
},
},
}

if useOtelAllInOne {
logrus.Infof("Using OTEL AllInOne image for %s", name)
j.Spec.AllInOne.Image = otelAllInOneImage
j.Spec.AllInOne.Config = v1.NewFreeForm(getOtelConfigForHealthCheckPort("14269"))
}

if useOtelAgent {
logrus.Infof("Using OTEL Agent for %s", name)
j.Spec.Agent.Image = otelAgentImage
j.Spec.Agent.Config = v1.NewFreeForm(getOtelConfigForHealthCheckPort("14269"))
}

err := fw.Client.Create(goctx.TODO(), j, cleanupOptions)
require.NoError(t, err, "Failed to create jaeger instance")

err = e2eutil.WaitForDeployment(t, fw.KubeClient, namespace, name, 1, retryInterval, timeout)
require.NoError(t, err, "Error waiting for Jaeger instance deployment")

return j
}
6 changes: 3 additions & 3 deletions test/e2e/streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func jaegerStreamingDefinition(namespace string, name string, useOtelCollector b
if useOtelCollector {
log.Infof("Using OTEL collector for %s", name)
j.Spec.Collector.Image = otelCollectorImage
j.Spec.Collector.Config = v1.NewFreeForm(getOtelCollectorOptions())
j.Spec.Collector.Config = v1.NewFreeForm(getOtelConfigForHealthCheckPort("14269"))
}

return j
Expand Down Expand Up @@ -269,7 +269,7 @@ func jaegerStreamingDefinitionWithTLS(namespace string, name, kafkaUserName stri
if useOtelCollector {
log.Infof("Using OTEL collector for %s", name)
j.Spec.Collector.Image = otelCollectorImage
j.Spec.Collector.Config = v1.NewFreeForm(getOtelCollectorOptions())
j.Spec.Collector.Config = v1.NewFreeForm(getOtelConfigForHealthCheckPort("14269"))
}

return j
Expand Down Expand Up @@ -304,7 +304,7 @@ func jaegerAutoProvisionedDefinition(namespace string, name string, useOtelColle
if useOtelCollector {
log.Infof("Using OTEL collector for %s", name)
jaegerInstance.Spec.Collector.Image = otelCollectorImage
jaegerInstance.Spec.Collector.Config = v1.NewFreeForm(getOtelCollectorOptions())
jaegerInstance.Spec.Collector.Config = v1.NewFreeForm(getOtelConfigForHealthCheckPort("14269"))
}

return jaegerInstance
Expand Down
106 changes: 87 additions & 19 deletions test/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,31 @@ import (
)

var (
retryInterval = time.Second * 5
timeout = time.Duration(getIntEnv("TEST_TIMEOUT", 2)) * time.Minute
storageNamespace = os.Getenv("STORAGE_NAMESPACE")
kafkaNamespace = os.Getenv("KAFKA_NAMESPACE")
debugMode = getBoolEnv("DEBUG_MODE", false)
usingOLM = getBoolEnv("OLM", false)
usingJaegerViaOLM = getBoolEnv("JAEGER_OLM", false)
saveLogs = getBoolEnv("SAVE_LOGS", false)
skipCassandraTests = getBoolEnv("SKIP_CASSANDRA_TESTS", false)
testOtelCollector = getBoolEnv("USE_OTEL_COLLECTOR", false)
retryInterval = time.Second * 5
timeout = time.Duration(getIntEnv("TEST_TIMEOUT", 2)) * time.Minute
storageNamespace = os.Getenv("STORAGE_NAMESPACE")
kafkaNamespace = os.Getenv("KAFKA_NAMESPACE")
debugMode = getBoolEnv("DEBUG_MODE", false)
usingOLM = getBoolEnv("OLM", false)
usingJaegerViaOLM = getBoolEnv("JAEGER_OLM", false)
saveLogs = getBoolEnv("SAVE_LOGS", false)
skipCassandraTests = getBoolEnv("SKIP_CASSANDRA_TESTS", false)
testOtelCollector = getBoolEnv("USE_OTEL_COLLECTOR", false)
testOtelAgent = getBoolEnv("USE_OTEL_AGENT", false)
testOtelAllInOne = getBoolEnv("USE_OTEL_ALL_IN_ONE", false)

esServerUrls = "http://elasticsearch." + storageNamespace + ".svc:9200"
cassandraServiceName = "cassandra." + storageNamespace + ".svc"
cassandraKeyspace = "jaeger_v1_datacenter1"
cassandraDatacenter = "datacenter1"
otelCollectorImage = "jaegertracing/jaeger-opentelemetry-collector:latest"
ctx *framework.TestCtx
fw *framework.Framework
namespace string
t *testing.T
otelAgentImage = "jaegertracing/jaeger-opentelemetry-agent:latest"
otelAllInOneImage = "jaegertracing/opentelemetry-all-in-one:latest"

ctx *framework.TestCtx
fw *framework.Framework
namespace string
t *testing.T
)

func getBoolEnv(key string, defaultValue bool) bool {
Expand Down Expand Up @@ -576,14 +582,76 @@ func wasUsingOtelCollector(jaegerInstanceName, namespace string) bool {
return false
}

func getOtelCollectorOptions() map[string]interface{} {
otelOptions := map[string]interface{}{
func verifyAllInOneImage(jaegerInstanceName, namespace string, expected bool) {
require.Equal(t, expected, wasUsingOtelAllInOne(jaegerInstanceName, namespace))
}

func wasUsingOtelAllInOne(jaegerInstanceName, namespace string) bool {
deployment, err := fw.KubeClient.AppsV1().Deployments(namespace).Get(context.Background(), jaegerInstanceName, metav1.GetOptions{})
require.NoError(t, err)
containers := deployment.Spec.Template.Spec.Containers
for _, container := range containers {
if container.Name == "jaeger" {
logrus.Infof("Test %s is using image %s", t.Name(), container.Image)
return strings.Contains(container.Image, "opentelemetry-all-in-one")
}
}

return false
}

func verifyAgentImage(appName, namespace string, expected bool) {
require.Equal(t, expected, wasUsingOtelAgent(appName, namespace))
}

// Was this Jaeger Instance using the OTEL agent?
func wasUsingOtelAgent(appName, namespace string) bool {
var pods *corev1.PodList
var pod corev1.Pod

// Sometimes the app gets redeployed twice and we can get three pods, wait till there are either 1 or 2
err := wait.Poll(retryInterval, timeout, func() (done bool, err error) {
pods, err = fw.KubeClient.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: "app=" + appName})
require.NoError(t, err)
if len(pods.Items) > 0 && len(pods.Items) < 3 {
return true, nil
}
return false, nil
})
require.NoError(t, err)

if len(pods.Items) == 1 {
logrus.Infof("Found 1 pod %s", pods.Items[0].Name)
pod = pods.Items[0]
} else {
for _, p := range pods.Items {
if p.DeletionTimestamp == nil {
logrus.Infof("Using pod %s", p.Name)
pod = p
} else {
logrus.Infof("Skipping pod %s with deletionTimestamp %v", p.Name, p.DeletionTimestamp)
}
}
}

containers := pod.Spec.Containers
for _, container := range containers {
if container.Name == "jaeger-agent" {
logrus.Infof("Test %s is using agent image %s", t.Name(), container.Image)
return strings.Contains(container.Image, "jaeger-opentelemetry-agent")
}
}

require.Failf(t, "Did not find an agent image for %s in namespace %s", appName, namespace)
return false
}

func getOtelConfigForHealthCheckPort(healthCheckPort string) map[string]interface{} {
return map[string]interface{}{
"extensions": map[string]interface{}{
"health_check": map[string]string{"port": "14269"},
"health_check": map[string]string{"port": healthCheckPort},
},
}

return otelOptions
}

func logWarningEvents() {
Expand Down

0 comments on commit f606719

Please sign in to comment.