Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pawel plesniak/logger inheritance #322

Draft
wants to merge 31 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6cbbcad
Updated logging.getLogger -> get_logger
PawelPlesniak Dec 3, 2024
b961564
Logging separated as expected, now clearing up name hierarchies
PawelPlesniak Dec 5, 2024
5637e1c
Start of logger hierarchy implementation
PawelPlesniak Dec 5, 2024
455b297
self.logger -> self.log, self._log -> self.log
PawelPlesniak Dec 6, 2024
4ee01f3
process_manager loggers done, reviewing remaining loggers
PawelPlesniak Dec 6, 2024
1b93085
Included the process_manager type in the logger name
PawelPlesniak Dec 6, 2024
f9e42b3
This has been annoying me for a while
PawelPlesniak Dec 9, 2024
ab66f53
Adding more debug statements
PawelPlesniak Dec 9, 2024
7d74b5c
More default ignores
PawelPlesniak Dec 9, 2024
f019cb6
Ruff fix
PawelPlesniak Dec 9, 2024
a0b5b6a
Separating unified_shell and process_manager logger instances
PawelPlesniak Dec 9, 2024
8e8b24e
Removed `drunc` logger instantiation issue
PawelPlesniak Dec 9, 2024
a6a5326
Unified shell completed
PawelPlesniak Dec 9, 2024
998ca2e
Unified shell complete
PawelPlesniak Dec 9, 2024
6baeb64
Exceptions handled through logging
PawelPlesniak Dec 9, 2024
e1252d6
Removing duplicated handlers
PawelPlesniak Dec 9, 2024
5d106bc
Setting up the root controller within the ShellContext
PawelPlesniak Dec 9, 2024
4f9c6c5
Unified shell ready
PawelPlesniak Dec 10, 2024
137eb5f
Cleaning up unified_shell
PawelPlesniak Dec 10, 2024
b178a5d
Started pm log hierarchy
PawelPlesniak Dec 10, 2024
4649a71
separate process_manager and associated shell work
PawelPlesniak Dec 10, 2024
c27cd77
separate pm shell works as intended
PawelPlesniak Dec 12, 2024
1db87b8
Fixes to the controller shell
PawelPlesniak Dec 12, 2024
1cc2d0c
Controller shell fixes
PawelPlesniak Dec 12, 2024
ecb63e2
drunc-controller fixes
PawelPlesniak Dec 12, 2024
fa528cd
Correcting controller setup
PawelPlesniak Dec 13, 2024
bea0a37
utils logging and imports corrected
PawelPlesniak Jan 13, 2025
750c0be
Unified shell corrections
PawelPlesniak Jan 13, 2025
107cb7e
process_manager import fix
PawelPlesniak Jan 13, 2025
57acbf0
Controller imports fixed, tested with msqt
PawelPlesniak Feb 5, 2025
7f4421d
controller.interfaces polished
PawelPlesniak Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ __pycache__
venv/
build
.DS_Store
log*
log*
.nfs*
info.*.json
5 changes: 0 additions & 5 deletions src/drunc/apps/__main_controller_shell__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def main() -> None:
from drunc.controller.interface.context import ControllerContext
context = ControllerContext()
Expand All @@ -15,9 +14,5 @@ def main() -> None:
rprint(f'Exiting...')
exit(1)





if __name__ == '__main__':
main()
5 changes: 0 additions & 5 deletions src/drunc/apps/__main_pm_shell__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

def main():
from drunc.process_manager.interface.context import ProcessManagerContext
context = ProcessManagerContext()

try:
from drunc.process_manager.interface.shell import process_manager_shell

process_manager_shell(obj = context)

except Exception as e:
Expand All @@ -16,7 +13,5 @@ def main():
rprint(f'Exiting...')
exit(1)



if __name__ == '__main__':
main()
1 change: 0 additions & 1 deletion src/drunc/apps/__main_unified_shell__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def main():
from drunc.unified_shell.context import UnifiedShellContext
context = UnifiedShellContext()
Expand Down
8 changes: 4 additions & 4 deletions src/drunc/authoriser/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def decor(cmd):

@functools.wraps(cmd) # this nifty decorator of decorator (!) is nicely preserving the cmd.__name__ (i.e. signature)
def check_token(obj, request):
from logging import getLogger
log = getLogger('authentified_and_authorised_decorator')
from drunc.utils.utils import get_logger
log = get_logger('authentified_and_authorised_decorator')
log.debug('Entering')
if not obj.authoriser.is_authorised(request.token, action, system, cmd.__name__):
from drunc.authoriser.exceptions import Unauthorised
Expand Down Expand Up @@ -46,8 +46,8 @@ def decor(cmd):

