Skip to content

Commit b7973cd

Browse files
authored
Update log_collector.py
1 parent ef711da commit b7973cd

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

log_collector/log_collector.py

+20-17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
TIME_FORMAT = time.strftime("%Y%m%d-%H%M%S")
3030

31+
timeout = 180
32+
3133
API_RESOURCES = [
3234
"RedisEnterpriseCluster",
3335
"RedisEnterpriseDatabase",
@@ -75,7 +77,6 @@ def make_dir(directory):
7577

7678

7779
def _get_namespaces_to_run_on(namespace):
78-
7980
def _get_namespace_from_config():
8081
config_namespace = get_namespace_from_config()
8182
if not config_namespace:
@@ -96,6 +97,21 @@ def _get_namespace_from_config():
9697
return namespace.split(',')
9798

9899

100+
def collect_from_ns(namespace, output_dir):
101+
"Collect the context of a specific namespace. Typically runs in parallel processes."
102+
logger.info("Started collecting from namespace '%s'", namespace)
103+
ns_output_dir = output_dir + ("/" + namespace if output_dir[-1] != '/' else namespace)
104+
make_dir(ns_output_dir)
105+
106+
get_redis_enterprise_debug_info(namespace, ns_output_dir)
107+
collect_pod_rs_logs(namespace, ns_output_dir)
108+
collect_resources_list(namespace, ns_output_dir)
109+
collect_events(namespace, ns_output_dir)
110+
collect_api_resources(namespace, ns_output_dir)
111+
collect_api_resources_description(namespace, ns_output_dir)
112+
collect_pods_logs(namespace, ns_output_dir)
113+
114+
99115
def run(namespace_input, output_dir):
100116
"""
101117
Collect logs
@@ -111,22 +127,9 @@ def run(namespace_input, output_dir):
111127
make_dir(output_dir)
112128
collect_cluster_info(output_dir)
113129

114-
def collect_from_ns(namespace):
115-
logger.info("Started collecting from namespace '%s'", namespace)
116-
ns_output_dir = output_dir + ("/" + namespace if output_dir[-1] != '/' else namespace)
117-
make_dir(ns_output_dir)
118-
119-
get_redis_enterprise_debug_info(namespace, ns_output_dir)
120-
collect_pod_rs_logs(namespace, ns_output_dir)
121-
collect_resources_list(namespace, ns_output_dir)
122-
collect_events(namespace, ns_output_dir)
123-
collect_api_resources(namespace, ns_output_dir)
124-
collect_api_resources_description(namespace, ns_output_dir)
125-
collect_pods_logs(namespace, ns_output_dir)
126-
127130
processes = []
128131
for namespace in namespaces:
129-
p = Process(target=collect_from_ns, args=[namespace])
132+
p = Process(target=collect_from_ns, args=[namespace, output_dir])
130133
p.start()
131134
processes.append(p)
132135

@@ -135,7 +138,7 @@ def collect_from_ns(namespace):
135138

136139
archive_files(output_dir, output_file_name)
137140
logger.info("Finished Redis Enterprise log collector")
138-
logger.info("--- Run time: %d minutes ---", round(((time.time() - start_time)/60), 3))
141+
logger.info("--- Run time: %d minutes ---", round(((time.time() - start_time) / 60), 3))
139142

140143

141144
def get_non_ready_rs_pod_names(namespace):
@@ -576,7 +579,7 @@ def run_kubectl_describe(namespace, resource_type):
576579
"when left empty will use namespace from kube config")
577580
parser.add_argument('-o', '--output_dir', action="store", type=str)
578581
parser.add_argument('-t', '--timeout', action="store",
579-
type=int, default=180,
582+
type=int, default=timeout,
580583
help="time to wait for external commands to "
581584
"finish execution "
582585
"(default: 180s, specify 0 to not timeout) "

0 commit comments

Comments
 (0)