Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor metric process #339

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/spaceone/inventory/manager/collecting_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/spaceone/inventory/manager/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/spaceone/inventory/model/metric/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -31,6 +32,7 @@ class Metric(MongoModel):
"unit",
"tags",
"labels_info",
"is_new",
"version",
"workspaces",
"updated_at",
Expand Down
2 changes: 1 addition & 1 deletion src/spaceone/inventory/model/metric_data/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/spaceone/inventory/model/metric_example/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/spaceone/inventory/model/namespace/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading