Skip to content

Commit e4cfb16

Browse files
committed
debug messages
1 parent aadd9ec commit e4cfb16

10 files changed

Lines changed: 188 additions & 26 deletions

File tree

src/drunc/connectivity_service/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def is_ready(self, timeout: int = 10):
4242
elapsed = time.time() - start
4343

4444
self.log.debug(f"Health check attempt {attempt} at {elapsed:.2f}s elapsed")
45-
self.log.debug(f"Polling address: {self.address}")
45+
self.log.warning(f"Polling address: {self.address}")
4646
try:
4747
r = get(self.address)
4848
except Exception as e:

src/drunc/controller/controller.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import multiprocessing
2+
import os
3+
import socket
24
import threading
35
import time
46
from concurrent.futures import ThreadPoolExecutor
@@ -151,6 +153,15 @@ def __init__(self, configuration, name: str, session: str, token: Token):
151153

152154
connection_server_new = socket.gethostname()
153155
connection_port_new = os.getenv("CONNECTION_PORT")
156+
157+
# i mean the heasiest thing to do would be to do the same, if localhost change something
158+
159+
log_init.critical(
160+
f"{connection_server_old=}, {connection_port_old=}, {connection_server_new=}, {connection_port_new=}"
161+
)
162+
163+
##########
164+
154165
connection_server = (
155166
socket.gethostname()
156167
if connection_server_old == "localhost"
@@ -369,6 +380,10 @@ def advertise_control_address(self, address):
369380
if not self.connectivity_service:
370381
return
371382

383+
self.log.info(
384+
f"Checking if connectivity service exists at {self.connectivity_service.address}"
385+
)
386+
372387
if not self.connectivity_service.is_ready(10):
373388
raise ValueError("failssss")
374389
self.log.info(

src/drunc/process_manager/configuration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
if TYPE_CHECKING:
2222
import conffwk
2323

24+
2425
def touch_and_chmod(filepath, mode=0o777):
2526
with open(filepath, "a"):
2627
os.utime(filepath, None)
@@ -96,6 +97,10 @@ def _parse_dict(self, data):
9697
)
9798

9899
if self.opmon_conf.path == "./info.json":
100+
self.log.error(
101+
f"IN JSON MAKER,{self.opmon_conf.session=}, {self.opmon_conf.application=}"
102+
)
103+
99104
self.opmon_conf.path = (
100105
"./info."
101106
+ self.opmon_conf.session
@@ -120,6 +125,8 @@ def _parse_dict(self, data):
120125
new_data.opmon_publisher = OpMonPublisher(
121126
conf=self.opmon_conf, rich_handler=True
122127
)
128+
129+
# raise ValueError("should be here!")
123130
self.log.debug(
124131
"%s OpMonPublisher initialized with configuration %s",
125132
self.opmon_conf.opmon_type,

src/drunc/process_manager/interface/process_manager.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
_cleanup_coroutines = []
3535

3636

37+
def touch_and_chmod(filepath, mode=0o777):
38+
with open(filepath, "a"):
39+
os.utime(filepath, None)
40+
os.chmod(filepath, mode)
41+
42+
3743
def run_pm(
3844
pm_conf: str,
3945
pm_address: str,
@@ -65,6 +71,12 @@ def run_pm(
6571
log_path=log_path, type=conf_type, data=conf_path.split(":")[1]
6672
)
6773

74+
# raise ValueError("Yote")
75+
76+
log.warning(f"{conf_path.split(":")[1]=}, {conf_type=}, {log_path=}")
77+
78+
# do we want to touch things here for the conf path?
79+
6880
log_path = get_log_path(
6981
user=getpass.getuser(),
7082
session_name=pmch.data.type.name,
@@ -73,6 +85,12 @@ def run_pm(
7385
app_log_path=log_path,
7486
)
7587

88+
# touch_and_chmod(log_path)
89+
90+
# also the log path?
91+
92+
log.warning(f"{conf_path=}, {conf_type=}, {log_path=}")
93+
7694
# Logger has been added to process_manager, so everything will be logged
7795
add_handler(log, HandlerType.File, True, path=log_path)
7896

src/drunc/process_manager/oks_parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def collect_apps(
183183
collect_variables(controller.application_environment, rc_env)
184184
rc_env["DUNEDAQ_APPLICATION_NAME"] = controller.id
185185
host = controller.runs_on.runs_on.id
186+
log.info(f"main host is {host}")
186187

187188
tree_id_str = ".".join(map(str, tree_prefix))
188189
apps.append(
@@ -260,6 +261,8 @@ def collect_apps(
260261
)
261262
log.debug(f"Collecting app {app.id} with args {args}")
262263

264+
log.info(f"app host is {host}")
265+
263266
data_path = get_writer_directory_path(app, log)
264267
if not data_path:
265268
log.debug(f"No data path found for app {app.id}")

src/drunc/process_manager/process_manager.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pprint import pprint
12
import abc
23
import re
34
import sys
@@ -45,6 +46,17 @@
4546
from drunc.utils.utils import get_logger, pid_info_str, resolve_context_peer
4647

4748

49+
def to_dict(obj):
50+
if hasattr(obj, "__dict__"):
51+
return {k: to_dict(v) for k, v in obj.__dict__.items()}
52+
elif isinstance(obj, list):
53+
return [to_dict(i) for i in obj]
54+
elif isinstance(obj, dict):
55+
return {k: to_dict(v) for k, v in obj.items()}
56+
else:
57+
return obj
58+
59+
4860
class BadQuery(DruncCommandException):
4961
def __init__(self, txt):
5062
super(BadQuery, self).__init__(txt, code_pb2.INVALID_ARGUMENT)
@@ -94,6 +106,11 @@ def __init__(
94106
self.opmon_publisher = getattr(
95107
self.configuration.get_data(), "opmon_publisher", None
96108
)
109+
110+
obj = self.configuration.get_data().opmon_uri
111+
112+
self.log.error("some errors")
113+
self.log.error(pprint(obj))
97114
interval_s = getattr(self.configuration.get_data(), "interval_s", 10.0)
98115
self.authoriser = DummyAuthoriser(dach, SystemType.PROCESS_MANAGER)
99116

@@ -296,7 +313,7 @@ def _boot_impl(self, boot_request: BootRequest) -> ProcessInstanceList:
296313
def boot(
297314
self, request: BootRequest, context: ServicerContext
298315
) -> ProcessInstanceList:
299-
self.log.debug(
316+
self.log.warning(
300317
f"{self.name} booting '{request.process_description.metadata.name}' "
301318
f"from session '{request.process_description.metadata.session}'"
302319
)

src/drunc/process_manager/process_manager_driver.py

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import tempfile
66
import time
77
from collections.abc import Iterator
8+
from pprint import pprint
89
from time import sleep
910
from typing import Dict, List
1011
from urllib.parse import urlparse
@@ -58,6 +59,18 @@ def touch_and_chmod(filepath, mode=0o777):
5859
os.utime(filepath, None)
5960
os.chmod(filepath, mode)
6061

62+
63+
def to_dict(obj):
64+
if hasattr(obj, "__dict__"):
65+
return {k: to_dict(v) for k, v in obj.__dict__.items()}
66+
elif isinstance(obj, list):
67+
return [to_dict(i) for i in obj]
68+
elif isinstance(obj, dict):
69+
return {k: to_dict(v) for k, v in obj.items()}
70+
else:
71+
return obj
72+
73+
6174
class ProcessManagerDriver:
6275
controller_address = ""
6376

@@ -145,8 +158,13 @@ def boot(
145158
db, session_dal = self._initialise_session(conf_file, conf_id)
146159

147160
# Step 3 - check for port conflicts and update configuration/DAL as needed
161+
# Should remap the local host here actually
148162
db, session_dal = self.check_port_conflicts(db, session_dal)
149163

164+
# step 3.5 update localhost mapping
165+
166+
# session_dal = self.change_localhost(session_dal)
167+
150168
# Step 4 - connect to the connection service
151169
csc, connection_server, connection_port = self._connect_to_service(
152170
session_dal, session_name
@@ -155,7 +173,7 @@ def boot(
155173
# Step 5 - track boot timings per host
156174
last_boot_on_host_at = {}
157175
previous_host = None
158-
176+
self.log.warning("step 6")
159177
# Step 6: iterate over boot requests
160178
for request in self._convert_oks_to_boot_request(
161179
oks_conf=conf_file,
@@ -175,7 +193,7 @@ def boot(
175193
f"Skipping connectivity service readiness check for application {request.process_description.metadata.name}"
176194
)
177195
else:
178-
self.log.debug(
196+
self.log.warning(
179197
f"Checking connectivity service readiness before booting application {request.process_description.metadata.name}"
180198
)
181199
if csc and not csc.is_ready(timeout=10):
@@ -195,14 +213,35 @@ def boot(
195213

196214
previous_host = this_host
197215
last_boot_on_host_at[this_host] = time.time()
216+
217+
self.log.critical(request)
218+
219+
self.log.critical(
220+
f"info name: {request.process_description.metadata.name}, {request.process_description.metadata.session}, {request.process_description.process_execution_directory}"
221+
)
222+
198223
newfile = (
199224
f"{request.process_description.process_execution_directory}/info."
200225
+ request.process_description.metadata.session
201226
+ "."
202227
+ request.process_description.metadata.name
203228
+ ".json"
204229
)
230+
231+
self.log.critical(f"{newfile=}")
232+
205233
touch_and_chmod(newfile)
234+
# touch_and_chmod(request.process_description.process_logs_path)
235+
236+
# we should also do the same for the log file if necessary
237+
238+
# although the CD should keep us all safe
239+
240+
# touch this and make this easily accessible
241+
242+
# BefORE YOU TRY BOOT PARSE OUT THE CD PATH AND PING IT
243+
244+
# ah wait you need to do it as the ssh-ee
206245

207246
try:
208247
response = self.stub.boot(request, timeout=timeout)
@@ -220,6 +259,7 @@ def boot(
220259
handle_grpc_error(e)
221260

222261
# Step 7: discover segment root controller
262+
# maybe the problem is here?
223263
self._discover_controller(
224264
session_dal, session_name, csc, connection_server, connection_port
225265
)
@@ -253,7 +293,8 @@ def _collect_all_apps(
253293

254294
apps = infra_apps + apps
255295

256-
self.log.debug(f"{json.dumps(apps, indent=4)}")
296+
# self.log.warning("json dumps")
297+
# self.log.debug(f"{json.dumps(apps, indent=4)}")
257298

258299
return apps
259300

@@ -362,6 +403,8 @@ def _build_boot_request(
362403
process_restriction=process_restriction,
363404
)
364405
self.log.debug(f"{breq=}\n\n")
406+
407+
# boot_request.process_description.metadata.name
365408
return breq
366409

367410
def _convert_oks_to_boot_request(
@@ -421,7 +464,7 @@ def _consolidate_config(self, session_name, conf_file: str) -> str | None:
421464
)
422465
return
423466

424-
def update_connectivity_port_dal(
467+
def update_connectivity_port_dal( # why is th9is hanging?
425468
self,
426469
env_variables: list["conffwk.dal.Variable | conffwk.dal.VariableSet"],
427470
new_port: int,
@@ -435,6 +478,28 @@ def update_connectivity_port_dal(
435478
if item.name == "CONNECTION_PORT":
436479
item.value = new_port
437480

481+
def change_localhost(self, session_dal):
482+
self.log.critical("in session dalling")
483+
484+
connectivity_service_host: str = session_dal.connectivity_service.host
485+
if connectivity_service_host == "localhost":
486+
# resolve localhost to hostname to enable multi host
487+
resolved_address = resolve_localhost_to_hostname(connectivity_service_host)
488+
if "://" not in resolved_address:
489+
resolved_address = "grpc://" + resolved_address
490+
491+
resolved_server = urlparse(resolved_address).hostname
492+
self.log.debug(
493+
f"Resolved connection server 'localhost' to '{resolved_server}' to avoid K8s hairpinning."
494+
)
495+
session_dal.connectivity_service.host = resolved_server
496+
497+
output = to_dict(session_dal.connectivity_service)
498+
499+
self.log.critical(pprint(output))
500+
501+
return session_dal
502+
438503
def check_port_conflicts(
439504
self, db: conffwk.Configuration, session_dal: "conffwk.dal.Session"
440505
) -> tuple[conffwk.Configuration, "conffwk.dal.Session"]:
@@ -500,8 +565,13 @@ def check_port_conflicts(
500565
# Temporarily removed to allow integration tests to pass without restructuring
501566
# Note - if infrastructure applications outside of the connectivity service are spawned, this will need to be adjusted.
502567
if session_dal.infrastructure_applications: # Check if the own application needs to be spawned, or if an externally managed one is in use (e.g. if using ehn1 connectivity service or integration tests.)
568+
#! WE NEEED TO REPLACE THE CONNECTIVITY SERVICE HOST HERE
569+
503570
connectivity_service_host: str = session_dal.connectivity_service.host
504571
connectivity_service_port = session_dal.connectivity_service.service.port
572+
self.log.info(
573+
f"infrastructure apps: {connectivity_service_host=}, {connectivity_service_port=}"
574+
)
505575
if not is_port_available(
506576
connectivity_service_host, connectivity_service_port
507577
):
@@ -608,14 +678,14 @@ def get_controller_address(session_dal, session_name):
608678

609679
# 1: Try dynamic lookup via Connectivity Service
610680
if csc:
611-
self.log.debug(
681+
self.log.critical(
612682
f"Attempting to discover controller '{top_controller_name}' via connectivity service at {connection_server}:{connection_port}"
613683
)
614684
try:
615685
timeout = (
616686
get_segment_lookup_timeout(session_dal.segment, 60) + 60
617687
) # root-controller timeout to find all its children + 60s for the root controller to start itself
618-
self.log.debug(
688+
self.log.critical(
619689
f"Using a timeout of {timeout}s to find the [green]{top_controller_name}[/] on the connectivity service"
620690
)
621691
_, uri = get_control_type_and_uri_from_connectivity_service(
@@ -628,7 +698,7 @@ def get_controller_address(session_dal, session_name):
628698
)
629699

630700
address = uri.replace("grpc://", "")
631-
self.log.debug(
701+
self.log.warning(
632702
f"Successfully discovered controller '{top_controller_name}' via connectivity service: {address}"
633703
)
634704
return address

0 commit comments

Comments
 (0)