-
Notifications
You must be signed in to change notification settings - Fork 48
/
startup_check.go
57 lines (47 loc) · 1.47 KB
/
startup_check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package checks
import (
"context"
"fmt"
"time"
"github.com/newrelic/newrelic-lambda-extension/config"
"github.com/newrelic/newrelic-lambda-extension/lambda/extension/api"
"github.com/newrelic/newrelic-lambda-extension/lambda/logserver"
"github.com/newrelic/newrelic-lambda-extension/util"
)
type checkFn func(context.Context, *config.Configuration, *api.RegistrationResponse, runtimeConfig) error
type LogSender interface {
SendFunctionLogs(ctx context.Context, lines []logserver.LogLine) error
}
/// Register checks here
var checks = []checkFn{
agentVersionCheck,
handlerCheck,
sanityCheck,
vendorCheck,
}
func RunChecks(ctx context.Context, conf *config.Configuration, reg *api.RegistrationResponse, logSender LogSender) {
runtimeConfig, err := checkAndReturnRuntime()
if err != nil {
errLog := fmt.Sprintf("There was an issue querying for the latest agent version: %v", err)
util.Logln(errLog)
}
for _, check := range checks {
runCheck(ctx, conf, reg, runtimeConfig, logSender, check)
}
}
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)
util.Logln(errLog)
//Send a log line to NR as well
logSender.SendFunctionLogs(ctx, []logserver.LogLine{
{
Time: time.Now(),
RequestID: "0",
Content: []byte(errLog),
},
})
}
return err
}