Skip to content

Commit 2e6bdf5

Browse files
committed
[TO REVERT] test on controller ers
1 parent 789d397 commit 2e6bdf5

6 files changed

Lines changed: 51 additions & 12 deletions

File tree

src/drunc/controller/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class cler:
4141
self.controller.broadcaster = id_able()
4242
self.controller.fsm = id_able()
4343

44+
# Maybe we can have something here? but what uses tihs
45+
4446

4547
class ControllerConfHandler(ConfHandler):
4648
@staticmethod
@@ -74,6 +76,8 @@ def _post_process_oks(self, *args, **kwargs):
7476
if self.this_host in ["localhost"] or self.this_host.startswith("127."):
7577
self.this_host = socket.gethostname()
7678

79+
print(self.session.opmon_uri)
80+
print(self.session)
7781
self.opmon_publisher = None
7882
self.opmon_conf = parse_opmon_conf(
7983
log=self.log,

src/drunc/controller/controller.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ def __init__(self, configuration, name: str, session: str, token: Token):
226226
self.broadcast_service = None
227227
self.monitoring_metrics = ControllerMonitoringMetrics()
228228

229-
self.log = get_logger("controller", stream_handlers=True)
229+
self.log = get_logger("controller", rich_handler=True)
230+
test_loggess = get_logger("controller.heyo")
231+
test_loggess.error("Hello, world")
230232
log_init = get_logger("controller.__init__")
231233
log_init.info(f"Initialising controller '{name}' with session '{session}'")
232234

@@ -250,6 +252,8 @@ def __init__(self, configuration, name: str, session: str, token: Token):
250252
data=self.configuration.data.controller.broadcaster,
251253
)
252254

