# What this PR does Adds labels implementation for integrations: - ability to create/update labels on creating/updating integration - ability to associate labels to integrations - cache for label reprs on OnCall side - feature flag to enable/disable labels ## Which issue(s) this PR fixes https://github.com/grafana/oncall-private/issues/2157 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --------- Co-authored-by: Maxim <maxim.mordasov@grafana.com> Co-authored-by: Rares Mardare <rares.mardare@grafana.com>
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
import logging
|
|
import typing
|
|
|
|
from django.apps import apps # noqa: I251
|
|
from django.conf import settings
|
|
|
|
if typing.TYPE_CHECKING:
|
|
from apps.labels.models import AssociatedLabel
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
LABEL_OUTDATED_TIMEOUT_MINUTES = 30
|
|
ASSOCIATED_MODEL_NAME = "AssociatedLabel"
|
|
|
|
|
|
class LabelUpdateParam(typing.TypedDict):
|
|
name: str
|
|
|
|
|
|
class LabelParams(typing.TypedDict):
|
|
id: str
|
|
name: str
|
|
|
|
|
|
class LabelData(typing.TypedDict):
|
|
key: LabelParams
|
|
value: LabelParams
|
|
|
|
|
|
class LabelKeyData(typing.TypedDict):
|
|
key: LabelParams
|
|
values: typing.List[LabelParams]
|
|
|
|
|
|
LabelsData = typing.List[LabelData]
|
|
LabelsKeysData = typing.List[LabelParams]
|
|
|
|
|
|
def get_associating_label_model(obj_model_name: str) -> typing.Type["AssociatedLabel"]:
|
|
associating_label_model_name = obj_model_name + ASSOCIATED_MODEL_NAME
|
|
label_model = apps.get_model("labels", associating_label_model_name)
|
|
return label_model
|
|
|
|
|
|
def is_labels_feature_enabled(organization) -> bool:
|
|
# check FEATURE_LABELS_ENABLED in settings
|
|
# checking labels feature flag per organization will be added later
|
|
|
|
logger.info(
|
|
"is_labels_feature_enabled: "
|
|
f"FEATURE_LABELS_ENABLED={settings.FEATURE_LABELS_ENABLED} "
|
|
f"organization={organization.id}"
|
|
)
|
|
return settings.FEATURE_LABELS_ENABLED
|