Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeouts #206

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

ctxSSMParameter, cancelSSMParameter := context.WithTimeout(ctx, timeout)
defer cancelSSMParameter()

isSSMParameterConfigured := false
if conf.LicenseKeySSMParameterName != "" {
isSSMParameterConfigured = credentials.IsSSMParameterConfigured(ctx, conf)
isSSMParameterConfigured = credentials.IsSSMParameterConfigured(ctxSSMParameter, 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
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ func main() {
}

// Attempt to find the license key for telemetry sending
licenseKey, err := credentials.GetNewRelicLicenseKey(ctx, conf)
var timeout = 1 * time.Second
ctxLicenseKey, cancelLicenseKey := context.WithTimeout(ctx, timeout)
defer cancelLicenseKey()
licenseKey, err := credentials.GetNewRelicLicenseKey(ctxLicenseKey, conf)
if err != nil {
util.Logln("Failed to retrieve New Relic license key", err)
// We fail open; telemetry will go to CloudWatch instead
Expand Down
Loading