From 91172abf7acbc21f802d4958a34ade487db20325 Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Wed, 29 May 2024 22:54:37 +0900 Subject: [PATCH] refactor: refactor metric process Signed-off-by: Jongmin Kim --- src/spaceone/inventory/manager/collecting_manager.py | 1 + src/spaceone/inventory/manager/job_manager.py | 8 ++++++-- src/spaceone/inventory/model/metric/database.py | 4 +++- src/spaceone/inventory/model/metric_data/database.py | 2 +- src/spaceone/inventory/model/metric_example/database.py | 4 ++-- src/spaceone/inventory/model/namespace/database.py | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/spaceone/inventory/manager/collecting_manager.py b/src/spaceone/inventory/manager/collecting_manager.py index ed50c9a..d29280c 100644 --- a/src/spaceone/inventory/manager/collecting_manager.py +++ b/src/spaceone/inventory/manager/collecting_manager.py @@ -277,6 +277,7 @@ def _upsert_metric_and_namespace(self, resource_data: dict, params: dict) -> Non if workspace_id not in workspaces: workspaces.append(workspace_id) request_data["workspaces"] = workspaces + request_data["is_new"] = True is_changed = True else: request_data["workspaces"] = workspaces diff --git a/src/spaceone/inventory/manager/job_manager.py b/src/spaceone/inventory/manager/job_manager.py index 3858b95..84857f5 100644 --- a/src/spaceone/inventory/manager/job_manager.py +++ b/src/spaceone/inventory/manager/job_manager.py @@ -109,14 +109,18 @@ def _run_metric_queries(self, plugin_id: str, domain_id: str) -> None: is_managed=True, domain_id=domain_id ) for managed_metric_vo in managed_metric_vos: - if managed_metric_vo.metric_id in recent_metrics: + if managed_metric_vo.is_new or ( + managed_metric_vo.metric_id in recent_metrics + ): metric_mgr.push_task(managed_metric_vo) plugin_metric_vos = metric_mgr.filter_metrics( plugin_id=plugin_id, domain_id=domain_id ) for plugin_metric_vo in plugin_metric_vos: - if plugin_metric_vo.metric_id in recent_metrics: + if plugin_metric_vo.is_new or ( + plugin_metric_vo.metric_id in recent_metrics + ): metric_mgr.push_task(plugin_metric_vo) @staticmethod diff --git a/src/spaceone/inventory/model/metric/database.py b/src/spaceone/inventory/model/metric/database.py index aba99d6..eab6803 100644 --- a/src/spaceone/inventory/model/metric/database.py +++ b/src/spaceone/inventory/model/metric/database.py @@ -14,9 +14,10 @@ class Metric(MongoModel): tags = DictField(default=None) labels_info = ListField(DictField()) is_managed = BooleanField(default=False) + is_new = BooleanField(default=True) version = StringField(max_length=40, default=None, null=True) plugin_id = StringField(max_length=40, default=None, null=True) - namespace_id = StringField(max_length=40) + namespace_id = StringField(max_length=80) domain_id = StringField(max_length=40) workspaces = ListField(StringField(max_length=40)) created_at = DateTimeField(auto_now_add=True) @@ -31,6 +32,7 @@ class Metric(MongoModel): "unit", "tags", "labels_info", + "is_new", "version", "workspaces", "updated_at", diff --git a/src/spaceone/inventory/model/metric_data/database.py b/src/spaceone/inventory/model/metric_data/database.py index 90b2b7a..a3e5879 100644 --- a/src/spaceone/inventory/model/metric_data/database.py +++ b/src/spaceone/inventory/model/metric_data/database.py @@ -10,7 +10,7 @@ class MetricData(MongoModel): value = FloatField(default=0) unit = StringField(default=None) labels = DictField(default=None) - namespace_id = StringField(max_length=40) + namespace_id = StringField(max_length=80) service_account_id = StringField(max_length=40, default=None, null=True) project_id = StringField(max_length=40) workspace_id = StringField(max_length=40) diff --git a/src/spaceone/inventory/model/metric_example/database.py b/src/spaceone/inventory/model/metric_example/database.py index b124ea9..5ea3bd2 100644 --- a/src/spaceone/inventory/model/metric_example/database.py +++ b/src/spaceone/inventory/model/metric_example/database.py @@ -7,8 +7,8 @@ class MetricExample(MongoModel): name = StringField(max_length=40) options = DictField(default=None) tags = DictField(default=None) - metric_id = StringField(max_length=40) - namespace_id = StringField(max_length=40) + metric_id = StringField(max_length=80) + namespace_id = StringField(max_length=80) user_id = StringField(max_length=40) workspace_id = StringField(max_length=40, default=None, null=True) domain_id = StringField(max_length=40) diff --git a/src/spaceone/inventory/model/namespace/database.py b/src/spaceone/inventory/model/namespace/database.py index c022e1c..08e902b 100644 --- a/src/spaceone/inventory/model/namespace/database.py +++ b/src/spaceone/inventory/model/namespace/database.py @@ -3,7 +3,7 @@ class Namespace(MongoModel): - namespace_id = StringField(max_length=40, unique_with="domain_id") + namespace_id = StringField(max_length=80, unique_with="domain_id") name = StringField(max_length=40) category = StringField(max_length=40) provider = StringField(max_length=40)