Skip to content

Commit

Permalink
Do not modify the global builtin_dashboards in CME provider sites
Browse files Browse the repository at this point in the history
Such global states must not be modified by the request processing logic.
Doing so can lead to inconsistent situations and lead to race conditions
in threaded environments.

CMK-20694

Change-Id: I15a1c21c52ca166327340e2dbf7f3df69a8c8f2a
  • Loading branch information
LarsMichelsen committed Jan 20, 2025
1 parent af4ab9f commit c4482ce
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
10 changes: 9 additions & 1 deletion cmk/gui/cre/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
from cmk.gui.cron import cron_job_registry
from cmk.gui.custom_icons.registration import custom_icons_register
from cmk.gui.customer import customer_api_registry, CustomerAPIStub
from cmk.gui.dashboard import dashlet_registry
from cmk.gui.dashboard import (
builtin_dashboard_extender_registry,
BuiltinDashboardExtender,
dashlet_registry,
noop_builtin_dashboard_extender,
)
from cmk.gui.data_source import data_source_registry
from cmk.gui.features import Features, features_registry
from cmk.gui.help_menu import (
Expand Down Expand Up @@ -280,6 +285,9 @@ def register(edition: Edition) -> None:
permission_registry,
)
_openapi_registration()
builtin_dashboard_extender_registry.register(
BuiltinDashboardExtender(edition.short, noop_builtin_dashboard_extender)
)


def _openapi_registration() -> None:
Expand Down
14 changes: 13 additions & 1 deletion cmk/gui/dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
from cmk.gui.permissions import declare_dynamic_permissions, declare_permission, permission_registry

from ._network_topology import get_topology_context_and_filters
from .builtin_dashboards import builtin_dashboards, GROW, MAX
from .builtin_dashboards import (
builtin_dashboard_extender_registry,
builtin_dashboards,
BuiltinDashboardExtender,
BuiltinDashboardExtenderRegistry,
GROW,
MAX,
noop_builtin_dashboard_extender,
)
from .dashlet import (
ABCFigureDashlet,
Dashlet,
Expand All @@ -36,7 +44,10 @@
"DashletRegistry",
"DashboardName",
"DashboardConfig",
"builtin_dashboard_extender_registry",
"builtin_dashboards",
"BuiltinDashboardExtender",
"BuiltinDashboardExtenderRegistry",
"MAX",
"GROW",
"dashlet_registry",
Expand All @@ -47,6 +58,7 @@
"get_topology_context_and_filters",
"get_all_dashboards",
"get_permitted_dashboards",
"noop_builtin_dashboard_extender",
"render_title_with_macros_string",
"ABCFigureDashlet",
"IFrameDashlet",
Expand Down
29 changes: 29 additions & 0 deletions cmk/gui/dashboard/builtin_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,39 @@
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from collections.abc import Callable, Mapping
from dataclasses import dataclass

from cmk.ccc.plugin_registry import Registry

from cmk.gui.config import Config

from .type_defs import DashboardConfig, DashboardName

# Declare constants to be used in the definitions of the dashboards
GROW = 0
MAX = -1

builtin_dashboards: dict[DashboardName, DashboardConfig] = {}


@dataclass(frozen=True)
class BuiltinDashboardExtender:
ident: str
callable: Callable[
[Mapping[DashboardName, DashboardConfig], Config], dict[DashboardName, DashboardConfig]
]


class BuiltinDashboardExtenderRegistry(Registry[BuiltinDashboardExtender]):
def plugin_name(self, instance: BuiltinDashboardExtender) -> str:
return instance.ident


def noop_builtin_dashboard_extender(
dashboards: Mapping[DashboardName, DashboardConfig], config: Config
) -> dict[DashboardName, DashboardConfig]:
return {**dashboards}


builtin_dashboard_extender_registry = BuiltinDashboardExtenderRegistry()
12 changes: 10 additions & 2 deletions cmk/gui/dashboard/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@
import time
from typing import Any

import cmk.ccc.version as cmk_version
from cmk.ccc.exceptions import MKGeneralException

from cmk.utils import paths
from cmk.utils.user import UserId

from cmk.gui import visuals
from cmk.gui.config import active_config
from cmk.gui.exceptions import MKUserError
from cmk.gui.hooks import request_memoize
from cmk.gui.http import request
from cmk.gui.i18n import _
from cmk.gui.user_async_replication import user_profile_async_replication_page
from cmk.gui.views.store import internal_view_to_runtime_view

from .builtin_dashboards import builtin_dashboards
from .builtin_dashboards import (
builtin_dashboard_extender_registry,
builtin_dashboards,
)
from .type_defs import DashboardConfig, DashboardName, DashletConfig, DashletId


Expand All @@ -39,7 +45,9 @@ def _load_all(self) -> dict[tuple[UserId, DashboardName], DashboardConfig]:
"""Loads all definitions from disk and returns them"""
return visuals.load(
"dashboards",
builtin_dashboards,
builtin_dashboard_extender_registry[cmk_version.edition(paths.omd_root).short].callable(
builtin_dashboards, active_config
),
_internal_dashboard_to_runtime_dashboard,
)

Expand Down

0 comments on commit c4482ce

Please sign in to comment.