From 176fa9fd6c7137c60ce053ef787a6d8c567b9a59 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Thu, 15 Aug 2024 11:55:55 -0600 Subject: [PATCH 01/10] Adding Started Log Message Signed-off-by: Alfredo Gutierrez --- server/src/main/java/com/hedera/block/server/Server.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/src/main/java/com/hedera/block/server/Server.java b/server/src/main/java/com/hedera/block/server/Server.java index a454af26f..53538ec7e 100644 --- a/server/src/main/java/com/hedera/block/server/Server.java +++ b/server/src/main/java/com/hedera/block/server/Server.java @@ -109,9 +109,7 @@ public static void main(final String[] args) { webServer.start(); // Log the server status - LOGGER.log( - System.Logger.Level.INFO, - "Block Node Server started at port: " + webServer.port()); + LOGGER.log(System.Logger.Level.INFO, "Block Node Server started at port: " + webServer.port()); } catch (IOException e) { throw new RuntimeException(e); } From 13cff89aa2074f91661654a0baed9f716566a99f Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Thu, 15 Aug 2024 12:02:09 -0600 Subject: [PATCH 02/10] Added HealthService interface and its implementation, unit test and integration with Server Signed-off-by: Alfredo Gutierrez --- server/src/main/java/com/hedera/block/server/Server.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/hedera/block/server/Server.java b/server/src/main/java/com/hedera/block/server/Server.java index 53538ec7e..a454af26f 100644 --- a/server/src/main/java/com/hedera/block/server/Server.java +++ b/server/src/main/java/com/hedera/block/server/Server.java @@ -109,7 +109,9 @@ public static void main(final String[] args) { webServer.start(); // Log the server status - LOGGER.log(System.Logger.Level.INFO, "Block Node Server started at port: " + webServer.port()); + LOGGER.log( + System.Logger.Level.INFO, + "Block Node Server started at port: " + webServer.port()); } catch (IOException e) { throw new RuntimeException(e); } From 7c6f84a48dbabd09f86522aff734d24d603f98e8 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Thu, 15 Aug 2024 15:09:11 -0600 Subject: [PATCH 03/10] Adding CI Check for Runtime issues, created a smoke-test script for verifying that everything works as expected. Signed-off-by: Alfredo Gutierrez --- .github/workflows/helm-charts.yaml | 3 +- .github/workflows/smoke-test.yaml | 83 +++++++++++++++++++ server/src/test/resources/get-block.sh | 25 ++++++ server/src/test/resources/smoke-test.sh | 106 ++++++++++++++++++++++++ 4 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/smoke-test.yaml create mode 100755 server/src/test/resources/get-block.sh create mode 100755 server/src/test/resources/smoke-test.sh diff --git a/.github/workflows/helm-charts.yaml b/.github/workflows/helm-charts.yaml index 7f71396e8..7a3a4e872 100644 --- a/.github/workflows/helm-charts.yaml +++ b/.github/workflows/helm-charts.yaml @@ -18,7 +18,8 @@ name: Lint and Test Charts on: pull_request jobs: - lint-test: + lint-install-test: + name: Lint and Install Charts runs-on: ubuntu-latest steps: - name: Harden Runner diff --git a/.github/workflows/smoke-test.yaml b/.github/workflows/smoke-test.yaml new file mode 100644 index 000000000..c6f192ac6 --- /dev/null +++ b/.github/workflows/smoke-test.yaml @@ -0,0 +1,83 @@ +## +# Copyright (C) 2024 Hedera Hashgraph, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## +name: "PR Gradle Checks" +on: + push: + branches: + - main + - release/* + pull_request: + branches: + - "*" + +defaults: + run: + shell: bash + +env: + GRADLE_EXEC: ./gradlew + +jobs: + smoke-test: + name: "Smoke Tests" + runs-on: [ self-hosted, Linux, medium, ephemeral ] + steps: + - name: Harden Runner + uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 + with: + egress-policy: audit + + - name: Checkout code + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + fetch-depth: 0 + + - name: Expand Shallow Clone for Spotless + run: | + if [ -f .git/shallow ]; then + git fetch --unshallow --no-recurse-submodules + else + echo "Repository is not shallow, no need to unshallow." + fi + + - name: Set up JDK 21 + uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 + with: + distribution: 'temurin' + java-version: '21' + + - name: Cache Gradle packages + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Run application in background, capture logs, and save PID in a variable + run: | + nohup ./gradlew run > app.log 2>&1 & + APP_PID=$! + echo "Application started with PID $APP_PID" + sleep 5 + + - name: Smoke Test + run: ./server/src/test/resources/smoke-test.sh app.log + + - name: Kill application + run: kill $APP_PID diff --git a/server/src/test/resources/get-block.sh b/server/src/test/resources/get-block.sh new file mode 100755 index 000000000..c441d1aed --- /dev/null +++ b/server/src/test/resources/get-block.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +usage_error() { + echo "Usage: $0 " + exit 1 +} + +# An integer is expected as the first parameter +if [ "$#" -lt 1 ] || ! [[ "$1" =~ ^[0-9]+$ ]]; then + usage_error +fi + +# If the script reaches here, the parameters are valid +echo "Param is: $1" + +# Use environment variables or default values +GRPC_SERVER=${GRPC_SERVER:-"localhost:8080"} +GRPC_METHOD=${GRPC_METHOD:-"BlockStreamGrpcService/singleBlock"} +PATH_TO_PROTO=${PATH_TO_PROTO:-"../../../../protos/src/main/protobuf/blockstream.proto"} +PROTO_IMPORT_PATH=${PROTO_IMPORT_PATH:-"../../../../protos/src/main/protobuf"} + +echo "Requesting block $1..." + +# Response block messages from the gRPC server are printed to stdout. +echo "{\"block_number\": $1}" | grpcurl -plaintext -import-path $PROTO_IMPORT_PATH -proto $PATH_TO_PROTO -d @ $GRPC_SERVER $GRPC_METHOD diff --git a/server/src/test/resources/smoke-test.sh b/server/src/test/resources/smoke-test.sh new file mode 100755 index 000000000..787b49c1a --- /dev/null +++ b/server/src/test/resources/smoke-test.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +# Variable to track whether shutdown has been called +SHUTDOWN_CALLED=0 + +# Function to shut down the background processes +shutdown() { + if [[ $SHUTDOWN_CALLED -eq 1 ]]; then + return + fi + SHUTDOWN_CALLED=1 + + echo "Shutting down background processes..." + + if [[ -n "$PRODUCER_PID" ]]; then + if kill -0 $PRODUCER_PID 2>/dev/null; then + kill $PRODUCER_PID + wait $PRODUCER_PID 2>/dev/null + echo "Producer process $PRODUCER_PID terminated." + else + echo "Error: Producer process $PRODUCER_PID has already terminated." + echo "Producer logs:" + cat producer.log + exit 1 + fi + fi + + if [[ -n "$CONSUMER_PID" ]]; then + if kill -0 $CONSUMER_PID 2>/dev/null; then + kill $CONSUMER_PID + wait $CONSUMER_PID 2>/dev/null + echo "Consumer process $CONSUMER_PID terminated." + else + echo "Error: Consumer process $CONSUMER_PID has already terminated." + echo "Consumer logs:" + cat consumer.log + exit 1 + fi + fi +} + +# Trap any exit signal to ensure everything is cleaned up +trap "shutdown; exit 1" ERR SIGINT SIGTERM + +# 1. Verify that the logs have the startup pattern (only if log file is provided) +LOG_FILE=$1 +STARTUP_PATTERN="Expected startup pattern" + +if [[ -n "$LOG_FILE" ]]; then + if grep -q "$STARTUP_PATTERN" "$LOG_FILE"; then + echo "Startup pattern found in logs." + else + echo "Startup pattern not found in logs." + exit 1 + fi +else + echo "No log file provided, skipping startup pattern check." +fi + +# 2. Start the producer script with parameter 1 and save logs to producer.log +./producer.sh 1 > producer.log 2>&1 & +PRODUCER_PID=$! +echo "Started producer with PID $PRODUCER_PID, logging to producer.log" + +# 3. Start the consumer script with parameters 1 1000 and save logs to consumer.log +./consumer.sh 1 1000 > consumer.log 2>&1 & +CONSUMER_PID=$! +echo "Started consumer with PID $CONSUMER_PID, logging to consumer.log" + +# Sleep time after starting the consumer +sleep 5 # Adjust sleep time as needed + +# 4. Run the get-block script with parameter 1 and save logs to get-block.log +if ! ./get-block.sh 1 > get-block.log 2>&1; then + echo "get-block.sh failed." + echo "get-block logs:" + cat get-block.log + shutdown + exit 1 +fi +echo "get-block.sh executed successfully." + +# 5. Call the endpoints /health/liveness and /health/readiness +LIVENESS_URL="http://localhost:8080/health/liveness" +READINESS_URL="http://localhost:8080/health/readiness" + +if ! curl -f $LIVENESS_URL; then + echo "/health/liveness endpoint failed." + shutdown + exit 1 +fi +echo "/health/liveness endpoint is healthy." + +if ! curl -f $READINESS_URL; then + echo "/health/readiness endpoint failed." + shutdown + exit 1 +fi +echo "/health/readiness endpoint is ready." + +# 6. Shut everything down +shutdown + +# 7. Return success +echo "Smoke test completed successfully." +exit 0 From bbfe7bd24aa9283105ae5aee60f1d79df0aeaade Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Thu, 15 Aug 2024 18:58:46 -0600 Subject: [PATCH 04/10] Fix moving the logs to file. Signed-off-by: Alfredo Gutierrez --- .github/workflows/smoke-test.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/smoke-test.yaml b/.github/workflows/smoke-test.yaml index c6f192ac6..a714412d4 100644 --- a/.github/workflows/smoke-test.yaml +++ b/.github/workflows/smoke-test.yaml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. ## -name: "PR Gradle Checks" +name: "Smoke Test" on: push: branches: @@ -69,12 +69,15 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- + - name: Build application + run: ${{ env.GRADLE_EXEC }} build + - name: Run application in background, capture logs, and save PID in a variable run: | - nohup ./gradlew run > app.log 2>&1 & + ${{ env.GRADLE_EXEC }} run 2> output.log < /dev/null APP_PID=$! echo "Application started with PID $APP_PID" - sleep 5 + sleep 10 - name: Smoke Test run: ./server/src/test/resources/smoke-test.sh app.log From a0524d5728b3f0afdb9ba69f2736833d368fcf35 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Thu, 15 Aug 2024 19:55:05 -0600 Subject: [PATCH 05/10] fixes issues Signed-off-by: Alfredo Gutierrez --- .github/workflows/smoke-test.yaml | 23 +++++++++++++++-------- server/src/test/resources/smoke-test.sh | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/smoke-test.yaml b/.github/workflows/smoke-test.yaml index a714412d4..542eeda1c 100644 --- a/.github/workflows/smoke-test.yaml +++ b/.github/workflows/smoke-test.yaml @@ -59,6 +59,13 @@ jobs: distribution: 'temurin' java-version: '21' + - name: Install grpcurl + run: | + curl -L https://github.com/fullstorydev/grpcurl/releases/download/v1.8.7/grpcurl_1.8.7_linux_x86_64.tar.gz -o grpcurl.tar.gz + sudo tar -xzf grpcurl.tar.gz -C /usr/local/bin grpcurl + rm grpcurl.tar.gz + + - name: Cache Gradle packages uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 with: @@ -72,15 +79,15 @@ jobs: - name: Build application run: ${{ env.GRADLE_EXEC }} build - - name: Run application in background, capture logs, and save PID in a variable + - name: Run application in background, capture logs in app.log run: | - ${{ env.GRADLE_EXEC }} run 2> output.log < /dev/null - APP_PID=$! + ${{ env.GRADLE_EXEC }} run 2> server/src/test/resources/app.log < /dev/null & echo "Application started with PID $APP_PID" sleep 10 - - - name: Smoke Test - run: ./server/src/test/resources/smoke-test.sh app.log - - name: Kill application - run: kill $APP_PID + - name: Print App Logs + run: cat server/src/test/resources/app.log + + - name: Smoke Test + working-directory: server/src/test/resources/ + run: ./smoke-test.sh app.log diff --git a/server/src/test/resources/smoke-test.sh b/server/src/test/resources/smoke-test.sh index 787b49c1a..b0ee4c50c 100755 --- a/server/src/test/resources/smoke-test.sh +++ b/server/src/test/resources/smoke-test.sh @@ -44,7 +44,7 @@ trap "shutdown; exit 1" ERR SIGINT SIGTERM # 1. Verify that the logs have the startup pattern (only if log file is provided) LOG_FILE=$1 -STARTUP_PATTERN="Expected startup pattern" +STARTUP_PATTERN="Block Node Server started at port" if [[ -n "$LOG_FILE" ]]; then if grep -q "$STARTUP_PATTERN" "$LOG_FILE"; then From a92f48cfc65d817e522b937efa43c843fc5d0d60 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Mon, 19 Aug 2024 10:08:05 -0600 Subject: [PATCH 06/10] changed order of init, first consumer then producer. Signed-off-by: Alfredo Gutierrez --- server/src/test/resources/smoke-test.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/test/resources/smoke-test.sh b/server/src/test/resources/smoke-test.sh index b0ee4c50c..fc24b8e90 100755 --- a/server/src/test/resources/smoke-test.sh +++ b/server/src/test/resources/smoke-test.sh @@ -57,16 +57,16 @@ else echo "No log file provided, skipping startup pattern check." fi -# 2. Start the producer script with parameter 1 and save logs to producer.log -./producer.sh 1 > producer.log 2>&1 & -PRODUCER_PID=$! -echo "Started producer with PID $PRODUCER_PID, logging to producer.log" - -# 3. Start the consumer script with parameters 1 1000 and save logs to consumer.log +# 2. Start the consumer script with parameters 1 1000 and save logs to consumer.log ./consumer.sh 1 1000 > consumer.log 2>&1 & CONSUMER_PID=$! echo "Started consumer with PID $CONSUMER_PID, logging to consumer.log" +# 3. Start the producer script with parameter 1 and save logs to producer.log +./producer.sh 1 > producer.log 2>&1 & +PRODUCER_PID=$! +echo "Started producer with PID $PRODUCER_PID, logging to producer.log" + # Sleep time after starting the consumer sleep 5 # Adjust sleep time as needed From b3d7cde11afc2e19a531122c3b74f1e27a3aeaf8 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Mon, 19 Aug 2024 15:50:58 -0600 Subject: [PATCH 07/10] update runs-on Signed-off-by: Alfredo Gutierrez --- .github/workflows/smoke-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoke-test.yaml b/.github/workflows/smoke-test.yaml index 542eeda1c..e2935a070 100644 --- a/.github/workflows/smoke-test.yaml +++ b/.github/workflows/smoke-test.yaml @@ -33,7 +33,7 @@ env: jobs: smoke-test: name: "Smoke Tests" - runs-on: [ self-hosted, Linux, medium, ephemeral ] + runs-on: block-node-linux-medium steps: - name: Harden Runner uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 From 999d4b3426532a029c53c3489b2235845c936796 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Mon, 19 Aug 2024 15:57:52 -0600 Subject: [PATCH 08/10] update health to healthz endpoints Signed-off-by: Alfredo Gutierrez --- server/src/test/resources/smoke-test.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/src/test/resources/smoke-test.sh b/server/src/test/resources/smoke-test.sh index fc24b8e90..203975fd9 100755 --- a/server/src/test/resources/smoke-test.sh +++ b/server/src/test/resources/smoke-test.sh @@ -81,22 +81,23 @@ fi echo "get-block.sh executed successfully." # 5. Call the endpoints /health/liveness and /health/readiness -LIVENESS_URL="http://localhost:8080/health/liveness" -READINESS_URL="http://localhost:8080/health/readiness" +SERVER_URL="http://localhost:8080" +LIVENESS_URL="/healthz/liveness" +READINESS_URL="/healthz/readiness" -if ! curl -f $LIVENESS_URL; then - echo "/health/liveness endpoint failed." +if ! curl -f $SERVER_URL$LIVENESS_URL; then + echo "$LIVENESS_URL failed." shutdown exit 1 fi -echo "/health/liveness endpoint is healthy." +echo "$LIVENESS_URL endpoint is healthy." -if ! curl -f $READINESS_URL; then - echo "/health/readiness endpoint failed." +if ! curl -f $SERVER_URL$READINESS_URL; then + echo "$READINESS_URL endpoint failed." shutdown exit 1 fi -echo "/health/readiness endpoint is ready." +echo "$READINESS_URL endpoint is ready."z # 6. Shut everything down shutdown From 68abcd492ef8be021405f9b2352258b472d3b059 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Mon, 19 Aug 2024 16:09:22 -0600 Subject: [PATCH 09/10] removing extra unneeded char Signed-off-by: Alfredo Gutierrez --- server/src/test/resources/smoke-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/test/resources/smoke-test.sh b/server/src/test/resources/smoke-test.sh index 203975fd9..5d4eb12be 100755 --- a/server/src/test/resources/smoke-test.sh +++ b/server/src/test/resources/smoke-test.sh @@ -97,7 +97,7 @@ if ! curl -f $SERVER_URL$READINESS_URL; then shutdown exit 1 fi -echo "$READINESS_URL endpoint is ready."z +echo "$READINESS_URL endpoint is ready." # 6. Shut everything down shutdown From e1c3bf2791404acb1f7005f81b937c26b5d113a6 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Mon, 19 Aug 2024 16:11:27 -0600 Subject: [PATCH 10/10] improved wording of healthz endpoints Signed-off-by: Alfredo Gutierrez --- server/src/test/resources/smoke-test.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/src/test/resources/smoke-test.sh b/server/src/test/resources/smoke-test.sh index 5d4eb12be..efad6d9c8 100755 --- a/server/src/test/resources/smoke-test.sh +++ b/server/src/test/resources/smoke-test.sh @@ -82,22 +82,22 @@ echo "get-block.sh executed successfully." # 5. Call the endpoints /health/liveness and /health/readiness SERVER_URL="http://localhost:8080" -LIVENESS_URL="/healthz/liveness" -READINESS_URL="/healthz/readiness" +LIVENESS_ENDPOINT="/healthz/liveness" +READINESS_ENDPOINT="/healthz/readiness" -if ! curl -f $SERVER_URL$LIVENESS_URL; then - echo "$LIVENESS_URL failed." +if ! curl -f $SERVER_URL$LIVENESS_ENDPOINT; then + echo "$LIVENESS_ENDPOINT failed." shutdown exit 1 fi -echo "$LIVENESS_URL endpoint is healthy." +echo "$LIVENESS_ENDPOINT endpoint is healthy." -if ! curl -f $SERVER_URL$READINESS_URL; then - echo "$READINESS_URL endpoint failed." +if ! curl -f $SERVER_URL$READINESS_ENDPOINT; then + echo "$READINESS_ENDPOINT endpoint failed." shutdown exit 1 fi -echo "$READINESS_URL endpoint is ready." +echo "$READINESS_ENDPOINT endpoint is ready." # 6. Shut everything down shutdown