Skip to content

Commit ea1677c

Browse files
authored
Merge pull request #319 from JohT/feature/improve-logging
Improve Logging
2 parents f4d9c61 + 7d97d65 commit ea1677c

File tree

9 files changed

+87
-31
lines changed

9 files changed

+87
-31
lines changed

cypher/Dependencies_Projection/Dependencies_4c_Create_Undirected_Type_Projection.cypher renamed to cypher/Dependencies_Projection/Dependencies_4c_Create_Undirected_Java_Type_Projection.cypher

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Create filtered Type node projection without zero-degree nodes, external types, java types or duplicates. Variables: dependencies_projection. Requires 'Label_base_java_types', 'Label_buildin_java_types' and 'Label_resolved_duplicate_types' of 'Types' directory.
1+
// Create filtered Java Type node projection without zero-degree nodes, external types, java types or duplicates. Variables: dependencies_projection. Requires 'Label_base_java_types', 'Label_buildin_java_types' and 'Label_resolved_duplicate_types' of 'Types' directory.
22

3-
MATCH (internalType:Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType&!ExternalType)
3+
MATCH (internalType:Java&Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType&!ExternalType)
44
OPTIONAL MATCH (internalType)-[typeDependency:DEPENDS_ON]->(dependentType:Type&!PrimitiveType&!Void&!JavaType&!ResolvedDuplicateType&!ExternalType)
55
WITH internalType
66
,typeDependency

scripts/analysis/analyze.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ REPORT_COMPILATIONS_SCRIPTS_DIRECTORY=${REPORT_COMPILATIONS_SCRIPTS_DIRECTORY:-"
3939
SETTINGS_PROFILE_SCRIPTS_DIRECTORY=${SETTINGS_PROFILE_SCRIPTS_DIRECTORY:-"profiles"} # Repository directory that contains scripts containing settings
4040
ARTIFACTS_DIRECTORY=${ARTIFACTS_DIRECTORY:-"artifacts"} # Working directory containing the artifacts to be analyzed
4141
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-"source"}
42+
LOG_GROUP_START=${LOG_GROUP_START:-"::group::"} # Prefix to start a log group. Defaults to GitHub Actions log group start command.
43+
LOG_GROUP_END=${LOG_GROUP_END:-"::endgroup::"} # Prefix to end a log group. Defaults to GitHub Actions log group end command.
4244

