Skip to content

Commit

Permalink
Cleaned up logging and function sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Oct 24, 2024
1 parent 673b7ac commit 0f9d39c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 14 additions & 14 deletions scripts/rca-demo/post-setup
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash

SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")

set -a
source $SCRIPTS_DIR/shared.sh
source $SCRIPTS_DIR/.env
set +a

create_data_view () {
ID=$1
Expand All @@ -11,10 +14,10 @@ create_data_view () {
EXISTS=$(curl -s $KIBANA_URL/api/data_views/data_view/$ID -H "Authorization: ApiKey $OTEL_DEMO_ES_API_KEY" -H 'elastic-api-version: 2023-10-31')

if [[ $EXISTS == '{"statusCode":404,"error":"Not Found"'* ]]; then
echo "Creating data view $1 for indices $2"
title "Creating data view $1 for indices $2"
curl -X POST $KIBANA_URL/api/data_views/data_view -H 'kbn-xsrf: bananas' -H 'Content-Type: application/json' -H 'elastic-api-version: 2023-10-31' -H "Authorization: ApiKey $OTEL_DEMO_ES_API_KEY" -d "{\"data_view\": { \"name\": \"$1 (Automated by Demo CLI)\", \"title\": \"$2\", \"id\": \"$1\", \"timeFieldName\": \"@timestamp\" }}"
else
echo "Data view $1 already exists"
title "Data view $1 already exists"
fi
}

Expand All @@ -23,18 +26,9 @@ create_rule () {
DATA_FILE=$2

curl -X POST $KIBANA_URL/api/alerting/rule/$ID -H 'kbn-xsrf: bananas' -H "Authorization: ApiKey $OTEL_DEMO_ES_API_KEY" -H 'Content-Type: application/json; elastic-api-version: 2023-10-31' -d @$SCRIPTS_DIR/data/$DATA_FILE

echo ""
}

echo "Setting up Kibana assets for the demo..."

# Load local user .env file
ENV_FILE="./scripts/rca-demo/.env"
if [ -f $ENV_FILE ]; then
echo "Sourcing env vars from $ENV_FILE ..."
source $ENV_FILE
fi
title "Setting up Kibana assets for the demo..."

if [ -z "${KIBANA_URL}" ]; then
die "You must set KIBANA_URL so that we can post API requests there (please include base path if one exists)"
Expand All @@ -50,10 +44,16 @@ create_data_view otel_logs_data logs-*otel*
# Create rules
create_rule 9055220c-8fb1-4f9f-be7c-0a33eb2bafc5 rule-01.json

# Update mappints in ES
echo -e "\n"

# Update mappings in ES
# NOTE: this will fail if the data stream is not created
# TODO: Update the component template also, and just swallow errors on this call
title "Attempting to add message alias for otel logs"
curl -X PUT http://localhost:9200/logs-*otel*/_mapping -H "Authorization: ApiKey $OTEL_DEMO_ES_API_KEY" -H "Content-Type: application/json" -d @$SCRIPTS_DIR/data/mapping-message-alias.json

echo ""
echo -e "\n"

# Enable EEM
title "Attempting to enable EEM"
curl -X PUT -H "Authorization: ApiKey $OTEL_DEMO_ES_API_KEY" -H "kbn-xsrf: bananas" $KIBANA_URL/internal/entities/managed/enablement
2 changes: 2 additions & 0 deletions scripts/rca-demo/setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
APP_NAME=my-otel-demo

# source shared utils
set -a
source ./shared.sh
set +a

title "Checking environment for $APP_NAME..."

Expand Down

0 comments on commit 0f9d39c

Please sign in to comment.