Skip to content

Commit 105c4ce

Browse files
committed
Switch to enabling/disabling runtime state writing to a hard-coded path.
1 parent 564d07d commit 105c4ce

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

config/config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,14 @@ func getPluginDir(v *viper.Viper) (string, error) {
12951295
return pluginDir, nil
12961296
}
12971297

1298+
// GetRuntimeStatePath returns the path that the node's runtime state
1299+
// (including PID, API URI, boostrap address) will be written to if
1300+
// --write-runtime-state-enabled is set to true. Exported to support
1301+
// local network orchestration.
1302+
func GetRuntimeStatePath(baseDataDir string) string {
1303+
return filepath.Join(baseDataDir, "runtime.json")
1304+
}
1305+
12981306
func GetNodeConfig(v *viper.Viper) (node.Config, error) {
12991307
var (
13001308
nodeConfig node.Config
@@ -1495,7 +1503,8 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
14951503

14961504
nodeConfig.ChainDataDir = GetExpandedArg(v, ChainDataDirKey)
14971505

1498-
nodeConfig.RuntimeStatePath = v.GetString(RuntimeStatePathKey)
1506+
nodeConfig.WriteRuntimeStateEnabled = v.GetBool(WriteRuntimeStateEnabledKey)
1507+
nodeConfig.RuntimeStatePath = GetRuntimeStatePath(v.GetString(DataDirKey))
14991508

15001509
nodeConfig.ProvidedFlags = providedFlags(v)
15011510
return nodeConfig, nil

config/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func addNodeFlags(fs *pflag.FlagSet) {
389389
fs.StringToString(TracingHeadersKey, map[string]string{}, "The headers to provide the trace indexer")
390390
// TODO add flag to take in headers to send from exporter
391391

392-
fs.String(RuntimeStatePathKey, "", "The path to write runtime state to (including uri, bootstrap address and pid). If empty, runtime state will not be written.")
392+
fs.Bool(WriteRuntimeStateEnabledKey, false, "Whether to write runtime state (including PID, API URI, and boostrap address) to [base-data-dir]/runtime.json. If false (the default), runtime state will not be written.")
393393
}
394394

395395
// BuildFlagSet returns a complete set of flags for avalanchego

config/keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,5 @@ const (
219219
TracingSampleRateKey = "tracing-sample-rate"
220220
TracingExporterTypeKey = "tracing-exporter-type"
221221
TracingHeadersKey = "tracing-headers"
222-
RuntimeStatePathKey = "runtime-state-path"
222+
WriteRuntimeStateEnabledKey = "write-runtime-state-enabled"
223223
)

node/config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,12 @@ type Config struct {
234234
// write arbitrary data.
235235
ChainDataDir string `json:"chainDataDir"`
236236

237-
// Path to write runtime state to (including uri, bootstrap
238-
// address and pid). If empty, runtime state will not be written.
237+
// Whether to write runtime state (including PID, API URI and
238+
// bootstrap address) to the default path of
239+
// [base-data-dir]/runtime.json. If false, runtime state will not
240+
// be written.
241+
WriteRuntimeStateEnabled bool `json:"writeRuntimeStateEnabled"`
242+
243+
// The path to write runtime state to.
239244
RuntimeStatePath string `json:"runtimeStatePath"`
240245
}

node/node.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ type NodeRuntimeState struct {
397397
// Write runtime state to the configured path. Supports the use of
398398
// dynamically chosen network ports with local network orchestration.
399399
func (n *Node) writeRuntimeState() {
400-
n.Log.Info("attempting to write runtime state to configured path", zap.String("path", n.Config.RuntimeStatePath))
400+
n.Log.Info("attempting to write runtime state", zap.String("path", n.Config.RuntimeStatePath))
401401

402402
uri := ""
403403

@@ -463,7 +463,7 @@ func (n *Node) Dispatch() error {
463463
n.Shutdown(1)
464464
})
465465

466-
if len(n.Config.RuntimeStatePath) > 0 {
466+
if n.Config.WriteRuntimeStateEnabled {
467467
go n.writeRuntimeState()
468468
}
469469

@@ -497,8 +497,9 @@ func (n *Node) Dispatch() error {
497497
// Wait until the node is done shutting down before returning
498498
n.DoneShuttingDown.Wait()
499499

500-
if len(n.Config.RuntimeStatePath) > 0 {
501-
// Attempt to remove the runtime state path
500+
if n.Config.WriteRuntimeStateEnabled {
501+
// Attempt to remove the runtime state path to communicate to an
502+
// orchestrator that the node is no longer running.
502503
if err := os.Remove(n.Config.RuntimeStatePath); err != nil && !os.IsNotExist(err) {
503504
n.Log.Error("removal of runtime state file failed",
504505
zap.String("path", n.Config.RuntimeStatePath),

0 commit comments

Comments
 (0)