Skip to content

Commit

Permalink
Refactor error handling to ensure that .env misconfigurations do not …
Browse files Browse the repository at this point in the history
…go unnoticed.

- If NODE_DATAAPI_URL is not defined, we will continue to log error every interval.
- If the constructed checkUrl is invalid, we will continue to log error every interval
  • Loading branch information
pschork committed May 12, 2024
1 parent 3190725 commit 3dfe830
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions node/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GITCOMMIT := $(shell git rev-parse --short HEAD)
GITDATE := $(shell git log -1 --format=%cd --date=unix)

# GitVersion provides the semantic versioning for the project
# GitVersion provides the semantic versioning for the project. If docker is not installed, semver fallsback to 0.0.0
SEMVER := $(shell docker run --rm --volume "${PWD}/../:/repo" gittools/gitversion:5.12.0 /repo -output json -showvariable SemVer)
ifeq ($(SEMVER), )
SEMVER = "0.0.0"
Expand All @@ -19,7 +19,7 @@ docker: docker-node docker-plugin
docker-node:
cd ../ && docker build --build-arg SEMVER=${SEMVER} --build-arg GITCOMMIT=${GITCOMMIT} --build-arg GITDATE=${GITDATE} . -t opr-node:${SEMVER} -t opr-node:latest -f node/cmd/Dockerfile

docker-nodeplugin:
docker-plugin:
cd ../ && docker build --build-arg SEMVER=${SEMVER} --build-arg GITCOMMIT=${GITCOMMIT} --build-arg GITDATE=${GITDATE} . -t opr-nodeplugin:${SEMVER} -t opr-nodeplugin:latest -f node/plugin/cmd/Dockerfile

semver:
Expand Down
25 changes: 13 additions & 12 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,6 @@ func (n *Node) checkNodeReachability() {
n.Logger.Warn("Node reachability checks disabled!!! ReachabilityPollIntervalSec set to 0")
return
}
if n.Config.DataApiUrl == "" {
n.Logger.Error("Node reachability checks disabled!!! DataAPI URL is not configured")
return
}

checkUrl, err := url.Parse(fmt.Sprintf("%s/api/v1/operators-info/port-check?operator_id=%s", n.Config.DataApiUrl, n.Config.ID.Hex()))
if err != nil {
n.Logger.Error("Node reachability checks disabled!!! Failed to parse reachability check url", err)
return
}

n.Logger.Info("Start nodeReachabilityCheck goroutine in background to check the reachability of the operator node")
ticker := time.NewTicker(time.Duration(n.Config.ReachabilityPollIntervalSec) * time.Second)
Expand All @@ -491,17 +481,28 @@ func (n *Node) checkNodeReachability() {
for {
<-ticker.C

if n.Config.DataApiUrl == "" {
n.Logger.Error("Unable to perform reachability check - NODE_DATAAPI_URL is not defined in .env")
continue
}

checkUrl, err := url.Parse(fmt.Sprintf("%s/api/v1/operators-info/port-check?operator_id=%s", n.Config.DataApiUrl, n.Config.ID.Hex()))
if err != nil {
n.Logger.Error("Reachability check failed - invalid check url", err, "checkUrl", checkUrl.String())
return
}

n.Logger.Info("Calling reachability check", "url", checkUrl.String())

resp, err := http.Get(checkUrl.String())
if err != nil {
n.Logger.Error("Reachability check failed", err)
n.Logger.Error("Reachability check request failed", err)
continue
} else if resp.StatusCode == 404 {
n.Logger.Error("Reachability check failed - operator id not found", "status", resp.StatusCode, "operator_id", n.Config.ID.Hex())
continue
} else if resp.StatusCode != 200 {
n.Logger.Error("Reachability check failed", "status", resp.StatusCode)
n.Logger.Error("Reachability check request failed", "status", resp.StatusCode)
continue
}

Expand Down

0 comments on commit 3dfe830

Please sign in to comment.