Skip to content

Commit

Permalink
feat: add log-level configuration option (#440)
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Belanger <[email protected]>
  • Loading branch information
gruyaume authored Dec 9, 2024
1 parent febfd1f commit 4d84e7e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,7 @@ config:
default: true
description: |
When enabled, hardware checksum will be used on the network interfaces.
log-level:
type: string
default: info
description: Log level for the UPF. One of `debug`, `info`, `warn`, `error`, `fatal`, `panic`.
4 changes: 4 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ def _create_upf_configuration_file(self) -> tuple[bool, bool]:
dnn=self._charm_config.dnn,
pod_share_path=POD_SHARE_PATH,
enable_hw_checksum=self._charm_config.enable_hw_checksum,
log_level=self._charm_config.log_level,
)
if (
not self._upf_config_file_is_written_to_bessd_container()
Expand Down Expand Up @@ -1164,6 +1165,7 @@ def render_bessd_config_file(
dnn: str,
pod_share_path: str,
enable_hw_checksum: bool,
log_level: str,
) -> str:
"""Render the configuration file for the 5G UPF service.
Expand All @@ -1176,6 +1178,7 @@ def render_bessd_config_file(
dnn: Data Network Name (DNN)
pod_share_path: pod_share path
enable_hw_checksum: Whether to enable hardware checksum or not
log_level (str): Log level for the UPF.
"""
jinja2_environment = Environment(loader=FileSystemLoader("src/templates/"))
template = jinja2_environment.get_template(f"{CONFIG_FILE_NAME}.j2")
Expand All @@ -1188,6 +1191,7 @@ def render_bessd_config_file(
dnn=dnn,
pod_share_path=pod_share_path,
hwcksum=str(enable_hw_checksum).lower(),
log_level=log_level,
)
return content

Expand Down
12 changes: 12 additions & 0 deletions src/charm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class UpfMode(str, Enum):
af_packet = "af_packet"
dpdk = "dpdk"

class LogLevel(str, Enum):
"""Class to define available log levels for UPF operator."""

DEBUG = "debug"
INFO = "info"
WARN = "warn"
ERROR = "error"
FATAL = "fatal"
PANIC = "panic"

NetworkType: TypeAlias = "str | bytes | int | tuple[str | bytes | int, str | int]"

Expand Down Expand Up @@ -85,6 +94,7 @@ class UpfConfig(BaseModel): # pylint: disable=too-few-public-methods
core_interface_mtu_size: Optional[int] = Field(default=None, ge=1200, le=65535)
external_upf_hostname: Optional[StrictStr] = Field(default="")
enable_hw_checksum: bool = True
log_level: LogLevel = LogLevel.INFO

@model_validator(mode="after")
def validate_upf_mode_with_mac_addresses(self):
Expand Down Expand Up @@ -153,6 +163,7 @@ class CharmConfig:
core_interface_mtu_size: Optional[int]
external_upf_hostname: Optional[StrictStr]
enable_hw_checksum: bool
log_level: LogLevel

def __init__(self, *, upf_config: UpfConfig):
"""Initialize a new instance of the CharmConfig class.
Expand All @@ -176,6 +187,7 @@ def __init__(self, *, upf_config: UpfConfig):
self.core_interface_mtu_size = upf_config.core_interface_mtu_size
self.external_upf_hostname = upf_config.external_upf_hostname
self.enable_hw_checksum = upf_config.enable_hw_checksum
self.log_level = upf_config.log_level

@classmethod
def from_charm(
Expand Down
2 changes: 1 addition & 1 deletion src/templates/upf.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"enable_notify_bess": true,
"gtppsc": true,
"hwcksum": {{ hwcksum }},
"log_level": "info",
"log_level": "{{ log_level }}",
"max_sessions": 50000,
"measure_flow": false,
"measure_upf": true,
Expand Down

0 comments on commit 4d84e7e

Please sign in to comment.