Skip to content

Commit

Permalink
feat: add log-level configuration option (#478)
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Belanger <guillaume.belanger27@gmail.com>
  • Loading branch information
gruyaume authored Dec 6, 2024
1 parent b29d974 commit 5d85f11
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 28 deletions.
4 changes: 4 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ parts:
config:
options:
log-level:
type: string
default: info
description: Log level for the AMF. One of `debug`, `info`, `warn`, `error`, `fatal`, `panic`.
dnn:
type: string
default: internet
Expand Down
19 changes: 15 additions & 4 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,20 @@ def _get_invalid_configs(self) -> list[str]:
invalid_configs = []
if not self._get_dnn_config():
invalid_configs.append("dnn")
if not self._is_log_level_valid():
invalid_configs.append("log-level")
return invalid_configs

def _get_dnn_config(self) -> Optional[str]:
return cast(Optional[str], self.model.config.get("dnn"))

def _get_log_level_config(self) -> Optional[str]:
return cast(Optional[str], self.model.config.get("log-level"))

def _is_log_level_valid(self) -> bool:
log_level = self._get_log_level_config()
return log_level in ["debug", "info", "warn", "error", "fatal", "panic"]

def _get_external_amf_ip_config(self) -> Optional[str]:
return cast(Optional[str], self.model.config.get("external-amf-ip"))

Expand Down Expand Up @@ -558,6 +567,8 @@ def _generate_amf_config_file(self) -> str:
raise ValueError("NRF URL is not available")
if not self._webui_requires.webui_url:
raise ValueError("Webui URL is not available")
if not (log_level := self._get_log_level_config()):
raise ValueError("Log level configuration value is empty")

return self._render_config_file(
ngapp_port=NGAPP_PORT,
Expand All @@ -570,6 +581,7 @@ def _generate_amf_config_file(self) -> str:
dnn=dnn,
scheme="https",
webui_uri=self._webui_requires.webui_url,
log_level=log_level,
)

@staticmethod
Expand All @@ -585,6 +597,7 @@ def _render_config_file(
dnn: str,
scheme: str,
webui_uri: str,
log_level: str,
) -> str:
"""Render the AMF config file.
Expand All @@ -599,6 +612,7 @@ def _render_config_file(
dnn (str): Data Network name.
scheme (str): SBI interface scheme ("http" or "https")
webui_uri (str) : URL of the Webui.
log_level (str): Log level for the AMF.
Returns:
str: Content of the rendered config file.
Expand All @@ -616,6 +630,7 @@ def _render_config_file(
dnn=dnn,
scheme=scheme,
webui_uri=webui_uri,
log_level=log_level,
)
return content

Expand Down Expand Up @@ -684,10 +699,6 @@ def _amf_environment_variables(self) -> dict:
"""
return {
"GOTRACEBACK": "crash",
"GRPC_GO_LOG_VERBOSITY_LEVEL": "99",
"GRPC_GO_LOG_SEVERITY_LEVEL": "info",
"GRPC_TRACE": "all",
"GRPC_VERBOSITY": "DEBUG",
"POD_IP": _get_pod_ip(),
"MANAGED_BY_CONFIG_POD": "true",
}
Expand Down
3 changes: 3 additions & 0 deletions src/templates/amfcfg.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ configuration:
enable: true
expireTime: 6s
maxRetryTimes: 4
logger:
AMF:
debugLevel: {{ log_level }}
info:
description: AMF initial configuration
version: 1.0.0
3 changes: 3 additions & 0 deletions tests/unit/expected_config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ configuration:
enable: true
expireTime: 6s
maxRetryTimes: 4
logger:
AMF:
debugLevel: info
info:
description: AMF initial configuration
version: 1.0.0
24 changes: 16 additions & 8 deletions tests/unit/test_charm_collect_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@


class TestCharmCollectUnitStatus(AMFUnitTestFixtures):
def test_given_invalid_log_level_config_when_collect_unit_status_then_status_is_blocked(
self,
):
container = testing.Container(name="amf", can_connect=True)
state_in = testing.State(
leader=True,
config={"log-level": "invalid"},
containers={container},
)

state_out = self.ctx.run(self.ctx.on.collect_unit_status(), state_in)

assert state_out.unit_status == BlockedStatus(
"The following configurations are not valid: ['log-level']"
)

def test_given_fiveg_nrf_relation_not_created_when_collect_unit_status_then_status_is_blocked(
self,
):
Expand Down Expand Up @@ -216,10 +232,6 @@ def test_relations_available_and_config_pushed_and_pebble_updated_when_collect_u
"command": "/bin/amf --amfcfg /free5gc/config/amfcfg.conf",
"environment": {
"GOTRACEBACK": "crash",
"GRPC_GO_LOG_VERBOSITY_LEVEL": "99",
"GRPC_GO_LOG_SEVERITY_LEVEL": "info",
"GRPC_TRACE": "all",
"GRPC_VERBOSITY": "DEBUG",
"POD_IP": "192.0.2.1",
"MANAGED_BY_CONFIG_POD": "true",
},
Expand Down Expand Up @@ -379,10 +391,6 @@ def test_given_n2_information_and_service_is_running_and_metallb_service_is_not_
"command": "/bin/amf --amfcfg /free5gc/config/amfcfg.conf",
"environment": {
"GOTRACEBACK": "crash",
"GRPC_GO_LOG_VERBOSITY_LEVEL": "99",
"GRPC_GO_LOG_SEVERITY_LEVEL": "info",
"GRPC_TRACE": "all",
"GRPC_VERBOSITY": "DEBUG",
"POD_IP": "192.0.2.1",
"MANAGED_BY_CONFIG_POD": "true",
},
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/test_charm_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ def test_given_relations_available_and_config_pushed_when_pebble_ready_then_pebb
"command": "/bin/amf --amfcfg /free5gc/config/amfcfg.conf",
"environment": {
"GOTRACEBACK": "crash",
"GRPC_GO_LOG_VERBOSITY_LEVEL": "99",
"GRPC_GO_LOG_SEVERITY_LEVEL": "info",
"GRPC_TRACE": "all",
"GRPC_VERBOSITY": "DEBUG",
"POD_IP": "192.0.2.1",
"MANAGED_BY_CONFIG_POD": "true",
},
Expand Down
12 changes: 0 additions & 12 deletions tests/unit/test_charm_fiveg_n2_relation_joined.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ def test_given_n2_information_and_service_is_running_when_fiveg_n2_relation_join
"command": "/bin/amf --amfcfg /free5gc/config/amfcfg.conf",
"environment": {
"GOTRACEBACK": "crash",
"GRPC_GO_LOG_VERBOSITY_LEVEL": "99",
"GRPC_GO_LOG_SEVERITY_LEVEL": "info",
"GRPC_TRACE": "all",
"GRPC_VERBOSITY": "DEBUG",
"POD_IP": "192.0.2.1",
"MANAGED_BY_CONFIG_POD": "true",
},
Expand Down Expand Up @@ -93,10 +89,6 @@ def test_given_n2_information_and_service_is_running_and_n2_config_is_overriden_
"command": "/bin/amf --amfcfg /free5gc/config/amfcfg.conf",
"environment": {
"GOTRACEBACK": "crash",
"GRPC_GO_LOG_VERBOSITY_LEVEL": "99",
"GRPC_GO_LOG_SEVERITY_LEVEL": "info",
"GRPC_TRACE": "all",
"GRPC_VERBOSITY": "DEBUG",
"POD_IP": "192.0.2.1",
"MANAGED_BY_CONFIG_POD": "true",
},
Expand Down Expand Up @@ -147,10 +139,6 @@ def test_given_n2_information_and_service_is_running_and_lb_service_has_no_hostn
"command": "/bin/amf --amfcfg /free5gc/config/amfcfg.conf",
"environment": {
"GOTRACEBACK": "crash",
"GRPC_GO_LOG_VERBOSITY_LEVEL": "99",
"GRPC_GO_LOG_SEVERITY_LEVEL": "info",
"GRPC_TRACE": "all",
"GRPC_VERBOSITY": "DEBUG",
"POD_IP": "192.0.2.1",
"MANAGED_BY_CONFIG_POD": "true",
},
Expand Down

0 comments on commit 5d85f11

Please sign in to comment.