-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
216 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /bin/bash | ||
## Run an end to end test with alerts | ||
|
||
# This will run an end to end test running the otel-lgtm stack (otel-collector, grafana, prometheus, tempo and loki) | ||
# Then check the test against a set of alerts defined in the alerts.yaml file | ||
# Note: these tests must run with METRICS enabled | ||
|
||
# Usage: ./e2e_test_with_alerts.sh <test-name> <...extra-args> | ||
# Example: ./e2e_test_with_alerts.sh gossip_network | ||
|
||
set -e | ||
|
||
test_path=$1 | ||
|
||
echo "Running otel stack" | ||
CONTAINER_ID=$(docker run -d -p 3000:3000 -p 4317:4317 -p 4318:4318 --rm grafana/otel-lgtm) | ||
|
||
trap "docker stop $CONTAINER_ID" EXIT SIGINT SIGTERM | ||
|
||
echo "Waiting for LGTM stack to be ready..." | ||
timeout=90 | ||
while [ $timeout -gt 0 ]; do | ||
if docker logs $CONTAINER_ID 2>&1 | grep -q "The OpenTelemetry collector and the Grafana LGTM stack are up and running"; then | ||
echo "LGTM stack is ready!" | ||
break | ||
fi | ||
sleep 1 | ||
((timeout--)) | ||
done | ||
|
||
if [ $timeout -eq 0 ]; then | ||
echo "Timeout waiting for LGTM stack to be ready" | ||
docker stop $CONTAINER_ID | ||
exit 1 | ||
fi | ||
|
||
## Pass through run the existing e2e test | ||
docker run \ | ||
--network host \ | ||
-e HARDWARE_CONCURRENCY="$HARDWARE_CONCURRENCY" \ | ||
-e FAKE_PROOFS="$FAKE_PROOFS" \ | ||
-e METRICS_PORT="4318" \ | ||
-e COLLECT_METRICS="true" \ | ||
-e PULL_REQUEST="$PULL_REQUEST" \ | ||
$env_args \ | ||
--rm aztecprotocol/end-to-end:$AZTEC_DOCKER_TAG \ | ||
"$test_path" "$@" || [ "$ignore_failures" = "true" ] | ||
|
||
|
||
echo "Running alert checker..." | ||
docker run --network host --rm aztecprotocol/end-to-end:$AZTEC_DOCKER_TAG quality_of_service/alert_checker.test.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
yarn-project/end-to-end/src/quality_of_service/alert_checker.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { type DebugLogger, createDebugLogger } from '@aztec/aztec.js'; | ||
import { fileURLToPath } from '@aztec/foundation/url'; | ||
|
||
import * as fs from 'fs'; | ||
import * as yaml from 'js-yaml'; | ||
import { dirname, join } from 'path'; | ||
|
||
const GRAFANA_ENDPOINT = 'http://localhost:3000/api/datasources/proxy/uid/prometheus/api/v1/query'; | ||
interface AlertConfig { | ||
alert: string; | ||
expr: string; | ||
for: string; | ||
labels: Record<string, string>; | ||
annotations: Record<string, string>; | ||
} | ||
// Define __dirname for ES modules | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
// Load YAML configuration | ||
function loadAlertsConfig(filePath: string): AlertConfig[] { | ||
const fileContents = fs.readFileSync(join(__dirname, filePath), 'utf8'); | ||
const data = yaml.load(fileContents) as { alerts: AlertConfig[] }; | ||
return data.alerts; | ||
} | ||
|
||
// Function to query Grafana based on an expression | ||
async function queryGrafana(expr: string): Promise<number> { | ||
// Create base64 encoded credentials for basic auth | ||
const credentials = Buffer.from('admin:admin').toString('base64'); | ||
|
||
const response = await fetch(`${GRAFANA_ENDPOINT}?query=${encodeURIComponent(expr)}`, { | ||
headers: { | ||
Authorization: `Basic ${credentials}`, | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to fetch data from Grafana: ${response.statusText}`); | ||
} | ||
|
||
const data = await response.json(); | ||
const result = data.data.result; | ||
return result.length > 0 ? parseFloat(result[0].value[1]) : 0; | ||
} | ||
|
||
// Function to check alerts based on expressions | ||
async function checkAlerts(alerts: AlertConfig[], logger: DebugLogger) { | ||
let alertTriggered = false; | ||
|
||
for (const alert of alerts) { | ||
logger.info(`Checking alert: ${JSON.stringify(alert)}`); | ||
|
||
const metricValue = await queryGrafana(alert.expr); | ||
logger.info(`Metric value: ${metricValue}`); | ||
if (metricValue > 0) { | ||
logger.error(`Alert ${alert.alert} triggered! Value: ${metricValue}`); | ||
alertTriggered = true; | ||
} else { | ||
logger.info(`Alert ${alert.alert} passed.`); | ||
} | ||
} | ||
|
||
// If any alerts have been triggered we fail the test | ||
if (alertTriggered) { | ||
throw new Error('Test failed due to triggered alert'); | ||
} | ||
} | ||
|
||
// Main function to run tests | ||
async function runAlertChecker(logger: DebugLogger) { | ||
const alerts = loadAlertsConfig('alerts.yaml'); | ||
try { | ||
await checkAlerts(alerts, logger); | ||
logger.info('All alerts passed.'); | ||
} catch (error) { | ||
logger.error(error instanceof Error ? error.message : String(error)); | ||
process.exit(1); // Exit with error code | ||
} | ||
} | ||
|
||
// Running as a jest test to use existing end to end test framework | ||
describe('Alert Checker', () => { | ||
const logger = createDebugLogger('aztec:alert-checker'); | ||
it('should check alerts', async () => { | ||
await runAlertChecker(logger); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
yarn-project/end-to-end/src/quality_of_service/alerts.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## A set of alerts for the quality of service of the sequencer, these are tested for in certain e2e tests | ||
|
||
## In end to end tests - page, will cause a test to fail | ||
## Warning will write a message to the PR | ||
|
||
alerts: | ||
- alert: SequencerTimeToCollectAttestations | ||
expr: aztec_sequencer_time_to_collect_attestations > 2500 | ||
labels: | ||
severity: page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.