Skip to content

Commit d2dabd5

Browse files
scripts: Move the logs explorer url generation to common lib. (#9470)
1 parent 87d3af4 commit d2dabd5

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

scripts/prod/restart_all_nodes_together.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Service,
1515
get_configmap,
1616
get_context_list_from_args,
17+
get_logs_explorer_url,
1718
get_namespace_list_from_args,
1819
parse_config_from_yaml,
1920
print_colored,
@@ -23,7 +24,7 @@
2324

2425

2526
# TODO(guy.f): Remove this once we have metrics we use to decide based on.
26-
def get_logs_explorer_url(
27+
def get_logs_explorer_url_for_proposal(
2728
namespace: str,
2829
validator_id: str,
2930
min_block_number: int,
@@ -38,17 +39,7 @@ def get_logs_explorer_url(
3839
f'textPayload =~ "DECISION_REACHED:.*proposer 0x0*{validator_id}"\n'
3940
f'CAST(REGEXP_EXTRACT(textPayload, "height: (\\\\d+)"), "INT64") > {min_block_number}'
4041
)
41-
# We need to double escape '(' and ')', so first we replace only them with their escaped versions.
42-
query = query.replace("(", urllib.parse.quote("(")).replace(")", urllib.parse.quote(")"))
43-
44-
# Now "normal" escape everything else
45-
query = urllib.parse.quote(query)
46-
47-
escaped_project_name = urllib.parse.quote(project_name)
48-
return (
49-
f"https://console.cloud.google.com/logs/query;query={query}"
50-
f"?project={escaped_project_name}"
51-
)
42+
return get_logs_explorer_url(query, project_name)
5243

5344

5445
class RestartStrategy(Enum):
@@ -186,7 +177,7 @@ def main():
186177
post_restart_instructions = []
187178
if args.restart_strategy == RestartStrategy.ONE_BY_ONE:
188179
for namespace, context in zip(namespace_list, context_list or [None] * len(namespace_list)):
189-
url = get_logs_explorer_url(
180+
url = get_logs_explorer_url_for_proposal(
190181
namespace,
191182
get_validator_id(namespace, context),
192183
# Feeder could be behind by up to 10 blocks, so we add 10 to the current block number.

scripts/prod/update_config_and_restart_nodes_lib.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Any, Optional
99

1010
import tempfile
11+
import urllib.parse
1112
import yaml
1213
from difflib import unified_diff
1314

@@ -211,6 +212,23 @@ def get_context_list_from_args(
211212
]
212213

213214

215+
def get_logs_explorer_url(
216+
query: str,
217+
project_name: Optional[str] = None,
218+
) -> str:
219+
# We need to double escape '(' and ')', so first we replace only them with their escaped versions.
220+
query = query.replace("(", urllib.parse.quote("(")).replace(")", urllib.parse.quote(")"))
221+
222+
# Now "normal" escape everything else
223+
query = urllib.parse.quote(query)
224+
225+
escaped_project_name = urllib.parse.quote(project_name)
226+
return (
227+
f"https://console.cloud.google.com/logs/query;query={query}"
228+
f"?project={escaped_project_name}"
229+
)
230+
231+
214232
def run_kubectl_command(args: list, capture_output: bool = True) -> subprocess.CompletedProcess:
215233
full_command = ["kubectl"] + args
216234
try:

0 commit comments

Comments
 (0)