Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ JAEGER_GRPC_PORT=4317
PROMETHEUS_PORT=9090
PROMETHEUS_HOST=prometheus
PROMETHEUS_ADDR=${PROMETHEUS_HOST}:${PROMETHEUS_PORT}
BASHUNIT_BOOTSTRAP=test/elastic/bootstrap.sh
2 changes: 2 additions & 0 deletions .env.bashunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BASHUNIT_DEFAULT_PATH=test/elastic
BASHUNIT_BOOTSTRAP="${BASHUNIT_DEFAULT_PATH}/bootstrap.sh"
41 changes: 41 additions & 0 deletions .github/workflows/run-integration-tests-elastic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Elastic Integration Tests

on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened]
paths-ignore:
- '.github/README.md'

permissions:
contents: read

jobs:
run-tests:
name: Test
runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Compose
uses: docker/setup-compose-action@v1

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1

- name: Set up helm
uses: azure/[email protected]

- name: Install bashunit
run: |
curl -s https://bashunit.typeddevs.com/install.sh | bash

- name: Run the tests
run: |
./lib/bashunit --env .env.bashunit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ test/tracetesting/tracetesting-vars.yaml
*.apk

!src/currency/build

#Bash unit
lib/
67 changes: 42 additions & 25 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ DOCKER_COLLECTOR_CONFIG_CLOUD='./src/otel-collector/otelcol-elastic-config.yaml'
DOCKER_COLLECTOR_CONFIG_SERVERLESS='./src/otel-collector/otelcol-elastic-otlp-config.yaml'
COLLECTOR_CONTRIB_IMAGE=docker.elastic.co/elastic-agent/elastic-agent:$ELASTIC_STACK_VERSION


# Variables
deployment_type=""
platform=""
Expand All @@ -33,13 +32,37 @@ elasticsearch_endpoint=""
elasticsearch_api_key=""

usage() {
echo "Usage: $0 [cloud-hosted|serverless] [docker|k8s] | destroy [docker|k8s]"
echo "Run the script with no arguments. This will start an interactive prompt that will guide you through the setup of the Elastic OpenTelemetry Demo."
echo
echo "To destroy the demo, run: $0 destroy [docker|k8s]"
echo " - pass 'docker' or 'k8s' to destroy only that platform"
echo " - omit the platform to destroy both docker and k8s resources"
exit 1
}

parse_args() {
if [ $# -eq 0 ]; then
usage

while true; do
echo
printf "❓ Which Elasticsearch deployment type do you want to send the data into? [serverless/cloud-hosted]? "
read -r deployment_type
case "$deployment_type" in
cloud-hosted|serverless) break ;;
*) echo "Please enter 'cloud-hosted' or 'serverless'." ;;
esac
done

while true; do
echo
printf "❓ In which environment the demo should be deployed? [docker/k8s]?"
read -r platform
case "$platform" in
docker|k8s) break ;;
*) echo "Please enter 'docker' or 'k8s'." ;;
esac
done
return
fi

