Skip to content

Commit

Permalink
Extension checks
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudharysaket committed Oct 9, 2024
1 parent ac7ad99 commit 04cfbad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
19 changes: 12 additions & 7 deletions checks/startup_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type LogSender interface {
}

/// Register checks here
var checks = []checkFn{
agentVersionCheck,
handlerCheck,
sanityCheck,
vendorCheck,
var checks = map[string]checkFn{
"agent": agentVersionCheck,
"handler": handlerCheck,
"sanity": sanityCheck,
"vendor": vendorCheck,
}

func RunChecks(ctx context.Context, conf *config.Configuration, reg *api.RegistrationResponse, logSender LogSender) {
Expand All @@ -32,8 +32,13 @@ func RunChecks(ctx context.Context, conf *config.Configuration, reg *api.Registr
util.Logln(errLog)
}

for _, check := range checks {
runCheck(ctx, conf, reg, runtimeConfig, logSender, check)
runAllChecks := len(conf.ExtensionChecks) == 0

for checkName, check := range checks {
if runAllChecks || conf.ExtensionChecks[checkName] {
util.Debugf("Running Extension check: %s", checkName)
runCheck(ctx, conf, reg, runtimeConfig, logSender, check)
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var EmptyNRWrapper = "Undefined"
type Configuration struct {
TestingOverride bool // ignores envioronment specific details when running unit tests
ExtensionEnabled bool
ExtensionChecks map[string]bool
LogsEnabled bool
SendFunctionLogs bool
CollectTraceID bool
Expand All @@ -40,6 +41,7 @@ type Configuration struct {
func ConfigurationFromEnvironment() *Configuration {
nrEnabledStr, nrEnabledOverride := os.LookupEnv("NEW_RELIC_ENABLED")
nrEnabledRubyStr, nrEnabledRubyOverride := os.LookupEnv("NEW_RELIC_AGENT_ENABLED")
nrExtensionChecksStr, nrExtensionChecksOverride := os.LookupEnv("NEW_RELIC_EXTENSION_CHECKS")
enabledStr, extensionEnabledOverride := os.LookupEnv("NEW_RELIC_LAMBDA_EXTENSION_ENABLED")
licenseKey, lkOverride := os.LookupEnv("NEW_RELIC_LICENSE_KEY")
licenseKeySecretId, lkSecretOverride := os.LookupEnv("NEW_RELIC_LICENSE_KEY_SECRET")
Expand Down Expand Up @@ -93,6 +95,28 @@ func ConfigurationFromEnvironment() *Configuration {
ret.LicenseKeySSMParameterName = licenseKeySSMParameterName
}

if nrExtensionChecksOverride && nrExtensionChecksStr != "" {
validChecks := map[string]bool{
"agent": true,
"handler": true,
"sanity": true,
"vendor": true,
}
selectedChecks := make(map[string]bool)
checks := strings.Split(nrExtensionChecksStr, ",")

for _, check := range checks {
trimmedCheck := strings.TrimSpace(check)
if trimmedCheck != "" && validChecks[trimmedCheck] {
selectedChecks[trimmedCheck] = true
}
}

if len(selectedChecks) > 0 {
ret.ExtensionChecks = selectedChecks
}
}

if nrOverride {
ret.NRHandler = nrHandler
} else {
Expand Down

0 comments on commit 04cfbad

Please sign in to comment.