in systemtest/apmservertest/server.go [192:265]
func (s *Server) start(tls bool) error {
if s.URL != "" {
panic("Server already started")
}
s.Logs.init()
extra := map[string]interface{}{
// These are config attributes that we always specify,
// as the testing framework relies on them being set.
"logging.level": "debug",
"logging.to_stderr": true,
"apm-server.expvar.enabled": true,
"apm-server.host": "127.0.0.1:0",
}
if tls {
certPath, keyPath, caCertPath, err := s.initTLS()
if err != nil {
panic(err)
}
extra["apm-server.ssl.certificate"] = certPath
extra["apm-server.ssl.key"] = keyPath
if s.Config.TLS != nil && s.Config.TLS.ClientAuthentication != "" {
extra["apm-server.ssl.certificate_authorities"] = []string{caCertPath}
}
}
cfgargs, err := configArgs(s.Config, extra)
if err != nil {
return err
}
args := append(cfgargs, s.args...)
args = append(args, "--path.home", ".") // working directory, s.Dir
s.cmd = ServerCommand(context.Background(), "run", args...)
s.cmd.Dir = s.Dir
// This speeds up tests by forcing the self-instrumentation
// event streams to be closed after 100ms. This is only necessary
// because processor/stream waits for the stream to be closed
// before the last batch is processed.
//
// TODO(axw) remove this once the server processes batches without
// waiting for the stream to be closed.
s.cmd.Env = append(os.Environ(), "ELASTIC_APM_API_REQUEST_TIME=100ms")
stderr, err := s.cmd.StderrPipe()
if err != nil {
return err
}
if err := s.cmd.Start(); err != nil {
stderr.Close()
return err
}
s.Dir = s.cmd.Dir
// Consume the process's stderr.
var stderrReader io.Reader = stderr
if s.Log != nil {
// Write the apm-server command line to the top of the log.
s.printCmdline(s.Log, args)
stderrReader = io.TeeReader(stderrReader, s.Log)
}
stderrPipeReader, stderrPipeWriter := io.Pipe()
s.Stderr = stderrPipeReader
go s.consumeStderr(stderrReader, stderrPipeWriter)
logs := s.Logs.Iterator()
defer logs.Close()
if err := s.waitUntilListening(tls, logs); err != nil {
return err
}
return nil
}