Skip to content

Commit 0d3da4a

Browse files
committed
Refactor logging initialization and test setup for ingestion monitoring
- Updated `monitorIngestion.sh` to initialize logging only when not in test mode or when executed directly, enhancing script behavior. - Modified test scripts `test_ddosProtection_load.sh`, `test_monitoring_overhead.sh` to set `TEST_MODE` before loading scripts, ensuring consistent test environment setup. - Adjusted `test_stress_metrics.sh` to disable alert deduplication for specific tests, ensuring all alerts are recorded for accurate testing outcomes.
1 parent 10e471d commit 0d3da4a

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

bin/monitor/monitorIngestion.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ source "${PROJECT_ROOT}/bin/lib/parseStructuredLogs.sh"
3535
# Set default LOG_DIR if not set
3636
export LOG_DIR="${LOG_DIR:-${PROJECT_ROOT}/logs}"
3737

38-
# Initialize logging
39-
init_logging "${LOG_DIR}/ingestion.log" "monitorIngestion"
38+
# Initialize logging only if not in test mode or if script is executed directly
39+
if [[ "${TEST_MODE:-false}" != "true" ]] || [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
40+
init_logging "${LOG_DIR}/ingestion.log" "monitorIngestion"
41+
fi
4042

4143
# Component name
4244
# Component name (allow override in test mode)

tests/performance/test_ddosProtection_load.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export TEST_DB_NAME="${TEST_DB_NAME:-osm_notes_monitoring_test}"
1212

1313
load "${BATS_TEST_DIRNAME}/../test_helper.bash"
1414

15-
# Set LOG_DIR before loading scripts
15+
# Set TEST_MODE and LOG_DIR before loading scripts
16+
export TEST_MODE=true
1617
export LOG_DIR="${LOG_DIR:-${BATS_TEST_DIRNAME}/../tmp/logs}"
1718
mkdir -p "${LOG_DIR}"
1819

tests/performance/test_monitoring_overhead.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export TEST_DB_NAME="${TEST_DB_NAME:-osm_notes_monitoring_test}"
1616

1717
load "${BATS_TEST_DIRNAME}/../test_helper.bash"
1818

19-
# Set LOG_DIR before loading monitorIngestion.sh
19+
# Set TEST_MODE and LOG_DIR before loading monitorIngestion.sh
20+
export TEST_MODE=true
2021
export LOG_DIR="${LOG_DIR:-${BATS_TEST_DIRNAME}/../tmp/logs}"
2122
mkdir -p "${LOG_DIR}"
2223

tests/performance/test_stress_metrics.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ skip_if_database_not_available() {
185185
@test "Stress test: concurrent alerts and metrics" {
186186
skip_if_database_not_available
187187

188+
# Disable alert deduplication for this test to ensure all alerts are recorded
189+
export ALERT_DEDUPLICATION_ENABLED="false"
190+
188191
# Clean up any existing test data
189192
run_sql_query "DELETE FROM metrics WHERE component = 'ingestion' AND metric_name = 'stress_concurrent';" > /dev/null 2>&1 || true
190193
run_sql_query "DELETE FROM alerts WHERE component = 'ingestion' AND alert_type = 'stress_alert';" > /dev/null 2>&1 || true
@@ -221,7 +224,7 @@ skip_if_database_not_available() {
221224
alert_count=$(run_sql_query "SELECT COUNT(*) FROM alerts WHERE component = 'ingestion' AND alert_type = 'stress_alert';" | tr -d ' ' || echo "0")
222225

223226
assert [ "${metric_count}" -eq 50 ]
224-
assert [ "${alert_count}" -ge 15 ] # Some may be deduplicated
227+
assert [ "${alert_count}" -eq 20 ] # All alerts should be recorded when deduplication is disabled
225228
assert [ "${duration_ms}" -lt 15000 ]
226229
}
227230

0 commit comments

Comments
 (0)