From 999298f9ec26a9cdb3db3b481d898770602ce1ff Mon Sep 17 00:00:00 2001 From: Cas Donoghue Date: Fri, 13 Dec 2024 09:22:45 -0800 Subject: [PATCH] Update serverless tests to include product origin header (#16766) This commit updates the curl scripts that interact with Kibana's `api/logstash/pipeline/*` endpoin. Additionally this adds the header to any curl that interacts with elasticsearch API as well. (cherry picked from commit 188d9e7ed8e27552b888f1aa222840ca5292e9ee) --- ci/serverless/common.sh | 4 +++- ci/serverless/cpm_tests.sh | 5 +++-- ci/serverless/elastic_integration_filter_tests.sh | 4 +++- ci/serverless/es_output_tests.sh | 2 +- ci/serverless/kibana_api_tests.sh | 11 +++++++---- ci/serverless/metricbeat_monitoring_tests.sh | 2 +- ci/serverless/monitoring_tests.sh | 2 +- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ci/serverless/common.sh b/ci/serverless/common.sh index 4a5fb3bc21f..a0d5c90d1b5 100755 --- a/ci/serverless/common.sh +++ b/ci/serverless/common.sh @@ -28,7 +28,9 @@ build_logstash() { } index_test_data() { - curl -X POST -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/$INDEX_NAME/_bulk" -H 'Content-Type: application/json' --data-binary @"$CURRENT_DIR/test_data/book.json" + curl -X POST -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/$INDEX_NAME/_bulk" \ + -H 'x-elastic-product-origin: logstash' \ + -H 'Content-Type: application/json' --data-binary @"$CURRENT_DIR/test_data/book.json" } # $1: check function diff --git a/ci/serverless/cpm_tests.sh b/ci/serverless/cpm_tests.sh index 16ed5dc3418..14d2338bd59 100755 --- a/ci/serverless/cpm_tests.sh +++ b/ci/serverless/cpm_tests.sh @@ -7,7 +7,8 @@ export PIPELINE_NAME='gen_es' # update pipeline and check response code index_pipeline() { - RESP_CODE=$(curl -s -w "%{http_code}" -X PUT -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/_logstash/pipeline/$1" -H 'Content-Type: application/json' -d "$2") + RESP_CODE=$(curl -s -w "%{http_code}" -X PUT -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/_logstash/pipeline/$1" \ + -H 'x-elastic-product-origin: logstash' -H 'Content-Type: application/json' -d "$2") if [[ $RESP_CODE -ge '400' ]]; then echo "failed to update pipeline for Central Pipeline Management. Got $RESP_CODE from Elasticsearch" exit 1 @@ -34,7 +35,7 @@ check_plugin() { } delete_pipeline() { - curl -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" -X DELETE "$ES_ENDPOINT/_logstash/pipeline/$PIPELINE_NAME" -H 'Content-Type: application/json'; + curl -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" -H 'x-elastic-product-origin: logstash' -X DELETE "$ES_ENDPOINT/_logstash/pipeline/$PIPELINE_NAME" -H 'Content-Type: application/json'; } cpm_clean_up_and_get_result() { diff --git a/ci/serverless/elastic_integration_filter_tests.sh b/ci/serverless/elastic_integration_filter_tests.sh index 3f7c121f84b..dbd3ab25f5e 100755 --- a/ci/serverless/elastic_integration_filter_tests.sh +++ b/ci/serverless/elastic_integration_filter_tests.sh @@ -6,10 +6,12 @@ source ./$(dirname "$0")/common.sh deploy_ingest_pipeline() { PIPELINE_RESP_CODE=$(curl -s -w "%{http_code}" -o /dev/null -X PUT -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/_ingest/pipeline/integration-logstash_test.events-default" \ -H 'Content-Type: application/json' \ + -H 'x-elastic-product-origin: logstash' \ --data-binary @"$CURRENT_DIR/test_data/ingest_pipeline.json") TEMPLATE_RESP_CODE=$(curl -s -w "%{http_code}" -o /dev/null -X PUT -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/_index_template/logs-serverless-default-template" \ -H 'Content-Type: application/json' \ + -H 'x-elastic-product-origin: logstash' \ --data-binary @"$CURRENT_DIR/test_data/index_template.json") # ingest pipeline is likely be there from the last run @@ -29,7 +31,7 @@ check_integration_filter() { } get_doc_msg_length() { - curl -s -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/logs-$INDEX_NAME.004-default/_search?size=1" | jq '.hits.hits[0]._source.message | length' + curl -s -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/logs-$INDEX_NAME.004-default/_search?size=1" -H 'x-elastic-product-origin: logstash' | jq '.hits.hits[0]._source.message | length' } # ensure no double run of ingest pipeline diff --git a/ci/serverless/es_output_tests.sh b/ci/serverless/es_output_tests.sh index 6bb5e9335e4..788fb786a8f 100755 --- a/ci/serverless/es_output_tests.sh +++ b/ci/serverless/es_output_tests.sh @@ -9,7 +9,7 @@ check_named_index() { } get_data_stream_count() { - curl -s -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/logs-$INDEX_NAME.001-default/_count" | jq '.count // 0' + curl -s -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" -H 'x-elastic-product-origin: logstash' "$ES_ENDPOINT/logs-$INDEX_NAME.001-default/_count" | jq '.count // 0' } compare_data_stream_count() { diff --git a/ci/serverless/kibana_api_tests.sh b/ci/serverless/kibana_api_tests.sh index 52f3f0f9b31..86e6f6df008 100755 --- a/ci/serverless/kibana_api_tests.sh +++ b/ci/serverless/kibana_api_tests.sh @@ -10,7 +10,7 @@ export EXIT_CODE="0" create_pipeline() { RESP_CODE=$(curl -s -w "%{http_code}" -o /dev/null -X PUT -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$KB_ENDPOINT/api/logstash/pipeline/$PIPELINE_NAME" \ - -H 'Content-Type: application/json' -H 'kbn-xsrf: logstash' \ + -H 'Content-Type: application/json' -H 'kbn-xsrf: logstash' -H 'x-elastic-product-origin: logstash' \ --data-binary @"$CURRENT_DIR/test_data/$PIPELINE_NAME.json") if [[ RESP_CODE -ge '400' ]]; then @@ -20,7 +20,8 @@ create_pipeline() { } get_pipeline() { - RESP_BODY=$(curl -s -X GET -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$KB_ENDPOINT/api/logstash/pipeline/$PIPELINE_NAME") + RESP_BODY=$(curl -s -X GET -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" -H 'x-elastic-product-origin: logstash' \ + "$KB_ENDPOINT/api/logstash/pipeline/$PIPELINE_NAME") \ SOURCE_BODY=$(cat "$CURRENT_DIR/test_data/$PIPELINE_NAME.json") RESP_PIPELINE_NAME=$(echo "$RESP_BODY" | jq -r '.id') @@ -41,7 +42,8 @@ get_pipeline() { } list_pipeline() { - RESP_BODY=$(curl -s -X GET -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$KB_ENDPOINT/api/logstash/pipelines" | jq --arg name "$PIPELINE_NAME" '.pipelines[] | select(.id==$name)' ) + RESP_BODY=$(curl -s -X GET -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" -H 'x-elastic-product-origin: logstash' \ + "$KB_ENDPOINT/api/logstash/pipelines" | jq --arg name "$PIPELINE_NAME" '.pipelines[] | select(.id==$name)' ) if [[ -z "$RESP_BODY" ]]; then EXIT_CODE=$(( EXIT_CODE + 1 )) echo "Fail to list pipeline." @@ -49,7 +51,8 @@ list_pipeline() { } delete_pipeline() { - RESP_CODE=$(curl -s -w "%{http_code}" -o /dev/null -X DELETE -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$KB_ENDPOINT/api/logstash/pipeline/$PIPELINE_NAME" \ + RESP_CODE=$(curl -s -w "%{http_code}" -o /dev/null -X DELETE -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" -H 'x-elastic-product-origin: logstash' \ + "$KB_ENDPOINT/api/logstash/pipeline/$PIPELINE_NAME" \ -H 'Content-Type: application/json' -H 'kbn-xsrf: logstash' \ --data-binary @"$CURRENT_DIR/test_data/$PIPELINE_NAME.json") diff --git a/ci/serverless/metricbeat_monitoring_tests.sh b/ci/serverless/metricbeat_monitoring_tests.sh index cd41d4c1742..ce3e47dc7b0 100755 --- a/ci/serverless/metricbeat_monitoring_tests.sh +++ b/ci/serverless/metricbeat_monitoring_tests.sh @@ -40,7 +40,7 @@ stop_metricbeat() { } get_monitor_count() { - curl -s -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" "$ES_ENDPOINT/$INDEX_NAME/_count" | jq '.count // 0' + curl -s -H "Authorization: ApiKey $TESTER_API_KEY_ENCODED" -H 'x-elastic-product-origin: logstash' "$ES_ENDPOINT/$INDEX_NAME/_count" | jq '.count // 0' } compare_monitor_count() { diff --git a/ci/serverless/monitoring_tests.sh b/ci/serverless/monitoring_tests.sh index 3113e44734f..431fc5f2d1c 100755 --- a/ci/serverless/monitoring_tests.sh +++ b/ci/serverless/monitoring_tests.sh @@ -6,7 +6,7 @@ set -ex source ./$(dirname "$0")/common.sh get_monitor_count() { - curl -s -H "Authorization: ApiKey $LS_ROLE_API_KEY_ENCODED" "$ES_ENDPOINT/.monitoring-logstash-7-*/_count" | jq '.count' + curl -s -H "Authorization: ApiKey $LS_ROLE_API_KEY_ENCODED" -H 'x-elastic-product-origin: logstash' "$ES_ENDPOINT/.monitoring-logstash-7-*/_count" | jq '.count' } compare_monitor_count() {