diff --git a/.github/actions/gcp-asset-inventory-ci/action.yml b/.github/actions/gcp-asset-inventory-ci/action.yml index 6f29660656..0d360c5588 100644 --- a/.github/actions/gcp-asset-inventory-ci/action.yml +++ b/.github/actions/gcp-asset-inventory-ci/action.yml @@ -35,9 +35,10 @@ runs: run: | ./cloudbeat -c deploy/asset-inventory/cloudbeat-gcp-asset-inventory.yml -d '*' & - - name: Wait for cloudbeat to send some events - shell: bash - run: sleep 20 + - name: Wait for data + uses: ./.github/actions/wait-for-es-data + with: + index: .ds-logs-cloud_asset_inventory.asset_inventory-* - name: Check for assets working-directory: ./tests diff --git a/.github/actions/wait-for-es-data/action.yml b/.github/actions/wait-for-es-data/action.yml new file mode 100644 index 0000000000..c70d8b97f2 --- /dev/null +++ b/.github/actions/wait-for-es-data/action.yml @@ -0,0 +1,39 @@ +name: "Wait for ES Data" +description: "Waits for data on ES indices" +inputs: + index: + description: "Which ES index to look at" + required: true + es_host: + description: "the ES host URL" + default: "http://localhost:9200" + retries: + description: "How many times to retry checking for data. (1s interval)" + default: "100" + +runs: + using: composite + steps: + - name: Wait for data + shell: bash + run: | + URL="${{inputs.es_host}}/${{ inputs.index }}/_search?size=0" + HEADER="Content-Type: application/json" + MAX_RETRIES=${{inputs.retries}} + + echo "Checking index: ${{ inputs.index }}" + + for ((i = 1; i <= MAX_RETRIES; i++)); do + result=$(curl -s -X GET "$URL" -H "$HEADER" | jq '.hits.total.value') + + if [ "$result" -gt 0 ]; then + echo "Data found: $result documents in index ${{ inputs.index }}" + exit 0 + fi + + echo "No data yet. Retrying in 1s... ($i/$MAX_RETRIES)" + sleep 1 + done + + echo "No data found after $MAX_RETRIES retries." + exit 1