diff --git a/packages/hub-web/examples/events/index.ts b/packages/hub-web/examples/events/index.ts index 0a9cd36e10..b51bba75f0 100644 --- a/packages/hub-web/examples/events/index.ts +++ b/packages/hub-web/examples/events/index.ts @@ -7,13 +7,63 @@ async function listen() { do { try { - const url = `${server}/v1/events?from_event_id=${from_event_id}`; - const response = await axios.get(url); - for (const event of response.data.events) { - console.log(event); - } - if (response.data.events.length <= 1) { - // wait a bit if there are no events + import axios from "axios"; + +const handleEvents = async () => { + try { + // Safely construct the URL using the URL object + const serverUrl = new URL(`${server}/v1/events`); + serverUrl.searchParams.append("from_event_id", from_event_id); + + // Execute the request using axios + const response = await axios.get(serverUrl.toString()); + + // Process each event from the response + for (const event of response.data.events) { + console.log(event); + } + + // Check for absence or minimal number of events + if (response.data.events.length <= 1) { + console.log("No events or only one event found. Waiting..."); + // Implement wait logic here if needed + } + } catch (error) { + // Handle errors and provide meaningful feedback + console.error("Error fetching events:", error.message); + } +}; + +handleEvents(); +import axios from "axios"; + +const handleEvents = async () => { + try { + // Safely construct the URL using the URL object + const serverUrl = new URL(`${server}/v1/events`); + serverUrl.searchParams.append("from_event_id", from_event_id); + + // Execute the request using axios + const response = await axios.get(serverUrl.toString()); + + // Process each event from the response + for (const event of response.data.events) { + console.log(event); + } + + // Check for absence or minimal number of events + if (response.data.events.length <= 1) { + console.log("No events or only one event found. Waiting..."); + // Implement wait logic here if needed + } + } catch (error) { + // Handle errors and provide meaningful feedback + console.error("Error fetching events:", error.message); + } +}; + +handleEvents(); + await new Promise((resolve) => setTimeout(resolve, 1000)); } from_event_id = response.data.nextPageEventId; diff --git a/scripts/hubble.sh b/scripts/hubble.sh index bf38d81a45..1b44333fb8 100755 --- a/scripts/hubble.sh +++ b/scripts/hubble.sh @@ -332,11 +332,16 @@ setup_grafana() { ensure_grafana # Step 2: Wait for Grafana to be ready +wait_for_grafana() { echo "Waiting for Grafana to be ready..." - while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' $grafana_url/api/health)" != "200" ]]; do - sleep 2; + while [[ "$(curl -s -o /dev/null -w '%{http_code}' "$grafana_url/api/health")" != "200" ]]; do + sleep 2 done echo "Grafana is ready." +} + +# Call the function to wait for Grafana +wait_for_grafana # Step 3: Add Graphite as a data source using Grafana's API add_datasource