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

[Archive Migrations] x-pack dashboard/session_in_spaces #136531

Merged
Merged
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
129 changes: 85 additions & 44 deletions scripts/archive_migration_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,76 @@

standard_list="url,index-pattern,query,graph-workspace,tag,visualization,canvas-element,canvas-workpad,dashboard,search,lens,map,cases,uptime-dynamic-settings,osquery-saved-query,osquery-pack,infrastructure-ui-source,metrics-explorer-view,inventory-view,infrastructure-monitoring-log-view,apm-indices"

orig_archive="x-pack/test/functional/es_archives/reporting/ecommerce_kibana_spaces"
new_archive="x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce_kibana_spaces"
newArchives=("x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce_kibana_non_default_space")
newArchives+=("x-pack/test/functional/fixtures/kbn_archiver/reporting/ecommerce_kibana_non_timezone_space")
test_config="x-pack/test/reporting_api_integration/reporting_and_security.config.ts"
orig_archive="x-pack/test/functional/es_archives/dashboard/session_in_space"
new_archive="x-pack/test/functional/fixtures/kbn_archiver/dashboard/session_in_space"
newArchives=("x-pack/test/functional/fixtures/kbn_archiver/dashboard/session_in_space")
newArchives+=("x-pack/test/functional/fixtures/kbn_archiver/dashboard/session_in_another_space")
test_config="x-pack/test/search_sessions_integration/config.ts"

curl_so_count() {
local so=${1:-search-session}
local count
count=$(curl -s -XGET "http://elastic:changeme@localhost:9220/.kibana/_count" -H "kbn-xsrf: archive-migration-functions" -H "Content-Type: application/json" -d'
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"type": "${so}"
}
}
]
}
}
}' | jq '.count')

echo " ### [${so}] count: ${count}"
}

watch_so_count() {
local so=${1:-search-session}

while true; do
curl_so_count "$so"
sleep 1
done
}

create_space() {
# Ex: Id, Name, and Disabled Features.
# create_space tre "Tre Space" apm,ml,canvas,dashboard,visualize,maps,monitoring,uptime
# Ex: Id. Name is generated
# create_space rashmi
# Ex: Id and Name. No disabled features.
# create_space another-space "Another Space"
local id=${1:-sales}
local upperCased
upperCased=$(echo "${id:0:1}" | tr '[:lower:]' '[:upper:]')"${id:1}"
local name=${2:-$upperCased}
local disabledFeatures=${3:-}

if [[ -n $3 ]]; then
disabledFeatures="$3"
fi

# Use jq to create the i and n variables, then inject them.
local payload
payload=$(jq -n --arg i "$id" --arg n "$name" --arg df "$disabledFeatures" \
'{ "id": $i, "name": $n, "disabledFeatures": [$df] }')

curl -H "Content-Type: application/json" -H "kbn-xsrf: archive-migration-functions" \
-X POST -d "$payload" \
--user elastic:changeme http://localhost:5620/api/spaces/space
}

delete_space() {
local id=${1:?Need a space id.}

curl -H "kbn-xsrf: archive-migration-functions" \
-X DELETE \
--user elastic:changeme http://localhost:5620/api/spaces/space/"$id"
}

arrayify_csv() {
local xs=${1}
Expand All @@ -31,11 +96,6 @@ intersection() {
echo "${intersections[@]}"
}

# Just a note that this is using Gnu date.
# On OSX if you don't install this, and instead use the native date you only get seconds.
# With gdate you can something like nanoseconds.
alias timestamp='while read line; do echo "[`gdate +%H:%M:%S.%N`] $line"; done'

is_zipped() {
local archive=$1

Expand Down Expand Up @@ -98,6 +158,7 @@ _find_config() {

local current
local parent
local grandParent
local greatGrand
current=$(dirname "$test_file")
parent=$(dirname "$current")
Expand All @@ -107,8 +168,9 @@ _find_config() {
local dirs=("$current" "$parent" "$grandParent" "$greatGrand")

local configs=()
local config
for x in "${dirs[@]}"; do
local config=$(find "$x" -maxdepth 1 -type f -name '*config.js' -or -name '*config.ts')
config=$(find "$x" -maxdepth 1 -type f -name '*config.js' -or -name '*config.ts')
if [ -n "$config" ]; then
configs+=("$config")
fi
Expand Down Expand Up @@ -277,42 +339,29 @@ save_kbn() {

load_kbn() {
local space=${1:-default}
local archive=${2:-${new_archive}}

set -x
node scripts/kbn_archiver.js --config "$test_config" load "$new_archive" --space "$space"
set +x
}

load_kbns() {
local space=${1:-default}

for x in "${newArchives[@]}"; do
set -x
node scripts/kbn_archiver.js --config "$test_config" load "$x" --space "$space"
set +x
done
}

load_created_kbn_archive() {
set -x
node scripts/kbn_archiver.js --config "$test_config" load "$new_archive"
node scripts/kbn_archiver.js --config "$test_config" load "$archive" --space "$space"
set +x
}

unload_kbn() {
local archive=${1:-${new_archive}}
set -x
node scripts/kbn_archiver.js --config "$test_config" unload "$new_archive"
node scripts/kbn_archiver.js --config "$test_config" unload "$archive"
set +x
}

unload_kbns() {
local space=${1:-default}
load_kbn_custom() {
load_kbn default "${newArchives[1]}"
create_space another-space "Another Space"
load_kbn another-space "${newArchives[2]}"
}

for x in "${newArchives[@]}"; do
set -x
node scripts/kbn_archiver.js --config "$test_config" unload "$x"
set +x
done
unload_kbn_custom() {
unload_kbn "${newArchives[1]}"
delete_space another-space
}

ping_server() {
Expand All @@ -338,14 +387,6 @@ run_test() {
set +x
}

run_test_with_timestamp() {
local config=${1:-$test_config}

set -x
node scripts/functional_test_runner --config "$config" | timestamp
set +x
}

run_test_extra() {
set -x
node scripts/functional_test_runner --config "$test_config" \
Expand Down

This file was deleted.

This file was deleted.

Loading