Skip to content
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

Write process context on node start to simplify test orchestration #1729

Merged
merged 6 commits into from
Jul 25, 2023

Conversation

marun
Copy link
Contributor

@marun marun commented Jul 18, 2023

Why this should be merged

The new local network fixture proposed in #1700 requires the following process context for each node to manage a local network a) without a daemon and b) with dynamically assigned ports:

  • PID: used to check if the node process is running and to enable stopping the node
  • URI: used to connect to the node's API (e.g. for health checks)
  • staking address: used by other nodes to bootstrap themselves

Initially these details were discovered by the fixture (e.g. addresses from logs and pid from process start), but it seemed more maintainable to have the node write the necessary data directly. Having the node write the process context directly also supports the start/stop and debug of test network nodes without explicit use of the test fixture.

How this works

  • On node start, process context (PID, URI, and staking address) is collected into the NodeProcessContext type, marshaled to JSON, and written to [base-data-dir]/process.json. On shutdown the file will be removed.
  • Consumers can read the process context file and unmarshal the resulting JSON to the NodeProcessContext type.

How this was tested

  • The new test fixture in e2e: Add local network fixture #1700 was refactored to depend on the new process context file and e2e tests were successfully executed against a fixture-managed network.

@marun marun requested a review from StephenButtolph as a code owner July 18, 2023 18:09
@marun marun force-pushed the write-runtime-state branch 3 times, most recently from eb15b3b to 178c9fc Compare July 18, 2023 19:30
@marun marun requested review from abi87 and gyuho as code owners July 18, 2023 19:30
@marun marun force-pushed the write-runtime-state branch 2 times, most recently from 2792c36 to 395815f Compare July 18, 2023 20:05
@marun marun force-pushed the write-runtime-state branch from 395815f to 1e6a308 Compare July 19, 2023 06:21
@marun marun force-pushed the write-runtime-state branch 2 times, most recently from e0ebb82 to 8bc6244 Compare July 19, 2023 06:24
Copy link
Contributor

@abi87 abi87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only objection I have is to provide a standard location for the node information somwhere in the data dir. I could imagine some downstreams could use the process information we store and providing a single, standard location may simplify adoption

@abi87 abi87 added testing This primarily focuses on testing cleanup Code quality improvement labels Jul 19, 2023
@marun
Copy link
Contributor Author

marun commented Jul 19, 2023

e2e failure is unrelated to this PR, and will be fixed by #1734

@marun marun force-pushed the write-runtime-state branch from 8bc6244 to a067cbb Compare July 19, 2023 17:43
@marun
Copy link
Contributor Author

marun commented Jul 19, 2023

Rebased to pick up test fixes merged to dev.

@marun marun force-pushed the write-runtime-state branch from 5579f4b to 7b4d38b Compare July 20, 2023 17:17
@marun marun changed the title Add --runtime-state-path parameter to support test orchestration Add --write-runtime-state-enabled parameter to support test orchestration Jul 20, 2023
@marun marun force-pushed the write-runtime-state branch 2 times, most recently from a6c8a69 to 105c4ce Compare July 20, 2023 17:26
@marun
Copy link
Contributor Author

marun commented Jul 20, 2023

Waiting for #1737 to merge to fix the upgrade timeout failure.

@marun marun requested a review from abi87 July 20, 2023 22:48
@marun marun force-pushed the write-runtime-state branch 2 times, most recently from ac90e91 to a4d415a Compare July 21, 2023 06:36
@marun marun mentioned this pull request Jul 21, 2023
1 task
abi87
abi87 previously approved these changes Jul 21, 2023
Copy link
Contributor

@abi87 abi87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@StephenButtolph StephenButtolph added this to the v1.10.6 milestone Jul 22, 2023
@marun marun force-pushed the write-runtime-state branch 3 times, most recently from 1e8e74d to e0abe51 Compare July 24, 2023 20:01
@marun marun changed the title Add --write-runtime-state-enabled parameter to support test orchestration Write runtime state on node start to simplify test orchestration Jul 24, 2023
@marun
Copy link
Contributor Author

marun commented Jul 24, 2023

Updated to always write runtime state to a default path, PTAL.

config/flags.go Outdated
@@ -369,6 +370,8 @@ func addNodeFlags(fs *pflag.FlagSet) {
fs.Float64(TracingSampleRateKey, 0.1, "The fraction of traces to sample. If >= 1, always sample. If <= 0, never sample")
fs.StringToString(TracingHeadersKey, map[string]string{}, "The headers to provide the trace indexer")
// TODO add flag to take in headers to send from exporter

fs.String(RuntimeStateFileKey, defaultRuntimeStatePath, "The path to write runtime state to (including PID, API URI, and staking address).")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we put a comment for this flag like the other groups of flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it's a single flag with no foreseeable additional flags to group with, what comment would you suggest beyond the flag description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is there an existing group of flags that this flag might fit with?

maru-ava and others added 6 commits July 24, 2023 17:09
By default state will not be written, and providing
--runtime-state-path will ensure runtime state (API URI, bootstrap
address, and pid) are written to the provided path on startup and
removed from the provided path on shutdown. The details in the written
file support orchestrating nodes for testing:

 - pid: check if process is running, stop the process
 - uri: connect to the node's API
 - bootstrap address: used by other nodes to bootstrap themselves
As per review comments, this includes using a default path with
GetExpandedArg.
As per review commentary, it is preferable to bind the listener on
construction to enable determining the URI to access the API endpoint
without the overhead of synchronization.
@marun marun force-pushed the write-runtime-state branch from fbff19d to 396095e Compare July 25, 2023 00:09
@marun marun changed the title Write runtime state on node start to simplify test orchestration Write process context on node start to simplify test orchestration Jul 25, 2023
@StephenButtolph StephenButtolph merged commit 2b8dc5f into dev Jul 25, 2023
@StephenButtolph StephenButtolph deleted the write-runtime-state branch July 25, 2023 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement testing This primarily focuses on testing
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants