forked from aws/aws-lambda-runtime-interface-emulator
- Notifications
You must be signed in to change notification settings - Fork 2
Add X-Ray daemon#14
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Add X-Ray daemon #14
Changes from all commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
ae1c506 optimize release binary & add build for debugging
dominikschubert d049984 start xray daemon if request is sampled
dominikschubert 44ba29b misc fixes
dominikschubert 9c7f7cc bind to localhost
dominikschubert 0c12c42 reduce flush interval
dominikschubert 3fc0a55 fix pr issues
dominikschubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -24,6 +24,8 @@ type LsOpts struct{ | ||
| HotReloadingPaths []string | ||
| EnableDnsServer string | ||
| LocalstackIP string | ||
| InitLogLevel string | ||
| EdgePort string | ||
| } | ||
| func GetEnvOrDie(env string) string{ | ||
| @@ -36,12 +38,15 @@ func GetEnvOrDie(env string) string{ | ||
| func InitLsOpts() *LsOpts{ | ||
| return &LsOpts{ | ||
| // required | ||
| RuntimeEndpoint: GetEnvOrDie("LOCALSTACK_RUNTIME_ENDPOINT"), | ||
| RuntimeId: GetEnvOrDie("LOCALSTACK_RUNTIME_ID"), | ||
| // optional with default | ||
| InteropPort: GetenvWithDefault("LOCALSTACK_INTEROP_PORT", "9563"), | ||
| InitTracingPort: GetenvWithDefault("LOCALSTACK_RUNTIME_TRACING_PORT", "9564"), | ||
| User: GetenvWithDefault("LOCALSTACK_USER", "sbx_user1051"), | ||
| InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "debug"), | ||
| EdgePort: GetenvWithDefault("EDGE_PORT", "4566"), | ||
| // optional or empty | ||
| CodeArchives: os.Getenv("LOCALSTACK_CODE_ARCHIVES"), | ||
| HotReloadingPaths: strings.Split(GetenvWithDefault("LOCALSTACK_HOT_RELOADING_PATHS", ""), ","), | ||
| @@ -62,6 +67,7 @@ func UnsetLsEnvs(){ | ||
| "LOCALSTACK_CODE_ARCHIVES", | ||
| "LOCALSTACK_HOT_RELOADING_PATHS", | ||
| "LOCALSTACK_ENABLE_DNS_SERVER", | ||
| "LOCALSTACK_INIT_LOG_LEVEL", | ||
| // Docker container ID | ||
| "HOSTNAME", | ||
| // User | ||
| @@ -78,22 +84,33 @@ func main(){ | ||
| // we're setting this to the same value as in the official RIE | ||
| debug.SetGCPercent(33) | ||
| // configuration parsing | ||
| lsOpts := InitLsOpts() | ||
| UnsetLsEnvs() | ||
| // set up logging (logrus) | ||
| //log.SetFormatter(&log.JSONFormatter{}) | ||
| //log.SetLevel(log.TraceLevel) | ||
| log.SetLevel(log.DebugLevel) | ||
| // set up logging | ||
| log.SetReportCaller(true) | ||
| switch lsOpts.InitLogLevel{ | ||
dominikschubert marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| case "debug": | ||
| log.SetLevel(log.DebugLevel) | ||
| case "trace": | ||
| log.SetFormatter(&log.JSONFormatter{}) | ||
| log.SetLevel(log.TraceLevel) | ||
| default: | ||
| log.Fatal("Invalid value for LOCALSTACK_INIT_LOG_LEVEL") | ||
| } | ||
| // enable dns server | ||
| dnsServerContext, stopDnsServer := context.WithCancel(context.Background()) | ||
| go RunDNSRewriter(lsOpts, dnsServerContext) | ||
| // download code archive if env variable is set | ||
| if err := DownloadCodeArchives(lsOpts.CodeArchives); err != nil{ | ||
| log.Fatal("Failed to download code archives") | ||
| } | ||
| // enable dns server | ||
| dnsServerContext, stopDnsServer := context.WithCancel(context.Background()) | ||
| go RunDNSRewriter(lsOpts, dnsServerContext) | ||
| // parse CLI args | ||
| bootstrap, handler := getBootstrap(os.Args) | ||
| // Switch to non-root user and drop root privileges | ||
| if IsRootUser() && lsOpts.User != ""{ | ||
| @@ -108,23 +125,36 @@ func main(){ | ||
| UserLogger().Debugln("Process running as non-root user.") | ||
| } | ||
| // parse CLI args | ||
| opts, args := getCLIArgs() | ||
| bootstrap, handler := getBootstrap(args, opts) | ||
| logCollector := NewLogCollector() | ||
| // file watcher for hot-reloading | ||
| fileWatcherContext, cancelFileWatcher := context.WithCancel(context.Background()) | ||
| // build sandbox | ||
| sandbox := rapidcore. | ||
| NewSandboxBuilder(bootstrap). | ||
| //SetTracer(tracer). | ||
| AddShutdownFunc(func(){ | ||
| log.Debugln("Closing contexts") | ||
| log.Debugln("Stopping file watcher") | ||
| cancelFileWatcher() | ||
| log.Debugln("Stopping DNS server") | ||
| stopDnsServer() | ||
| }). | ||
| AddShutdownFunc(func(){os.Exit(0) }). | ||
| SetExtensionsFlag(true). | ||
| SetInitCachingFlag(true). | ||
| SetTailLogOutput(logCollector) | ||
| // xray daemon | ||
| xrayConfig := initConfig("http://" + lsOpts.LocalstackIP + ":" + lsOpts.EdgePort) | ||
| d := initDaemon(xrayConfig) | ||
| sandbox.AddShutdownFunc(func(){ | ||
| log.Debugln("Shutting down xray daemon") | ||
| d.stop() | ||
| log.Debugln("Flushing segments in xray daemon") | ||
| d.close() | ||
| }) | ||
| runDaemon(d) // async | ||
| defaultInterop := sandbox.InteropServer() | ||
| interopServer := NewCustomInteropServer(lsOpts, defaultInterop, logCollector) | ||
| sandbox.SetInteropServer(interopServer) | ||
| @@ -136,7 +166,7 @@ func main(){ | ||
| go sandbox.Create() | ||
| // get timeout | ||
| invokeTimeoutEnv := GetEnvOrDie("AWS_LAMBDA_FUNCTION_TIMEOUT") | ||
| invokeTimeoutEnv := GetEnvOrDie("AWS_LAMBDA_FUNCTION_TIMEOUT") // TODO: collect all AWS_* env parsing | ||
| invokeTimeoutSeconds, err := strconv.Atoi(invokeTimeoutEnv) | ||
| if err != nil{ | ||
| log.Fatalln(err) | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.