forked from open-telemetry/opentelemetry-demo
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Adds more scripts for post-setup #108
Merged
jasonrhodes
merged 2 commits into
elastic:rca_ingress_obs
from
jasonrhodes:more-scripting
Oct 24, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,11 @@ | ||
{ | ||
"properties": { | ||
"body_text": { | ||
"type": "match_only_text" | ||
}, | ||
"message": { | ||
"type": "alias", | ||
"path": "body_text" | ||
} | ||
} | ||
} |
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,52 @@ | ||
{ | ||
"params": { | ||
"criteria": [ | ||
{ | ||
"comparator": ">", | ||
"metrics": [ | ||
{ | ||
"name": "A", | ||
"filter": "http.response.status_code:*", | ||
"aggType": "count" | ||
}, | ||
{ | ||
"name": "B", | ||
"filter": "http.response.status_code>=500", | ||
"aggType": "count" | ||
} | ||
], | ||
"threshold": [ | ||
1 | ||
], | ||
"timeSize": 1, | ||
"timeUnit": "m", | ||
"equation": "(B/A) * 100", | ||
"label": "500 Errors" | ||
} | ||
], | ||
"alertOnNoData": false, | ||
"alertOnGroupDisappear": false, | ||
"searchConfiguration": { | ||
"query": { | ||
"query": "k8s.namespace.name: \"ingress-nginx\" AND url.path: /api/*", | ||
"language": "kuery" | ||
}, | ||
"index": "otel_logs_data" | ||
}, | ||
"groupBy": [ | ||
"service.name", | ||
"url.path" | ||
] | ||
}, | ||
"consumer": "logs", | ||
"schedule": { | ||
"interval": "1m" | ||
}, | ||
"tags": [ | ||
"demo", | ||
"cli-created" | ||
], | ||
"name": "NGINX 500s", | ||
"rule_type_id": "observability.rules.custom_threshold", | ||
"actions": [] | ||
} |
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,59 @@ | ||
#!/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 | ||
INDICES=$2 | ||
|
||
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 | ||
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 | ||
title "Data view $1 already exists" | ||
fi | ||
} | ||
|
||
create_rule () { | ||
ID=$1 | ||
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 | ||
} | ||
|
||
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)" | ||
fi | ||
|
||
if [ -z "${OTEL_DEMO_ES_API_KEY}" ]; then | ||
die "You must set OTEL_DEMO_ES_API_KEY (must be valid API key for ES and Kibana APIs)" | ||
fi | ||
|
||
# Create data views | ||
create_data_view otel_logs_data logs-*otel* | ||
|
||
# Create rules | ||
create_rule 9055220c-8fb1-4f9f-be7c-0a33eb2bafc5 rule-01.json | ||
|
||
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 -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 |
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,33 @@ | ||
|
||
# Define bash colors | ||
# Reset | ||
Color_Off='\033[0m' # Text Reset | ||
|
||
# Regular Colors | ||
Black='\033[0;30m' # Black | ||
Red='\033[0;31m' # Red | ||
Green='\033[0;32m' # Green | ||
Yellow='\033[0;33m' # Yellow | ||
Blue='\033[0;34m' # Blue | ||
Purple='\033[0;35m' # Purple | ||
Cyan='\033[0;36m' # Cyan | ||
White='\033[0;37m' # White | ||
|
||
# Bold | ||
BBlack='\033[1;30m' # Black | ||
BRed='\033[1;31m' # Red | ||
BGreen='\033[1;32m' # Green | ||
BYellow='\033[1;33m' # Yellow | ||
BBlue='\033[1;34m' # Blue | ||
BPurple='\033[1;35m' # Purple | ||
BCyan='\033[1;36m' # Cyan | ||
BWhite='\033[1;37m' # White | ||
|
||
title () { | ||
echo -e ${Cyan}"<[${BBlue} $1 ${Cyan}]>${Color_Off}" | ||
} | ||
|
||
die () { | ||
echo -e "${BRed}ERROR: $1${Color_Off}" | ||
exit 1 | ||
} |
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.
this will fail if the data stream doesn't exist, in that case you need to update the component template as well.
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.
Thanks, I'll add the component update in a follow up and just make this fail silently