Skip to content

Commit

Permalink
Fix GCP asset inventory CI (#2528)
Browse files Browse the repository at this point in the history
  • Loading branch information
orouz authored Sep 16, 2024
1 parent 22a5020 commit 414f47b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .github/actions/gcp-asset-inventory-ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions .github/actions/wait-for-es-data/action.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 414f47b

Please sign in to comment.