Skip to content

Commit

Permalink
NR-115126: fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
rogercoll committed Oct 6, 2023
1 parent 98a13c9 commit da95aa2
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions cmd/newrelic-infra/dnschecks/dnschecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const (
LOG_PREFIX = " ====== "
logPrefix = " ====== "
)

func RunChecks(
Expand Down Expand Up @@ -55,14 +55,14 @@ func RunChecks(
}

func startLogMessage(logger log.Entry, testName string) {
logger.Info(LOG_PREFIX + strings.ToUpper("Checking endpoint reachability using "+testName) + LOG_PREFIX)
logger.Info(logPrefix + strings.ToUpper("Checking endpoint reachability using "+testName) + logPrefix)
}

func endLogMessage(logger log.Entry, testName string, err error) {
if err != nil {
logger.WithError(err).Error(LOG_PREFIX + strings.ToUpper("Endpoint reachability using "+testName+" FAILED") + LOG_PREFIX)
logger.WithError(err).Error(logPrefix + strings.ToUpper("Endpoint reachability using "+testName+" FAILED") + logPrefix)
} else {
logger.Info(LOG_PREFIX + strings.ToUpper("Endpoint reachability using "+testName+" SUCCEED") + LOG_PREFIX)
logger.Info(logPrefix + strings.ToUpper("Endpoint reachability using "+testName+" SUCCEED") + logPrefix)
}
}

Expand All @@ -80,7 +80,8 @@ func checkEndpointReachable(
}
request = http2.WithTracer(request, "checkEndpointReachable")
client := backendhttp.GetHttpClient(timeout, transport)
if _, err = client.Do(request); err != nil {
var resp *http.Response
if resp, err = client.Do(request); err != nil {

Check failure on line 84 in cmd/newrelic-infra/dnschecks/dnschecks.go

View workflow job for this annotation

GitHub Actions / linter-linux / Run Linter

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 84 in cmd/newrelic-infra/dnschecks/dnschecks.go

View workflow job for this annotation

GitHub Actions / linter-macos / Lint tests

only one cuddle assignment allowed before if statement (wsl)

Check failure on line 84 in cmd/newrelic-infra/dnschecks/dnschecks.go

View workflow job for this annotation

GitHub Actions / linter-windows / Lint tests

only one cuddle assignment allowed before if statement (wsl)
if e2, ok := err.(net.Error); ok && (e2.Timeout() || e2.Temporary()) {
timedOut = true
}
Expand All @@ -89,6 +90,7 @@ func checkEndpointReachable(
timedOut = true
}
}
resp.Body.Close()

Check failure on line 93 in cmd/newrelic-infra/dnschecks/dnschecks.go

View workflow job for this annotation

GitHub Actions / linter-linux / Run Linter

expressions should not be cuddled with blocks (wsl)

Check failure on line 93 in cmd/newrelic-infra/dnschecks/dnschecks.go

View workflow job for this annotation

GitHub Actions / linter-macos / Lint tests

expressions should not be cuddled with blocks (wsl)

Check failure on line 93 in cmd/newrelic-infra/dnschecks/dnschecks.go

View workflow job for this annotation

GitHub Actions / linter-windows / Lint tests

expressions should not be cuddled with blocks (wsl)

endLogMessage(logger, "configured agent's HTTP client", err)

Expand All @@ -110,8 +112,11 @@ func checkEndpointReachableDefaultTransport(
logrus.WithError(err).Error(fmt.Sprintf("cannot Create request for %s", collectorURL))
} else {
req = http2.WithTracer(req, "checkEndpointReachable")
_, err = client.Do(req)
var resp *http.Response
resp, err = client.Do(req)
resp.Body.Close()
}

endLogMessage(logger, "plain HTTP transport", err)

return
Expand All @@ -125,7 +130,8 @@ func checkEndpointReachableDefaultHTTPHeadClient(
) (timedOut bool, err error) {

startLogMessage(logger, "plain HEAD request")
_, err = http.Head(collectorURL)
_, err = http.Head(collectorURL) //nolint

endLogMessage(logger, "plain HEAD request", err)
return
}
Expand Down Expand Up @@ -162,8 +168,11 @@ func checkEndpointReachableGoResolverCustom(
client := http.Client{}
client.Transport = customTransport
req = http2.WithTracer(req, "checkEndpointReachable")
_, err = http.DefaultClient.Do(req)
var resp *http.Response
resp, err = http.DefaultClient.Do(req)
resp.Body.Close()
}

endLogMessage(logger, "Golang DNS custom resolver", err)
return
}
Expand All @@ -187,6 +196,7 @@ func checkEndpointReachableCustomDNS(
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
}

return d.DialContext(ctx, network, "1.1.1.1:53")
}
dialer := &net.Dialer{
Expand All @@ -209,9 +219,12 @@ func checkEndpointReachableCustomDNS(
logrus.WithError(err).Error(fmt.Sprintf("cannot Create request for %s", collectorURL))
} else {
req = http2.WithTracer(req, "testing")
_, err = client.Do(req)
var resp *http.Response
resp, err = client.Do(req)
resp.Body.Close()
}
}

endLogMessage(logger, "public DNS server", err)
return
}

0 comments on commit da95aa2

Please sign in to comment.