Commit 08c1643f authored by Konstantinos Togias's avatar Konstantinos Togias
Browse files

Use structlog for TF-SDK logging

TF-SDK loggers now come from structlog, so they follow the host
process's structlog configuration (e.g. SRM), with no extra setup.

Original-Author: Igli <kociaj4@gmail.com>
Reviewed-Commit: 68263cd13627df876c46c0b5da26c6694a9dbeaf
Publication-Reason: ETSI requires the author to be a project member.
parent d6d7de78
Loading
Loading
Loading
Loading
+1 −0
Changes for pyproject.toml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ dependencies = [
  "pymongo==4.13.2",
  "kubernetes==33.1.0",
  "PyYAML==6.0.3",
  "structlog>=25.5.0",
]

[project.urls]
+3 −2
Changes for src/openop_tfsdk/contract/adapters/kubernetes.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -7,10 +7,11 @@ What a kubernetes control path can execute. Not topology, so not read from
the bootstrap YAML.
"""
import json
import logging
import subprocess
from typing import Optional

import structlog

from openop_tfsdk.contract.errors import DomainExecutionFailed, ValidationError
from openop_tfsdk.contract.execution_models import (
    CapabilityLifecycleRequest,
@@ -22,7 +23,7 @@ from openop_tfsdk.contract.execution_models import (
)
from openop_tfsdk.contract.models import SupportedAction

log = logging.getLogger(__name__)
log = structlog.get_logger(__name__)

LIFECYCLE_CAPABILITY_KINDS = frozenset({"workload"})

+2 −2
Changes for src/openop_tfsdk/contract/adapters/network.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -6,11 +6,11 @@
Contract adapters for the network cores of the previous codebase. They translate
contract calls to the existing NetworkManager clients.
"""
import logging
from typing import Optional

import pydantic
import requests
import structlog

from openop_tfsdk.contract.errors import (
    DomainExecutionFailed,
@@ -41,7 +41,7 @@ from openop_tfsdk.network.adapters.open5gs.client import NetworkManager as Open5
from openop_tfsdk.network.core import schemas
from openop_tfsdk.network.core.common import CoreHttpError

log = logging.getLogger(__name__)
log = structlog.get_logger(__name__)

QOD_ACTIONS = [
    SupportedAction.ACTIVATE,
+14 −12
Changes for src/openop_tfsdk/edgecloud/adapters/kubernetes/client.py: 14 added lines, 12 removed lines.
Original line number Diff line number Diff line
# Mocked API for testing purposes
import logging
from typing import Dict, List, Optional

from kubernetes.client import V1Deployment
@@ -28,6 +27,9 @@ from openop_tfsdk.edgecloud.core.edgecloud_interface import (
    EdgeCloudManagementInterface,
)
from openop_tfsdk.edgecloud.core.utils import build_custom_http_response
from openop_tfsdk.logger import get_logger

log = get_logger(__name__)


class EdgeApplicationManager(EdgeCloudManagementInterface):
@@ -53,7 +55,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):

    def onboard_app(self, app_manifest: AppManifest) -> Response:
        print(f"Submitting application: {app_manifest}")
        logging.info("Extracting variables from payload...")
        log.info("Extracting variables from payload...")

        app_id = app_manifest.get("appId")
        app_name = app_manifest.get("name")
@@ -95,7 +97,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
        )

    def get_all_onboarded_apps(self) -> Response:
        logging.info("Retrieving all registered apps from database...")
        log.info("Retrieving all registered apps from database...")
        status_code = None
        content = []
        try:
@@ -115,7 +117,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
                request=None,
            )
        except Exception as e:
            logging.error(e.args)
            log.error(e.args)
            status_code = 500
            return {
                "status": 500,
@@ -124,7 +126,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
            }

    def get_onboarded_app(self, app_id: str) -> Response:
        logging.info("Searching for registered app with ID: " + app_id + " in database...")
        log.info("Searching for registered app with ID: " + app_id + " in database...")
        status_code = None
        content = None
        app = self.connector_db.get_documents_from_collection(
@@ -165,7 +167,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
        )

    def deploy_app(self, app_id: str, app_zones: List[Dict]) -> Response:
        logging.info("Searching for registered app with ID: " + app_id + " in database...")
        log.info("Searching for registered app with ID: " + app_id + " in database...")
        status_code = None
        app = self.connector_db.get_documents_from_collection(
            "service_functions", input_type="_id", input_value=app_id
@@ -226,7 +228,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
        app_instance_id: Optional[str] = None,
        region: Optional[str] = None,
    ) -> Response:
        logging.info("Retrieving all deployed apps in the edge cloud platform")
        log.info("Retrieving all deployed apps in the edge cloud platform")
        status_code = None
        content = None
        try:
@@ -258,7 +260,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
                request=None,
            )
        except Exception as e:
            logging.error(e.args)
            log.error(e.args)
            return {
                "status": 500,
                "code": "INTERNAL",
@@ -277,7 +279,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
        :param region: Optional filter by Edge Cloud region
        :return: Response with application instance details
        """
        logging.info("Retrieving for deployed app with ID: " + app_instance_id)
        log.info("Retrieving for deployed app with ID: " + app_instance_id)
        deployments = self.k8s_connector.get_deployed_service_functions(self.connector_db)
        deployed_app = None
        response = {}
@@ -317,7 +319,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
        )

    def undeploy_app(self, app_instance_id: str) -> None:
        logging.info("Searching for deployed app with ID: " + app_instance_id + " in database...")
        log.info("Searching for deployed app with ID: " + app_instance_id + " in database...")
        print(f"Deleting app instance: {app_instance_id}")
        status_code = 404
        try:
@@ -341,7 +343,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
                request=None,
            )
        except Exception as e:
            logging.error(e.args)
            log.error(e.args)
            return {"status": 404, "code": "NOT_FOUND", "message": "Resource does not exist"}

    def get_edge_cloud_zones(
@@ -359,7 +361,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
            zone["edgeCloudProvider"] = self.edge_cloud_provider
            zone["edgeCloudRegion"] = node.get("location")
            zone_list.append(zone)
        logging.info(zone_list)
        log.info(zone_list)
        return build_custom_http_response(
            status_code=200,
            content=zone_list,
+6 −3
Changes for src/openop_tfsdk/edgecloud/adapters/kubernetes/lib/utils/artifact_connector.py: 6 added lines, 3 removed lines.
Original line number Diff line number Diff line
import logging
import os

import requests

from openop_tfsdk.logger import get_logger

log = get_logger(__name__)

artifact_manager_host = os.environ["ARTIFACT_MANAGER_ADDRESS"]


def artifact_exists(body):
    logging.info("Contacting Artifact Manager")
    log.info("Contacting Artifact Manager")
    # body = json.dumps(body)
    headers = {"Content-Type": "application/json"}
    response = requests.post(
@@ -17,7 +20,7 @@ def artifact_exists(body):


def copy_artifact(body):
    logging.info("Submitting artifact to Artifact Manager")
    log.info("Submitting artifact to Artifact Manager")
    # body = json.dumps(body)
    headers = {"Content-Type": "application/json"}
    response = requests.post(artifact_manager_host + "/copy-artefact", headers=headers, json=body)
Loading