4345
# Function to display script usage
4446
usage() {
@@ -127,15 +129,21 @@ echo "analyze: Using analysis settings profile script ${SETTINGS_PROFILE_SCRIPT}
127129
source "${SETTINGS_PROFILE_SCRIPT}"
128130

129131
# Setup Tools
132+
echo "${LOG_GROUP_START}Setup Tools";
130133
source "${SCRIPTS_DIR}/setupNeo4j.sh"
131134
source "${SCRIPTS_DIR}/setupJQAssistant.sh"
132135
source "${SCRIPTS_DIR}/startNeo4j.sh"
136+
echo "${LOG_GROUP_END}";
133137

134138
# Scan and analyze artifacts when they were changed
139+
echo "${LOG_GROUP_START}Scan and Analyze Changed Artifacts";
135140
source "${SCRIPTS_DIR}/resetAndScanChanged.sh"
141+
echo "${LOG_GROUP_END}";
136142

137143
# Prepare and validate graph database before analyzing and creating reports
144+
echo "${LOG_GROUP_START}Prepare Analysis";
138145
source "${SCRIPTS_DIR}/prepareAnalysis.sh"
146+
echo "${LOG_GROUP_END}";
139147

140148
if ${exploreMode}; then
141149
echo "analyze: Explore mode activated. Report generation will be skipped. Neo4j keeps running."
@@ -149,4 +157,6 @@ echo "analyze: Creating Reports with ${REPORT_COMPILATION_SCRIPT} ..."
149157
source "${REPORT_COMPILATION_SCRIPT}"
150158

151159
# Stop Neo4j at the end
152-
source "${SCRIPTS_DIR}/stopNeo4j.sh"
160+
echo "${LOG_GROUP_START}Finishing Analysis";
161+
source "${SCRIPTS_DIR}/stopNeo4j.sh"
162+
echo "${LOG_GROUP_END}";

scripts/executeQuery.sh

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ set -o errexit -o pipefail
2121
NEO4J_HTTP_PORT=${NEO4J_HTTP_PORT:-"7474"} # Neo4j HTTP API port for executing queries
2222
NEO4J_HTTP_TRANSACTION_ENDPOINT=${NEO4J_HTTP_TRANSACTION_ENDPOINT:-"db/neo4j/tx/commit"} # Neo4j v5: "db/<name>/tx/commit", Neo4j v4: "db/data/transaction/commit"
2323

24+
# Local constants
25+
ERROR_COLOR='\033[0;31m'
26+
NO_COLOR='\033[0m'
27+
2428
# Check if environment variable is set
2529
if [ -z "${NEO4J_INITIAL_PASSWORD}" ]; then
2630
echo "executeQuery requires environment variable NEO4J_INITIAL_PASSWORD to be set first. Use 'export NEO4J_INITIAL_PASSWORD=<your-own-password>'." >&2
@@ -30,13 +34,15 @@ fi
3034
# Input Arguments: Initialize arguments and set default values for optional ones
3135
cypher_query_file_name=""
3236
no_source_reference=false
37+
omit_query_error_highlighting=false
3338
query_parameters=""
3439

3540
# Input Arguments: Function to print usage information
3641
print_usage() {
37-
echo "executeQuery Usage: $0 <filename> [--no-source-reference-column]" >&2
42+
echo "executeQuery Usage: $0 <filename> [--no-source-reference-column] [--omit-query-error-highlighting]" >&2
3843
echo "Options:" >&2
3944
echo " --no-source-reference-column: Exclude the source reference column" >&2
45+
echo " --omit-query-error-highlighting: Log query errors in same color as infos" >&2
4046
}
4147

4248
# Input Arguments: Parse the command-line arguments
@@ -48,6 +54,10 @@ while [[ $# -gt 0 ]]; do
4854
no_source_reference=true
4955
shift
5056
;;
57+
--omit_query_error_highlighting)
58+
omit_query_error_highlighting=true
59+
shift
60+
;;
5161
*)
5262
if [[ -z "${cypher_query_file_name}" ]]; then
5363
# Input Arguments: Read the first unnamed input argument containing the name of the cypher file
@@ -78,6 +88,13 @@ done
7888

7989
#echo "executeQuery: query_parameters: ${query_parameters}"
8090

91+
# Set the color for error messages
92+
error_message_color="${ERROR_COLOR}"
93+
if [ "${omit_query_error_highlighting}" = "true" ] ; then
94+
error_message_color="${NO_COLOR}"
95+
echo "executeQuery: Ommiting error highlighting" >&2
96+
fi
97+
8198
# Read the file that contains the Cypher query
8299
original_cypher_query=$(<"${cypher_query_file_name}")
83100
#echo "executeQuery: Original Query: $original_cypher_query"
@@ -102,21 +119,18 @@ if ! cypher_query_result=$(curl --silent -S --fail-with-body -H Accept:applicati
102119
"http://localhost:${NEO4J_HTTP_PORT}/${NEO4J_HTTP_TRANSACTION_ENDPOINT}" \
103120
-d "${cypher_query_for_api}" 2>&1) ;
104121
then
105-
redColor='\033[0;31m'
106-
noColor='\033[0m'
107-
echo -e "${redColor}${cypher_query_file_name}: ${cypher_query_result}${noColor}" >&2
108-
echo -e "${redColor}Parameters: ${query_parameters}${noColor}" >&2
122+
echo -e "${error_message_color}${cypher_query_file_name}: ${cypher_query_result}${NO_COLOR}" >&2
123+
echo -e "${error_message_color}Parameters: ${query_parameters}${NO_COLOR}" >&2
109124
exit 1
110125
fi
111126
#echo "executeQuery: Cypher Query OK Result: ${cypher_query_result}"
112127

113-
# If there is a error message print it to syserr >&2 in red color
128+
# If there is a error message print it to syserr >&2 in error color
114129
error_message=$( echo "${cypher_query_result}" | jq -r '.errors[0] // empty' )
115-
if [[ -n "${error_message}" ]]; then
116-
redColor='\033[0;31m'
117-
noColor='\033[0m'
118-
echo -e "${redColor}${cypher_query_file_name}: ${error_message}${noColor}" >&2
119-
echo -e "${redColor}Parameters: ${query_parameters}${noColor}" >&2
130+
if [[ -n "${error_message}" ]]; then
131+
# Set the message color to red if the query errors should be highlighted
132+
echo -e "${error_message_color}${cypher_query_file_name}: ${error_message}${NO_COLOR}" >&2
133+
echo -e "${error_message_color}Parameters: ${query_parameters}${NO_COLOR}" >&2
120134
exit 1
121135
fi
122136

scripts/projectionFunctions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ createUndirectedJavaTypeDependencyProjection() {
238238
execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_2_Delete_Subgraph.cypher" "${@}" >/dev/null
239239

240240
local projectionResult
241-
projectionResult=$( execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_4c_Create_Undirected_Type_Projection.cypher" "${@}")
241+
projectionResult=$( execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_4c_Create_Undirected_Java_Type_Projection.cypher" "${@}")
242242
if is_csv_column_greater_zero "${projectionResult}" "relationshipCount"; then
243243
true;
244244
else

scripts/reports/CentralityCsv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ TYPE_PROJECTION_UNDIRECTED="dependencies_projection=type-centrality-undirected"
407407
TYPE_NODE="dependencies_projection_node=Type"
408408
TYPE_WEIGHT="dependencies_projection_weight_property=weight"
409409

410-
if createDirectedJavaTypeDependencyProjection "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"; then
410+
if createDirectedJavaTypeDependencyProjection "${TYPE_PROJECTION}"; then
411411
runCentralityAlgorithms "${TYPE_PROJECTION}" "${TYPE_NODE}" "${TYPE_WEIGHT}"
412412
fi
413413
if createUndirectedJavaTypeDependencyProjection "${TYPE_PROJECTION_UNDIRECTED}"; then

scripts/reports/compilations/CsvReports.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
99
set -o errexit -o pipefail
1010

11+
# Overrideable Constants (defaults also defined in sub scripts)
12+
LOG_GROUP_START=${LOG_GROUP_START:-"::group::"} # Prefix to start a log group. Defaults to GitHub Actions log group start command.
13+
LOG_GROUP_END=${LOG_GROUP_END:-"::endgroup::"} # Prefix to end a log group. Defaults to GitHub Actions log group end command.
14+
1115
## Get this "scripts/reports/compilations" directory if not already set.
1216
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
1317
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
@@ -19,7 +23,14 @@ REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:-$(dirname -- "${REPORT_COMPILATIONS_SCR
1923
echo "CsvReports: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR}"
2024

2125
# Run all report scripts
22-
for report_script_file in "${REPORTS_SCRIPT_DIR}"/*Csv.sh; do
23-
echo "CsvReports: Starting ${report_script_file}...";
26+
for report_script_file in "${REPORTS_SCRIPT_DIR}"/*Csv.sh; do
27+
report_script_filename=$(basename -- "${report_script_file}")
28+
29+
echo "${LOG_GROUP_START}${report_script_file}";
30+
echo "CsvReports: $(date +'%Y-%m-%dT%H:%M:%S%z') Starting ${report_script_filename}...";
31+
2432
source "${report_script_file}"
25-
done
33+
34+
echo "CsvReports: $(date +'%Y-%m-%dT%H:%M:%S%z') Finished ${report_script_filename}";
35+
echo "${LOG_GROUP_END}";
36+
done

scripts/reports/compilations/JupyterReports.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
1212
set -o errexit -o pipefail
1313

14+
# Overrideable Constants (defaults also defined in sub scripts)
15+
LOG_GROUP_START=${LOG_GROUP_START:-"::group::"} # Prefix to start a log group. Defaults to GitHub Actions log group start command.
16+
LOG_GROUP_END=${LOG_GROUP_END:-"::endgroup::"} # Prefix to end a log group. Defaults to GitHub Actions log group end command.
17+
1418
## Get this "scripts/reports/compilations" directory if not already set.
1519
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
1620
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
@@ -29,9 +33,15 @@ echo "JupyterReports: SCRIPTS_DIR=${SCRIPTS_DIR}"
2933
JUPYTER_NOTEBOOK_DIRECTORY=${JUPYTER_NOTEBOOK_DIRECTORY:-"${SCRIPTS_DIR}/../jupyter"} # Repository directory containing the Jupyter Notebooks
3034
echo "JupyterReports: JUPYTER_NOTEBOOK_DIRECTORY=${JUPYTER_NOTEBOOK_DIRECTORY}"
3135

32-
# Run all report scripts
36+
# Run all jupiter notebooks
3337
for jupyter_notebook_file in "${JUPYTER_NOTEBOOK_DIRECTORY}"/*.ipynb; do
34-
jupyter_notebook_file=$( basename "${jupyter_notebook_file}")
35-
echo "JupyterReports: Executing ${jupyter_notebook_file}...";
36-
source "${SCRIPTS_DIR}/executeJupyterNotebookReport.sh" --jupyterNotebook "${jupyter_notebook_file}"
38+
jupyter_notebook_filename=$(basename -- "${jupyter_notebook_file}")
39+
40+
echo "${LOG_GROUP_START}${jupyter_notebook_filename}";
41+
echo "JupyterReports: $(date +'%Y-%m-%dT%H:%M:%S%z') Starting ${jupyter_notebook_filename}...";
42+
43+
source "${SCRIPTS_DIR}/executeJupyterNotebookReport.sh" --jupyterNotebook "${jupyter_notebook_filename}"
44+
45+
echo "JupyterReports: $(date +'%Y-%m-%dT%H:%M:%S%z') Finished ${jupyter_notebook_filename}";
46+
echo "${LOG_GROUP_END}";
3747
done

scripts/reports/compilations/VisualizationReports.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
1212
set -o errexit -o pipefail
1313

14+
# Overrideable Constants (defaults also defined in sub scripts)
15+
LOG_GROUP_START=${LOG_GROUP_START:-"::group::"} # Prefix to start a log group. Defaults to GitHub Actions log group start command.
16+
LOG_GROUP_END=${LOG_GROUP_END:-"::endgroup::"} # Prefix to end a log group. Defaults to GitHub Actions log group end command.
17+
1418
## Get this "scripts/reports/compilations" directory if not already set.
1519
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
1620
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
@@ -21,8 +25,15 @@ echo "VisualizationReports: REPORT_COMPILATIONS_SCRIPT_DIR=${REPORT_COMPILATIONS
2125
REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:-$(dirname -- "${REPORT_COMPILATIONS_SCRIPT_DIR}")}
2226
echo "VisualizationReports: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR}"
2327

24-
# Run all report scripts
25-
for report_script_file in "${REPORTS_SCRIPT_DIR}"/*Visualization.sh; do
26-
echo "VisualizationReports: Starting ${report_script_file}...";
27-
source "${report_script_file}"
28+
# Run all visualization scripts
29+
for visualization_script_file in "${REPORTS_SCRIPT_DIR}"/*Visualization.sh; do
30+
visualization_script_filename=$(basename -- "${visualization_script_file}")
31+
32+
echo "${LOG_GROUP_START}${visualization_script_filename}";
33+
echo "VisualizationReports: $(date +'%Y-%m-%dT%H:%M:%S%z') Starting ${visualization_script_filename}...";
34+
35+
source "${visualization_script_file}"
36+
37+
echo "VisualizationReports: $(date +'%Y-%m-%dT%H:%M:%S%z') Finished ${visualization_script_filename}";
38+
echo "${LOG_GROUP_END}";
2839
done

scripts/waitForNeo4jHttpFunctions.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ echo "waitForNeo4jHttp: CYPHER_DIR=${CYPHER_DIR}"
2424
# Define functions to execute a Cypher query from within the given file (first and only argument)
2525
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
2626

27-
queryDatabase() {
28-
execute_cypher "${CYPHER_DIR}/Count_nodes_and_relationships.cypher" "--no-source-reference-column"
27+
testDatabase() {
28+
execute_cypher "${CYPHER_DIR}/Count_nodes_and_relationships.cypher" "--no-source-reference-column" "--omit_query_error_highlighting"
2929
}
3030

3131
isDatabaseQueryable() {
3232
local cypher_elements_query_result
33-
if cypher_elements_query_result=$(queryDatabase);
33+
if cypher_elements_query_result=$(testDatabase);
3434
then
3535
echo "true"
3636
else
@@ -56,7 +56,7 @@ waitUntilDatabaseIsQueryable() {
5656
continue; # query failed -> try again
5757
fi
5858

59-
local queryResult=$(queryDatabase || true)
59+
local queryResult=$(testDatabase || true)
6060
if [[ -n "${queryResult}" ]]; then
6161
echo "waitForNeo4jHttp: Successfully accessed Neo4j HTTP API."
6262
echo "${queryResult}"

0 commit comments

Comments
 (0)