@functools.wraps(cmd) # this nifty decorator of decorator (!) is nicely preserving the cmd.__name__ (i.e. signature)
async def check_token(obj, request):
from logging import getLogger
log = getLogger('authentified_and_authorised_decorator')
from drunc.utils.utils import get_logger
log = get_logger('authentified_and_authorised_decorator')
log.debug('Entering')
if not obj.authoriser.is_authorised(request.token, action, system, cmd.__name__):
yield Response(
Expand Down
4 changes: 2 additions & 2 deletions src/drunc/authoriser/dummy_authoriser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# The Rolls Royce of the authoriser systems
class DummyAuthoriser:
def __init__(self, system:SystemType, configuration_handler:DummyAuthoriserConfHandler=None):
import logging
self.log = logging.getLogger("Controller")
from drunc.utils.utils import get_logger
self.log = get_logger("Controller")
self.log.debug(f'DummyAuthoriser ready')
self.configuration = configuration_handler
self.command_actions = {} # Dict[str, ActionType]
Expand Down
18 changes: 9 additions & 9 deletions src/drunc/connectivity_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ApplicationUpdateUnsuccessful(DruncException):
class ConnectivityServiceClient:
def __init__(self, session:str, address:str):
self.session = session
from logging import getLogger
self.logger = getLogger('ConnectivityServiceClient')
from drunc.utils.utils import get_logger
self.log = get_logger('ConnectivityServiceClient')

if address.startswith('http://') or address.startswith('https://'):
self.address = address
Expand All @@ -39,7 +39,7 @@ def retract(self, uid):
}
for i in range(50):
try:
self.logger.debug(f'Retracting \'{uid}\' on the connectivity service, attempt {i+1}')
self.log.debug(f'Retracting \'{uid}\' on the connectivity service, attempt {i+1}')

r = http_post(
self.address+"/retract",
Expand All @@ -53,7 +53,7 @@ def retract(self, uid):
)

if r.status_code == 404:
self.logger.warning(f'Connection \'{uid}\' not found on the application registry')
self.log.warning(f'Connection \'{uid}\' not found on the application registry')
break

r.raise_for_status()
Expand All @@ -73,7 +73,7 @@ def resolve(self, uid_regex:str, data_type:str) -> dict:
}
for i in range(50):
try:
self.logger.debug(f'Looking up \'{uid_regex}\' on the connectivity service, attempt {i+1}')
self.log.debug(f'Looking up \'{uid_regex}\' on the connectivity service, attempt {i+1}')
response = http_post(
self.address + "/getconnection/" + self.session,
data = data,
Expand All @@ -89,25 +89,25 @@ def resolve(self, uid_regex:str, data_type:str) -> dict:
if content:
return content
else:
self.logger.debug(f'Could not find the address of \'{uid_regex}\' on the application registry')
self.log.debug(f'Could not find the address of \'{uid_regex}\' on the application registry')
import time
time.sleep(0.2)

except (HTTPError, ConnectionError, ReadTimeout) as e:
self.logger.debug(e)
self.log.debug(e)
from time import sleep
sleep(0.2)
continue

self.logger.debug(f'Could not find the address of \'{uid_regex}\' on the application registry')
self.log.debug(f'Could not find the address of \'{uid_regex}\' on the application registry')
raise ApplicationLookupUnsuccessful


def publish(self, uid, uri, data_type:str):
from drunc.utils.utils import http_post
for i in range(50):
try:
self.logger.debug(f'Publishing \'{uid}\' on the connectivity service, attempt {i+1}')
self.log.debug(f'Publishing \'{uid}\' on the connectivity service, attempt {i+1}')

http_post(
self.address+"/publish",
Expand Down
8 changes: 4 additions & 4 deletions src/drunc/controller/children_interface/child_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def __init__(self, name:str, configuration, node_type:ControlType, **kwargs) ->
super().__init__(**kwargs)

self.node_type = node_type
import logging
self.log = logging.getLogger(f"{name}-child-node")
from drunc.utils.utils import get_logger
self.log = get_logger(f"{name}-child-node")
self.name = name
self.configuration = configuration

Expand Down Expand Up @@ -83,8 +83,8 @@ def describe(self, token:Token) -> Response:
def get_child(name:str, cli, configuration, init_token=None, connectivity_service=None, timeout=60, **kwargs):

from drunc.utils.configuration import ConfTypes
import logging
log = logging.getLogger("ChildNode.get_child")
from drunc.utils.utils import get_logger
log = get_logger("ChildNode.get_child")

ctype = ControlType.Unknown
uri = None
Expand Down
4 changes: 2 additions & 2 deletions src/drunc/controller/children_interface/client_side_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def __init__(self, name, node_type: ControlType = ControlType.Direct, fsm_config
configuration = configuration
)

from logging import getLogger
self.log = getLogger(f'{name}-client-side')
from drunc.utils.utils import get_logger
self.log = get_logger(f'{name}-client-side')

self.state = ClientSideState()

Expand Down
4 changes: 2 additions & 2 deletions src/drunc/controller/children_interface/grpc_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, name, configuration:gRCPChildConfHandler, init_token, uri):
configuration = configuration
)

