flow-emulator icon indicating copy to clipboard operation
flow-emulator copied to clipboard

Emit log when emulator successfully starts

Open bartolomej opened this issue 3 years ago • 0 comments

Issue To Be Solved

Currently, the flow emulator emits logs only when it transitions to "starting" state or to "error" state.

Transition to "starting" state:

> flow emulator
INFO[0000] ⚙️   Using service account 0xf8d6e0586b0a20c7  serviceAddress=f8d6e0586b0a20c7 serviceHashAlgo=SHA3_256 servicePrivKey=17db68f620ff786e3e5a8b87ba577093caece160f7ac57f5c619d86b973b7628 servicePubKey=a8d2074251eb721254004d758cf71d0bf8300651d25d6ef1991c41448ae02b8a61d232cb53a9d0f0b7adefec25fd267ed7bc09dd1490cb201f38b3b5ba783991 serviceSigAlgo=ECDSA_P256
INFO[0000] 📜  Flow contract                              FlowServiceAccount=0xf8d6e0586b0a20c7
INFO[0000] 📜  Flow contract                              FlowToken=0x0ae53cb6e3f42a79
INFO[0000] 📜  Flow contract                              FungibleToken=0xee82856bf20e2aa6
INFO[0000] 📜  Flow contract                              FlowFees=0xe5a8b7f23e8b548f
INFO[0000] 📜  Flow contract                              FlowStorageFees=0xf8d6e0586b0a20c7
INFO[0000] 🌱  Starting gRPC server on port 3569          port=3569
INFO[0000] 🌱  Starting REST API on port 8888             port=8888
INFO[0000] 🌱  Starting admin server on port 8080         port=8080

Transition to "error" state:

> flow emulator
INFO[0000] ⚙️   Using service account 0xf8d6e0586b0a20c7  serviceAddress=f8d6e0586b0a20c7 serviceHashAlgo=SHA3_256 servicePrivKey=17db68f620ff786e3e5a8b87ba577093caece160f7ac57f5c619d86b973b7628 servicePubKey=a8d2074251eb721254004d758cf71d0bf8300651d25d6ef1991c41448ae02b8a61d232cb53a9d0f0b7adefec25fd267ed7bc09dd1490cb201f38b3b5ba783991 serviceSigAlgo=ECDSA_P256
INFO[0000] 📜  Flow contract                              FlowFees=0xe5a8b7f23e8b548f
INFO[0000] 📜  Flow contract                              FlowStorageFees=0xf8d6e0586b0a20c7
INFO[0000] 📜  Flow contract                              FlowServiceAccount=0xf8d6e0586b0a20c7
INFO[0000] 📜  Flow contract                              FlowToken=0x0ae53cb6e3f42a79
INFO[0000] 📜  Flow contract                              FungibleToken=0xee82856bf20e2aa6
ERRO[0000] ❗  Failed to startup REST API                 error="listen tcp :8888: bind: address already in use"

I think it would be good to also emit a log when the emulator started successfully - when it transitions from "starting" to "started" state. This is because currently there is no indication if the emulator indeed started without errors.

Suggest A Solution

Emit "started" info log after all the flow-emulator components were started successfully. This will indicate that no startup errors can occur from now on.

Example output:

INFO[0000] 🌱  Starting gRPC server on port 3569          port=3569
INFO[0000] 🌱  Starting REST API on port 8888             port=8888
INFO[0000] 🌱  Starting admin server on port 8080         port=8080

INFO[0000] ✅  Started gRPC server on port 3569          port=3569
INFO[0000] ✅  Started REST API on port 8888             port=8888
INFO[0000] ✅  Started admin server on port 8080         port=8080

Related code that would need to be modified: https://github.com/onflow/flow-emulator/blob/fd493635ce6984bb323ff59a32c6d8d36445e909/server/server.go#L189-L229

Context

The lack of this log, also makes it harder to detect successful startups programmatically. For example, at Flowser, we currently assume that if no error logs are emitted 1s after "started" logs were seen, the emulator started successfully - which is not ideal.

See our issue: https://github.com/onflowser/flowser/issues/33

bartolomej avatar Aug 09 '22 08:08 bartolomej