255+
# And then its gonna go here im sure
256+
253257
self.broadcast_service = BroadcastSender(
254258
name=name,
255259
session=session,
@@ -974,9 +978,11 @@ def execute_fsm_command(
974978

975979
command = request.command
976980
command_name = command.command_name
977-
self.log.debug(f"FSM command: {command_name}")
981+
newlog = get_logger("mytestlogger", rich_handler=True)
982+
newlog.warning("Hello there")
983+
self.log.warning(f"FSM command: {command_name}")
978984
transition = self.stateful_node.get_fsm_transition(command_name)
979-
self.log.debug(f"FSM transition: {transition}")
985+
self.log.warning(f"FSM transition: {transition}")
980986

981987
# Check controller readiness.
982988
if not self.stateful_node.get_ready_state():

src/drunc/controller/controller_driver.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ def __init__(self, address: str, token: Token):
7979
("grpc.keepalive_time_ms", 60000) # pings the server every 60 seconds
8080
]
8181

82+
self.log.error(f"address: {address}, token: {token}")
83+
84+
#! SO HERE!!! is where we initialise the add ers protobuf handler. The question is now how do we get the correct config?
85+
#! But once yoh ave this it should be fine
86+
8287
try:
8388
resolved_address = self._resolve_address_to_ipv4(address)
8489
except ValueError as e:
@@ -189,6 +194,18 @@ def execute_fsm_command(
189194
execute_on_all_subsequent_children_in_path: bool = True,
190195
timeout: int | float = 60,
191196
) -> ExecuteFSMCommandResponse:
197+
test_log = get_logger("my_test_logger", rich_handler=True)
198+
199+
test_log.warning(
200+
f"Command: {command}, target: {target}, command_name: {command.command_name}"
201+
)
202+
203+
if command.command_name == "disable_triggers":
204+
test_log.error("there is an error here!")
205+
raise ValueError("Putting an error in here to stop the transition")
206+
207+
#! this is not where we want the value error, this is where we want the logger to be!!
208+
192209
request = ExecuteFSMCommandRequest(
193210
target=target,
194211
execute_along_path=execute_along_path,
@@ -199,7 +216,9 @@ def execute_fsm_command(
199216

200217
try:
201218
response = self.stub.execute_fsm_command(request, timeout=timeout)
219+
#! Here is where we do a fake 'failure'
202220
except grpc.RpcError as e:
221+
#! And then handle the logging
203222
handle_grpc_error(e)
204223

205224
return response

src/drunc/controller/interface/shell_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ def run_one_fsm_command(
480480
ArgumentException: If there is an issue with the arguments
481481
ServerTimeout: If the server times out
482482
"""
483+
log = get_logger("controller.shell_utils")
484+
485+
#! Is this where we want the protobuf handler?
483486
log.info(
484487
f"Running transition '{transition_name}' on controller '{controller_name}', targeting: '{target if target else controller_name}'"
485488
)
@@ -543,7 +546,10 @@ class DummyCommand:
543546
time_start = time.time()
544547
result = None
545548

549+
log.info("About to execute the command")
550+
546551
with ThreadPoolExecutor() as executor:
552+
# so the shell utils hands this over to the actual controller, which will then execute its own fsm command. Wow
547553
future = executor.submit(
548554
obj.get_driver("controller").execute_fsm_command,
549555
command=data,
@@ -581,6 +587,10 @@ class DummyCommand:
581587
"Alternatively, if you are patient, you can try to wait a bit longer and send [yellow]'status'[/yellow] to check if the command ends up being executed (you may want to check the logs of the controller and application with the [yellow]'logs'[/yellow] command)."
582588
)
583589
return
590+
except ValueError as e:
591+
log.error(e)
592+
log.error("Lets see what we have here")
593+
# log.error("This should go to ERS")
584594

585595
if not result:
586596
return
@@ -633,6 +643,8 @@ def add_to_table(table, response, prefix=""):
633643

634644

635645
def generate_fsm_command(ctx, transition: FSMCommandDescription, controller_name: str):
646+
log = get_logger("controller.shell_utils")
647+
# log.debug("inside generate_fsm_command")
636648
cmd = partial(run_one_fsm_command, controller_name, transition.name)
637649
cmd = click.pass_obj(cmd)
638650
cmd = click.option(

src/drunc/process_manager/interface/commands.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from drunc.process_manager.utils import tabulate_process_instance_list
1414
from drunc.utils.shell_utils import InterruptedCommand
1515
from drunc.utils.utils import get_logger
16-
from erskafka.ERSKafkaLogHandler import ERSKafkaLogHandler
1716

1817

1918
@click.command("boot")

src/drunc/process_manager/process_manager.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import threading
44
import time
55

6+
from daqpytools.logging.handlers import add_ers_protobuf_handler
67
from druncschema.authoriser_pb2 import ActionType, SystemType
78
from druncschema.broadcast_pb2 import BroadcastType
89
from druncschema.description_pb2 import CommandDescription, Description
@@ -23,6 +24,9 @@
2324
Request,
2425
ResponseFlag,
2526
)
27+
28+
# import logging
29+
from erskafka.ERSKafkaLogHandler import ERSKafkaLogHandler
2630
from google.rpc import code_pb2
2731
from grpc import ServicerContext
2832

@@ -40,11 +44,6 @@
4044
from drunc.utils.configuration import ConfTypes
4145
from drunc.utils.utils import get_logger, pid_info_str
4246

43-
from daqpytools.logging.handlers import add_file_handler, add_ers_protobuf_handler
44-
45-
# import logging
46-
from erskafka.ERSKafkaLogHandler import ERSKafkaLogHandler
47-
4847

4948
class BadQuery(DruncCommandException):
5049
def __init__(self, txt):
@@ -231,9 +230,9 @@ def publish(self, q: ProcessQuery, interval_s: float = 10.0):
231230
)
232231
#! Obviously hacky but proof of principle
233232
# Checks if n_dead changed compared to the previous iteration
234-
self.log.warning(
235-
f"Processes: {n_running}, {n_dead}, {n_session}, {n_dead_keep}"
236-
)
233+
# self.log.warning(
234+
# f"Processes: {n_running}, {n_dead}, {n_session}, {n_dead_keep}"
235+
# )
237236
if n_dead_keep != n_dead:
238237
self.log.error("We have a real dead one!", extra={"use_ers": True})
239238
n_dead_keep = n_dead

0 commit comments

Comments
 (0)