Skip to content

Commit

Permalink
add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudharysaket committed Apr 16, 2024
1 parent 1463635 commit 1b64510
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions checks/runtime_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func init() {
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
Timeout: time.Second * 10,
Timeout: time.Second * 2,
}
githubClient = github.NewClient(&http.Client{Timeout: time.Second * 10})
githubClient = github.NewClient(&http.Client{Timeout: time.Second * 2})
}

func checkAndReturnRuntime() (runtimeConfig, error) {
Expand Down
11 changes: 9 additions & 2 deletions checks/sanity_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package checks
import (
"context"
"fmt"
"time"

"github.com/newrelic/newrelic-lambda-extension/config"
"github.com/newrelic/newrelic-lambda-extension/credentials"
Expand All @@ -28,11 +29,17 @@ func sanityCheck(ctx context.Context, conf *config.Configuration, res *api.Regis
}

envKeyExists := util.EnvVarExists("NEW_RELIC_LICENSE_KEY")
isSecretConfigured := credentials.IsSecretConfigured(ctx, conf)
var timeout = 1 * time.Second
ctxSecret, cancelSecret := context.WithTimeout(ctx, timeout)
defer cancelSecret()
isSecretConfigured := credentials.IsSecretConfigured(ctxSecret, conf)

ctxSMParameter, cancelSMParameter := context.WithTimeout(ctx, timeout)
defer cancelSMParameter()

isSSMParameterConfigured := false
if conf.LicenseKeySSMParameterName != "" {
isSSMParameterConfigured = credentials.IsSSMParameterConfigured(ctx, conf)
isSSMParameterConfigured = credentials.IsSSMParameterConfigured(ctxSMParameter, conf)
}


Expand Down
2 changes: 1 addition & 1 deletion checks/startup_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func RunChecks(ctx context.Context, conf *config.Configuration, reg *api.Registr
func runCheck(ctx context.Context, conf *config.Configuration, reg *api.RegistrationResponse, r runtimeConfig, logSender LogSender, check checkFn) error {
err := check(ctx, conf, reg, r)
if err != nil {
errLog := fmt.Sprintf("Startup check failed: %v", err)
errLog := fmt.Sprintf("Startup check warning: %v", err)
util.Logln(errLog)

//Send a log line to NR as well
Expand Down
2 changes: 1 addition & 1 deletion checks/startup_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestRunCheckErr(t *testing.T) {
assert.Equal(t, true, tested)
assert.NotNil(t, result)

assert.Equal(t, "Startup check failed: Failure Test", string(logSender.sent[0].Content))
assert.Equal(t, "Startup check warning: Failure Test", string(logSender.sent[0].Content))
}

func TestRunChecks(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func main() {
}

// Attempt to find the license key for telemetry sending
var timeout = 5 * time.Second
var timeout = 1 * time.Second
ctxLicenseKey, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
licenseKey, err := credentials.GetNewRelicLicenseKey(ctxLicenseKey, conf)
Expand Down

0 comments on commit 1b64510

Please sign in to comment.