Skip to content

Commit

Permalink
feat: TOOLS-2995 a generate config output to collectinfo archive (#223
Browse files Browse the repository at this point in the history
)

* feat: TOOLS-2995 a `generate config` output to collectinfo archive
  • Loading branch information
Jesse S authored Nov 10, 2023
1 parent d309af7 commit 8144fb8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
14 changes: 12 additions & 2 deletions lib/live_cluster/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from lib.utils.lookup_dict import LookupDict
from lib.utils import util, constants
from lib.utils.types import NodeDict

from . import client_util
from .node import Node
Expand Down Expand Up @@ -179,7 +180,16 @@ def get_node_names(self, nodes=None):

return node_names

def get_node_ids(self, nodes=None):
def get_node_ids(self, nodes: list[str] | None = None) -> NodeDict[str]:
"""Gets node key to node id mapping
Keyword Arguments:
nodes {list[str] | None} -- A subset of all nodes that should be returned.
If None all nodes are returned (default: {None})
Returns:
NodeDict[str] -- A dictionary mapping node keys (ip:port) to node ids.
"""
selected_nodes = set()
node_ids = {}

Expand Down Expand Up @@ -459,7 +469,7 @@ def get_nodes(
constants.NodeSelection.PRINCIPAL,
constants.NodeSelection.RANDOM,
]
| list[str],
| list[str] = constants.NodeSelection.ALL,
) -> list[Node]:
use_nodes = []

Expand Down
32 changes: 32 additions & 0 deletions lib/live_cluster/collectinfo_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import sys
import traceback
from typing import Any, Callable, Optional
from lib.live_cluster.client.node import Node
from lib.live_cluster.generate_config_controller import GenerateConfigController
from lib.utils.types import NodeDict

from lib.view.sheet.render import get_style_json, set_style_json
Expand Down Expand Up @@ -799,6 +801,9 @@ async def _dump_collectinfo_sysinfo(self, as_logfile_prefix: str, fileHeader: st
async def _dump_collectinfo_aerospike_conf(
self, as_logfile_prefix: str, conf_path: Optional[str] = None
):
"""
Gets the static aerospike.conf if available.
"""
complete_filename = as_logfile_prefix + "aerospike.conf"

if not conf_path:
Expand All @@ -812,6 +817,32 @@ async def _dump_collectinfo_aerospike_conf(
self.logger.warning(str(e))
util.write_to_file(complete_filename, str(e))

async def _dump_collectinfo_dynamic_aerospike_conf(self, as_logfile_prefix):
"""
Used the GenerateConfigController to get the active runtime config of the
cluster. This will include changes that have not yet been save to the static
aerospike.conf file.
"""
nodes: list[Node] = self.cluster.get_nodes()

async def _get_aerospike_conf(self, key, id):
complete_filename = as_logfile_prefix + id + "_aerospike.conf"
line = f"-o {complete_filename} with {key}"
await GenerateConfigController().execute(line.split())

level = self.logger.getEffectiveLevel()
self.logger.setLevel(logging.ERROR)
results = await asyncio.gather(
*[_get_aerospike_conf(self, node.key, node.node_id) for node in nodes],
return_exceptions=True,
)
self.logger.setLevel(level)

for result in results:
if isinstance(result, Exception):
self.logger.error(str(result))
continue

###########################################################################
# Collectinfo caller functions

Expand Down Expand Up @@ -903,6 +934,7 @@ async def _run_collectinfo(
self._dump_collectinfo_health(as_logfile_prefix, file_header),
self._dump_collectinfo_sysinfo(as_logfile_prefix, file_header),
self._dump_collectinfo_aerospike_conf(as_logfile_prefix, config_path),
self._dump_collectinfo_dynamic_aerospike_conf(as_logfile_prefix),
]

for c in coroutines:
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,12 @@ async def capture_separate_and_parse_output(rc, commands):


def get_collectinfo_path(cp: CompletedProcess, collectinfo_prefix: str):
collectinfo_path = None
for line in reversed(cp.stderr.splitlines()):
if collectinfo_prefix in line and line.startswith("INFO:"):
words = line.split()
for word in words:
if collectinfo_prefix in word:
print("Found collectinfo_prefix", collectinfo_path)
if collectinfo_prefix in word and ".tgz" in word:
print("Found collectinfo_prefix", word)
return word
raise Exception("Unable to find collectinfo path in output")

Expand Down

0 comments on commit 8144fb8

Please sign in to comment.