Skip to content

Commit

Permalink
Add -I option to ignore health errors (#200)
Browse files Browse the repository at this point in the history
* Add -I option to ignore health errors
* minor doc
* Update to 1.7.0
  • Loading branch information
tmiddlet2666 committed May 17, 2024
1 parent ad8df66 commit 71248b9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# The version of the CLI being build - this should be a valid SemVer format
VERSION ?= 1.7.0
MILESTONE ?= -rc1
MILESTONE ?=
SHELL := /bin/bash

# Maven version is always 1.0.0 as it is only for testing
Expand Down
1 change: 1 addition & 0 deletions docs/reference/90_health.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ http://127.0.0.1:52136/ 2 200 200 200 200 4
All health endpoints are safe reached in 21 seconds
----
NOTE: You can add `-I` option when using the `-n` name service option, to ignore errors connecting to the name service.
=== See Also
Expand Down
40 changes: 26 additions & 14 deletions pkg/cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
nslookupAddress string
healthEndpoints string
getNodeID bool
ignoreNSErrors bool
healthTimeout int32
)

Expand Down Expand Up @@ -199,12 +200,11 @@ You may also specify -T option to wait until all health endpoints are safe.`,
}

if getNodeID {
// get the dataf etcher if we are wanting the node ID
// get the data fetcher if we are wanting the node ID
_, dataFetcher, err = GetConnectionAndDataFetcher()
if err != nil {
return err
}

}

// retrieve the list of endpoints using either of the 3 methods
Expand All @@ -224,34 +224,41 @@ You may also specify -T option to wait until all health endpoints are safe.`,
startTime := time.Now()

for {
var emptyData = false
if nslookupAddress != "" {
// use nslookup to look up the health endpoint of the cluster
ns, err = discovery.Open(nslookupAddress, timeout)
if err != nil {
return fmt.Errorf("unable to use nslookup against %s: %v", nslookupAddress, err)
if ignoreNSErrors {
emptyData = true
clusterName = "Not available"
} else {
return fmt.Errorf("unable to use nslookup against %s: %v", nslookupAddress, err)
}
}

result, err = ns.Lookup("NameService/string/health/HTTPHealthURL")
if err != nil {
return err
}
if !emptyData {
result, err = ns.Lookup("NameService/string/health/HTTPHealthURL")
if err != nil {
return err
}

clusterName, err = ns.Lookup("Cluster/name")
if err != nil {
return err
}
clusterName, err = ns.Lookup("Cluster/name")
if err != nil {
return err
}

_ = ns.Close()
_ = ns.Close()
}

// format returned is [http://127.0.0.1:6676/, http://127.0.0.1:6677/]
result = strings.Replace(result, "[", "", 1)
result = strings.Replace(result, "]", "", 1)
result = strings.Replace(result, " ", "", -1)
endpoints, err = parseHealthEndpoints(result)
if err != nil {
if err != nil && !emptyData {
return err
}

}

monitoringData := gatherMonitorData(dataFetcher, endpoints)
Expand Down Expand Up @@ -297,6 +304,10 @@ You may also specify -T option to wait until all health endpoints are safe.`,
}

func isMonitoringDataSafe(monitoringData []config.HealthMonitoring) bool {
if len(monitoringData) == 0 {
return false
}

for _, v := range monitoringData {
if v.Safe != http200 || v.Ready != http200 || v.Live != http200 || v.Started != http200 {
return false
Expand Down Expand Up @@ -388,6 +399,7 @@ func init() {
getHealthCmd.Flags().BoolVarP(&healthSummary, "summary", "S", false, "if true, returns a summary across nodes")

monitorHealthCmd.Flags().BoolVarP(&getNodeID, "node-id", "N", false, "if true, returns the node id using the current context")
monitorHealthCmd.Flags().BoolVarP(&ignoreNSErrors, "ignore-errors", "I", false, "if true, ignores nslookup errors")
monitorHealthCmd.Flags().Int32VarP(&timeout, "timeout", "t", 30, timeoutMessage)
monitorHealthCmd.Flags().StringVarP(&healthEndpoints, "endpoints", "e", "", "csv list of health endpoints")
monitorHealthCmd.Flags().StringVarP(&nslookupAddress, "nslookup", "n", "", "host:port to connect to to lookup health endpoints")
Expand Down
6 changes: 5 additions & 1 deletion pkg/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,11 @@ func parseHealthEndpoints(endpointCSV string) ([]string, error) {
endpoints = strings.Split(endpointCSV, ",")
)

// validate them
if endpointCSV == "[]" {
return validEndpoints, nil
}

// validate the endpoints
for _, v := range endpoints {
_, err := url.ParseRequestURI(v)
if err != nil {
Expand Down

0 comments on commit 71248b9

Please sign in to comment.