File tree Expand file tree Collapse file tree 6 files changed +51
-10
lines changed
Expand file tree Collapse file tree 6 files changed +51
-10
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,18 @@ elif [[ -z "${LOG_DIR:-}" ]]; then
3434 export LOG_DIR=" ${PROJECT_ROOT} /logs"
3535fi
3636
37- # Ensure log directory exists
38- mkdir -p " ${LOG_DIR} "
37+ # Ensure log directory exists (handle permission errors gracefully)
38+ mkdir -p " ${LOG_DIR} " 2> /dev/null || {
39+ # If we can't create LOG_DIR, try fallback locations
40+ if [[ -n " ${TMP_DIR:- } " ]]; then
41+ export LOG_DIR=" ${TMP_DIR} /logs"
42+ elif [[ -n " ${PROJECT_ROOT:- } " ]] && [[ -d " ${PROJECT_ROOT} " ]]; then
43+ export LOG_DIR=" ${PROJECT_ROOT} /tmp/logs"
44+ else
45+ export LOG_DIR=" /tmp/osm-notes-monitoring-logs"
46+ fi
47+ mkdir -p " ${LOG_DIR} " 2> /dev/null || export LOG_DIR=" /tmp"
48+ }
3949
4050# Initialize logging
4151init_logging " ${LOG_DIR} /alert_rules.log" " alertRules"
Original file line number Diff line number Diff line change @@ -34,8 +34,18 @@ elif [[ -z "${LOG_DIR:-}" ]]; then
3434 export LOG_DIR=" ${PROJECT_ROOT} /logs"
3535fi
3636
37- # Ensure log directory exists
38- mkdir -p " ${LOG_DIR} "
37+ # Ensure log directory exists (handle permission errors gracefully)
38+ mkdir -p " ${LOG_DIR} " 2> /dev/null || {
39+ # If we can't create LOG_DIR, try fallback locations
40+ if [[ -n " ${TMP_DIR:- } " ]]; then
41+ export LOG_DIR=" ${TMP_DIR} /logs"
42+ elif [[ -n " ${PROJECT_ROOT:- } " ]] && [[ -d " ${PROJECT_ROOT} " ]]; then
43+ export LOG_DIR=" ${PROJECT_ROOT} /tmp/logs"
44+ else
45+ export LOG_DIR=" /tmp/osm-notes-monitoring-logs"
46+ fi
47+ mkdir -p " ${LOG_DIR} " 2> /dev/null || export LOG_DIR=" /tmp"
48+ }
3949
4050# Only initialize if not in test mode or if script is executed directly
4151if [[ " ${TEST_MODE:- false} " != " true" ]] || [[ " ${BASH_SOURCE[0]} " == " ${0} " ]]; then
Original file line number Diff line number Diff line change @@ -34,8 +34,18 @@ elif [[ -z "${LOG_DIR:-}" ]]; then
3434 export LOG_DIR=" ${PROJECT_ROOT} /logs"
3535fi
3636
37- # Ensure log directory exists
38- mkdir -p " ${LOG_DIR} "
37+ # Ensure log directory exists (handle permission errors gracefully)
38+ mkdir -p " ${LOG_DIR} " 2> /dev/null || {
39+ # If we can't create LOG_DIR, try fallback locations
40+ if [[ -n " ${TMP_DIR:- } " ]]; then
41+ export LOG_DIR=" ${TMP_DIR} /logs"
42+ elif [[ -n " ${PROJECT_ROOT:- } " ]] && [[ -d " ${PROJECT_ROOT} " ]]; then
43+ export LOG_DIR=" ${PROJECT_ROOT} /tmp/logs"
44+ else
45+ export LOG_DIR=" /tmp/osm-notes-monitoring-logs"
46+ fi
47+ mkdir -p " ${LOG_DIR} " 2> /dev/null || export LOG_DIR=" /tmp"
48+ }
3949
4050# Only initialize logging if not in test mode
4151# When TEST_MODE is true, initialization is skipped to avoid database connections
Original file line number Diff line number Diff line change @@ -44,8 +44,9 @@ init_logging() {
4444 local log_dir
4545 log_dir=" $( dirname " ${LOG_FILE} " ) "
4646 if [[ ! -d " ${log_dir} " ]]; then
47- # In test mode or if we don't have permissions, use a temporary directory
48- if [[ " ${TEST_MODE:- false} " == " true" ]] || ! mkdir -p " ${log_dir} " 2> /dev/null; then
47+ # Try to create the directory first
48+ # Only use fallback if creation fails (e.g., no permissions)
49+ if ! mkdir -p " ${log_dir} " 2> /dev/null; then
4950 # Use TMP_DIR if set, otherwise try PROJECT_ROOT/tmp/logs, or use /tmp
5051 local fallback_dir
5152 if [[ -n " ${TMP_DIR:- } " ]]; then
Original file line number Diff line number Diff line change @@ -105,15 +105,21 @@ run_planet_check() {
105105 local planet_duration_threshold=" ${INGESTION_PLANET_CHECK_DURATION_THRESHOLD:- 600} "
106106 if [[ ${duration} -gt ${planet_duration_threshold} ]]; then
107107 log_warning " ${COMPONENT} : Planet check duration (${duration} s) exceeds threshold (${planet_duration_threshold} s)"
108- send_alert " WARNING" " ${COMPONENT} " " Planet Notes check took too long: ${duration} s (threshold: ${planet_duration_threshold} s)"
108+ # Only send alert if send_alert function is available and not mocked
109+ if command -v send_alert > /dev/null 2>&1 && [[ " ${TEST_MODE:- false} " != " true" ]]; then
110+ send_alert " WARNING" " ${COMPONENT} " " Planet Notes check took too long: ${duration} s (threshold: ${planet_duration_threshold} s)"
111+ fi
109112 fi
110113
111114 return 0
112115 else
113116 log_error " ${COMPONENT} : Planet Notes check failed (exit_code: ${exit_code} , duration: ${duration} s)"
114117 record_metric " ${COMPONENT} " " planet_check_status" " 0" " component=ingestion,check=processCheckPlanetNotes"
115118 record_metric " ${COMPONENT} " " planet_check_duration" " ${duration} " " component=ingestion,check=processCheckPlanetNotes"
116- send_alert " ERROR" " ${COMPONENT} " " Planet Notes check failed: exit_code=${exit_code} "
119+ # Only send alert if send_alert function is available and not mocked
120+ if command -v send_alert > /dev/null 2>&1 && [[ " ${TEST_MODE:- false} " != " true" ]]; then
121+ send_alert " ERROR" " ${COMPONENT} " " Planet Notes check failed: exit_code=${exit_code} "
122+ fi
117123 return 1
118124 fi
119125}
Original file line number Diff line number Diff line change @@ -257,7 +257,11 @@ teardown() {
257257 }
258258 export -f record_metric
259259
260+ # Set LOG_DIR to test directory if not already set
261+ export LOG_DIR=" ${LOG_DIR:- ${TEST_LOG_DIR} } "
262+
260263 # Create a mock log file with old execution times
264+ mkdir -p " ${LOG_DIR} " 2> /dev/null || export LOG_DIR=" ${TEST_LOG_DIR} "
261265 mkdir -p " ${LOG_DIR} "
262266 echo " cron_etl_last_execution_seconds 3600" > " ${LOG_DIR} /cron_metrics.log"
263267
You can’t perform that action at this time.
0 commit comments