if [ "$1" = "destroy" ]; then
Expand All @@ -49,21 +72,22 @@ parse_args() {
fi
return
fi

deployment_type="$1"
if [ $# -ge 2 ]; then
platform="$2"
fi
usage
}

update_env_var() {
VAR="$1"
VAL="$2"
VAR=$1
VAL=$2
tmp=$(mktemp) || exit 1

if grep -q "^$VAR=" "$ENV_OVERRIDE_FILE"; then
sed -i '' "s|^$VAR=.*|$VAR=\"$VAL\"|" "$ENV_OVERRIDE_FILE"
sed "s|^$VAR=.*|$VAR=\"$VAL\"|" "$ENV_OVERRIDE_FILE" >"$tmp"
else
echo "$VAR=\"$VAL\"" >> "$ENV_OVERRIDE_FILE"
cat "$ENV_OVERRIDE_FILE" >"$tmp"
echo "$VAR=\"$VAL\"" >>"$tmp"
fi

mv "$tmp" "$ENV_OVERRIDE_FILE"
}

# Read a secret from the terminal without echo and assign it to a variable by name
Expand Down Expand Up @@ -190,46 +214,39 @@ destroy_k8s() {
}

main() {
parse_args "$@"

echo '----------------------------------------------------'
echo '🚀 OpenTelemetry Demo with Elastic Observability'
echo '----------------------------------------------------'

parse_args "$@"

if [ "$destroy" = "true" ]; then
if [ -z "$platform" ]; then
echo "⌛️ Destroying Docker and Kubernetes resources..."
destroy_docker
destroy_k8s
echo "✅ Done! Destroyed Docker and Kubernetes resources."
return 0
exit 0
fi

if [ "$platform" = "docker" ]; then
echo "⌛️ Destroying Docker resources..."
destroy_docker
echo "✅ Done! Destroyed Docker resources."
return 0
exit 0
fi

if [ "$platform" = "k8s" ]; then
echo "⌛️ Destroying Kubernetes resources..."
destroy_k8s
echo "✅ Done! Destroyed Kubernetes resources."
return 0
exit 0
fi

usage
fi

if [ "$deployment_type" != "cloud-hosted" ] && [ "$deployment_type" != "serverless" ]; then
usage
fi

if [ "$platform" != "docker" ] && [ "$platform" != "k8s" ]; then
usage
fi

echo
echo "⌛️ Starting OTel Demo + EDOT on '$platform' → Elastic ($deployment_type)..."
echo
if [ "$platform" = "docker" ]; then
Expand Down
57 changes: 57 additions & 0 deletions test/elastic/basic_docker_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

set -e -o pipefail

source "${CURRENT_DIR}/test/elastic/utils.sh"

function set_up_before_script() {
start_local_elastic_stack
}

function tear_down_after_script() {
uninstall_local_elastic_stack
}

function test_launch_demo_docker() {
launch_demo "cloud-hosted" "docker"
}

function test_check_docker_service_running() {
local services=(
"accounting"
"ad"
"cart"
"checkout"
"currency"
"email"
"fraud-detection"
"frontend"
"frontend-proxy"
"image-provider"
"load-generator"
"payment"
"product-catalog"
"quote"
"recommendation"
"shipping"
"flagd"
"flagd-ui"
"kafka"
"postgresql"
"valkey-cart"
"jaeger"
"grafana"
"otel-collector"
"prometheus"
"opensearch"
)

for service in "${services[@]}"; do
assert_exit_code "0" "$(check_docker_service_running "$service")"
done
}

function test_destroy_demo_docker() {
destroy_demo "docker"
}

23 changes: 23 additions & 0 deletions test/elastic/basic_k8s_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -e -o pipefail

source "${CURRENT_DIR}/test/elastic/utils.sh"


function set_up_before_script() {
start_local_elastic_stack
}

function tear_down_after_script() {
uninstall_local_elastic_stack
}

function test_launch_demo_k8s() {
launch_demo "cloud-hosted" "k8s"
}

function test_destroy_demo_k8s() {
destroy_demo "k8s"
}

9 changes: 9 additions & 0 deletions test/elastic/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
# Place your common test setup here

CURRENT_DIR=$(pwd)
export CURRENT_DIR
export START_LOCAL_DIR="${CURRENT_DIR}/elastic-start-local"
export START_LOCAL_ENV_PATH="${START_LOCAL_DIR}/.env"
export START_LOCAL_UNINSTALL_FILE="${START_LOCAL_DIR}/uninstall.sh"
76 changes: 76 additions & 0 deletions test/elastic/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

set -e -o pipefail

# Returns the HTTP status code from a call
# usage: get_http_response_code url username password
function get_http_response_code() {
url=$1
if [ -z "$url" ]; then
echo "Error: you need to specify the URL for get the HTTP response"
exit 1
fi
username=$2
password=$3

if [ -z "$username" ] || [ -z "$password" ]; then
result=$(curl -LI "$url" -o /dev/null -w '%{http_code}\n' -s)
else
result=$(curl -LI -u "$username":"$password" "$url" -o /dev/null -w '%{http_code}\n' -s)
fi

echo "$result"
}

function start_local_elastic_stack() {
printf "CURRENT_DIR=%s\n" "$CURRENT_DIR"
curl -fsSL https://elastic.co/start-local | sh
# shellcheck source=test/elastic/bootstrap.sh
source "${START_LOCAL_ENV_PATH}"
sleep 2
result=$(get_http_response_code "http://localhost:9200" "elastic" "${ES_LOCAL_PASSWORD}")
assert_equals "200" "$result"
}

function uninstall_local_elastic_stack() {
printf "yes\nno\n" | "${START_LOCAL_UNINSTALL_FILE}"
rm -rf "${START_LOCAL_DIR}"
}

function launch_demo() {
local deployment_type="$1"
local platform="$2"
local elasticsearch_endpoint="${ES_LOCAL_URL:-$3}"
local elasticsearch_api_key="${ES_LOCAL_API_KEY}"
echo "Launching demo with:"
echo " deployment_type: $deployment_type"
echo " platform: $platform"
echo " elasticsearch_endpoint: $elasticsearch_endpoint"
echo " elasticsearch_api_key: $elasticsearch_api_key"
printf "${deployment_type}\n${platform}\n${elasticsearch_endpoint}\n${elasticsearch_api_key}\n" | ${CURRENT_DIR}/demo.sh
}

function destroy_demo() {
local platform="$1"
echo "Destroying demo on platform: $platform"
${CURRENT_DIR}/demo.sh destroy "$platform"
}

# Check if a docker service is running
check_docker_service_running() {
local container_name=$1
local status

# Get the container status
status=$(docker ps --filter "name=^${container_name}$" --format '{{.Status}}' 2>/dev/null)

# Check if container exists and is running (status starts with "Up")
if [[ -n "$status" ]] && [[ "$status" =~ ^Up ]]; then
echo "Container $container_name is running"
return 0
else
echo "Container $container_name not running. Current status: ${status:-not found}"
return 1
fi
}

Loading