diff --git a/tests/fixture/tmpnet/network.go b/tests/fixture/tmpnet/network.go index 69ff37bd5e41..e627d9135aa5 100644 --- a/tests/fixture/tmpnet/network.go +++ b/tests/fixture/tmpnet/network.go @@ -542,7 +542,7 @@ func (n *Network) RestartNode(ctx context.Context, log logging.Logger, node *Nod // Stops all nodes in the network. func (n *Network) Stop(ctx context.Context) error { // Target all nodes, including the ephemeral ones - nodes, err := ReadNodes(n.Dir, true /* includeEphemeral */) + nodes, err := ReadNodes(n, true /* includeEphemeral */) if err != nil { return err } @@ -585,11 +585,8 @@ func (n *Network) Restart(ctx context.Context, log logging.Logger) error { // no action will be taken. // TODO(marun) Reword or refactor to account for the differing behavior pre- vs post-start func (n *Network) EnsureNodeConfig(node *Node) error { - // Ensure nodes can label their metrics with the network uuid - node.NetworkUUID = n.UUID - - // Ensure nodes can label metrics with an indication of the shared/private nature of the network - node.NetworkOwner = n.Owner + // Ensure the node has access to network configuration + node.network = n if err := node.EnsureKeys(); err != nil { return err @@ -818,7 +815,7 @@ func (n *Network) GetNodeURIs() []NodeURI { // For consumption outside of avalanchego. Needs to be kept exported. func (n *Network) GetBootstrapIPsAndIDs(skippedNode *Node) ([]string, []string, error) { // Collect staking addresses of non-ephemeral nodes for use in bootstrapping a node - nodes, err := ReadNodes(n.Dir, false /* includeEphemeral */) + nodes, err := ReadNodes(n, false /* includeEphemeral */) if err != nil { return nil, nil, fmt.Errorf("failed to read network's nodes: %w", err) } diff --git a/tests/fixture/tmpnet/network_config.go b/tests/fixture/tmpnet/network_config.go index 26cb9e266f85..49b6e5503af6 100644 --- a/tests/fixture/tmpnet/network_config.go +++ b/tests/fixture/tmpnet/network_config.go @@ -59,7 +59,7 @@ func (n *Network) readNetwork() error { // Read the non-ephemeral nodes associated with the network from disk. func (n *Network) readNodes() error { - nodes, err := ReadNodes(n.Dir, false /* includeEphemeral */) + nodes, err := ReadNodes(n, false /* includeEphemeral */) if err != nil { return err } diff --git a/tests/fixture/tmpnet/node.go b/tests/fixture/tmpnet/node.go index 64804d20e713..93dc3469ce98 100644 --- a/tests/fixture/tmpnet/node.go +++ b/tests/fixture/tmpnet/node.go @@ -59,16 +59,6 @@ type NodeRuntimeConfig struct { // Node supports configuring and running a node participating in a temporary network. type Node struct { - // Uniquely identifies the network the node is part of to enable monitoring. - NetworkUUID string - - // Identify the entity associated with this network. This is - // intended to be used to label metrics to enable filtering - // results for a test run between the primary/shared network used - // by the majority of tests and private networks used by - // individual tests. - NetworkOwner string - // Set by EnsureNodeID which is also called when the node is read. NodeID ids.NodeID @@ -89,6 +79,9 @@ type Node struct { // Initialized on demand runtime NodeRuntime + + // Intended to be set by the network + network *Network } // Initializes a new node with only the data dir set @@ -129,11 +122,11 @@ func ReadNode(dataDir string) (*Node, error) { } // Reads nodes from the specified network directory. -func ReadNodes(networkDir string, includeEphemeral bool) ([]*Node, error) { +func ReadNodes(network *Network, includeEphemeral bool) ([]*Node, error) { nodes := []*Node{} // Node configuration is stored in child directories - entries, err := os.ReadDir(networkDir) + entries, err := os.ReadDir(network.Dir) if err != nil { return nil, fmt.Errorf("failed to read dir: %w", err) } @@ -142,7 +135,7 @@ func ReadNodes(networkDir string, includeEphemeral bool) ([]*Node, error) { continue } - nodeDir := filepath.Join(networkDir, entry.Name()) + nodeDir := filepath.Join(network.Dir, entry.Name()) node, err := ReadNode(nodeDir) if errors.Is(err, os.ErrNotExist) { // If no config file exists, assume this is not the path of a node @@ -159,6 +152,8 @@ func ReadNodes(networkDir string, includeEphemeral bool) ([]*Node, error) { return nil, fmt.Errorf("failed to ensure NodeID: %w", err) } + node.network = network + nodes = append(nodes, node) } @@ -382,7 +377,7 @@ func (n *Node) GetUniqueID() string { nodeIDString := n.NodeID.String() startIndex := len(ids.NodeIDPrefix) endIndex := startIndex + 8 // 8 characters should be enough to identify a node in the context of its network - return n.NetworkUUID + "-" + strings.ToLower(nodeIDString[startIndex:endIndex]) + return n.network.UUID + "-" + strings.ToLower(nodeIDString[startIndex:endIndex]) } // Saves the currently allocated API port to the node's configuration diff --git a/tests/fixture/tmpnet/node_config.go b/tests/fixture/tmpnet/node_config.go index e3d99ca59b80..ac355eec9e55 100644 --- a/tests/fixture/tmpnet/node_config.go +++ b/tests/fixture/tmpnet/node_config.go @@ -49,8 +49,6 @@ func (n *Node) readConfig() error { } type serializedNodeConfig struct { - NetworkUUID string - NetworkOwner string IsEphemeral bool Flags FlagsMap RuntimeConfig *NodeRuntimeConfig @@ -58,8 +56,6 @@ type serializedNodeConfig struct { func (n *Node) writeConfig() error { config := serializedNodeConfig{ - NetworkUUID: n.NetworkUUID, - NetworkOwner: n.NetworkOwner, IsEphemeral: n.IsEphemeral, Flags: n.Flags, RuntimeConfig: n.RuntimeConfig, diff --git a/tests/fixture/tmpnet/node_process.go b/tests/fixture/tmpnet/node_process.go index b695ac3f5d4a..3a4f3494520a 100644 --- a/tests/fixture/tmpnet/node_process.go +++ b/tests/fixture/tmpnet/node_process.go @@ -258,10 +258,10 @@ func (p *NodeProcess) writeMonitoringConfig() error { // behavior of using the node's URI since the URI isn't // guaranteed stable (e.g. port may change after restart). "instance": p.node.GetUniqueID(), - "network_uuid": p.node.NetworkUUID, + "network_uuid": p.node.network.UUID, "node_id": p.node.NodeID, "is_ephemeral_node": strconv.FormatBool(p.node.IsEphemeral), - "network_owner": p.node.NetworkOwner, + "network_owner": p.node.network.Owner, } commonLabels.SetDefaults(githubLabelsFromEnv()) @@ -296,7 +296,7 @@ func (p *NodeProcess) getMonitoringConfigPath(name string) (string, error) { if err != nil { return "", err } - return filepath.Join(serviceDiscoveryDir, fmt.Sprintf("%s_%s.json", p.node.NetworkUUID, p.node.NodeID)), nil + return filepath.Join(serviceDiscoveryDir, fmt.Sprintf("%s_%s.json", p.node.network.UUID, p.node.NodeID)), nil } // Ensure the removal of the monitoring configuration files for this node.