from logging import getLogger
self.log = getLogger(f'{self.name}-grpc-child')
from drunc.utils.utils import get_logger
self.log = get_logger(f'{self.name}-grpc-child')

host, port = uri.split(":")
port = int(port)
Expand Down
20 changes: 10 additions & 10 deletions src/drunc/controller/children_interface/rest_api_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ResponseDispatcher(threading.Thread):
def __init__(self,listener):
threading.Thread.__init__(self)
self.listener = listener
from logging import getLogger
self.log = getLogger('ResponseDispatcher')
from drunc.utils.utils import get_logger
self.log = get_logger('ResponseDispatcher')

def run(self) -> NoReturn:
self.log.debug(f'ResponseDispatcher starting to run')
Expand Down Expand Up @@ -56,8 +56,8 @@ def __init__(self):

@classmethod
def get(cls):
from logging import getLogger
log = getLogger('ResponseListener.get')
from drunc.utils.utils import get_logger
log = get_logger('ResponseListener.get')
if cls._instance is None:
cls._instance = cls.__new__(cls)
from drunc.utils.utils import get_new_port
Expand All @@ -75,8 +75,8 @@ def get(cls):

from flask import request
def index():
from logging import getLogger
log = getLogger('ResponseListener.index')
from drunc.utils.utils import get_logger
log = get_logger('ResponseListener.index')
json = request.get_json(force=True)
log.debug(f'Received {json}')
# enqueue command reply
Expand Down Expand Up @@ -199,9 +199,9 @@ def __init__(
self.proxy_host = proxy_host
self.proxy_port = proxy_port

from logging import getLogger
from drunc.utils.utils import get_logger
self.app = app_name
self.log = getLogger(f'{self.app}-commander')
self.log = get_logger(f'{self.app}-commander')
self.app_url = f"http://{self.app_host}:{self.app_port}/command"

from queue import Queue
Expand Down Expand Up @@ -349,8 +349,8 @@ def __init__(self, name, configuration:RESTAPIChildNodeConfHandler, fsm_configur
fsm_configuration = fsm_configuration,
)

from logging import getLogger
self.log = getLogger(f'{name}-rest-api-child')
from drunc.utils.utils import get_logger
self.log = get_logger(f'{name}-rest-api-child')

self.response_listener = ResponseListener.get()

Expand Down
15 changes: 8 additions & 7 deletions src/drunc/controller/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from drunc.utils.configuration import ConfHandler
import socket

from drunc.controller.children_interface.child_node import ChildNode
from drunc.controller.utils import get_segment_lookup_timeout
from drunc.exceptions import DruncSetupException
from drunc.process_manager.configuration import get_cla
from drunc.utils.configuration import ConfHandler

import confmodel


class ControllerConfData: # the bastardised OKS
def __init__(self):
Expand Down Expand Up @@ -33,7 +40,6 @@ def _grab_segment_conf_from_controller(self, configuration):
self.session = self.db.get_dal(class_name="Session", uid=self.oks_key.session)
this_segment = ControllerConfHandler.find_segment(self.session.segment, self.oks_key.obj_uid)
if this_segment is None:
from drunc.exceptions import DruncSetupException
DruncSetupException(f"Could not find segment with oks_key.obj_uid: {self.oks_key.obj_uid}")
return this_segment

Expand All @@ -44,7 +50,6 @@ def _post_process_oks(self):

self.this_host = self.data.controller.runs_on.runs_on.id
if self.this_host in ['localhost'] or self.this_host.startswith('127.'):
import socket
self.this_host = socket.gethostname()


Expand All @@ -63,7 +68,6 @@ def get_children(self, init_token, without_excluded=False, connectivity_service=
session = None

try:
import confmodel
session = self.db.get_dal(class_name="Session", uid=self.oks_key.session)

except ImportError as e:
Expand All @@ -81,7 +85,6 @@ def get_children(self, init_token, without_excluded=False, connectivity_service=
if confmodel.component_disabled(self.db._obj, session.id, segment.id):
continue

from drunc.process_manager.configuration import get_cla
new_node = ChildNode.get_child(
cli = get_cla(self.db._obj, session.id, segment.controller),
init_token = init_token,
Expand All @@ -99,8 +102,6 @@ def get_children(self, init_token, without_excluded=False, connectivity_service=
if confmodel.component_disabled(self.db._obj, session.id, app.id):
continue

from drunc.process_manager.configuration import get_cla

new_node = ChildNode.get_child(
cli = get_cla(self.db._obj, session.id, app),
name = app.id,
Expand Down
Loading