Skip to content

Commit

Permalink
feat: add metric data for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMin5 committed Sep 7, 2024
1 parent adc170e commit 3e647fa
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/plugin/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import logging

from spaceone.core.service import *
Expand Down Expand Up @@ -128,6 +127,12 @@ def collector_collect(params: dict) -> dict:
options=options, secret_data=secret_data, schema=""
)

for cloud_service_group in JiraBaseManager.get_all_cloud_service_group():
if not cloud_service_group:
continue

yield from JiraBaseManager.collect_metrics(cloud_service_group)


@app.route("Job.get_tasks")
def job_get_tasks(params: dict) -> dict:
Expand Down
39 changes: 39 additions & 0 deletions src/plugin/manager/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import logging
import os
from typing import Generator

from spaceone.core.error import *
from spaceone.core.manager import BaseManager
from spaceone.core import utils
from spaceone.inventory.plugin.collector.lib import *

_LOGGER = logging.getLogger("spaceone")

_CURRENT_DIR = os.path.dirname(__file__)
_METRIC_DIR = os.path.join(_CURRENT_DIR, "../metrics/")
_METADATA_DIR = os.path.join(_CURRENT_DIR, "../metadata/")


class JiraBaseManager(BaseManager):
provider = "jira"
Expand Down Expand Up @@ -38,6 +45,38 @@ def get_all_managers(cls, options):
else:
return cls.__subclasses__()

@classmethod
def get_all_cloud_service_group(cls) -> list:
cloud_service_groups = []
for subclass in cls.__subclasses__():
cloud_service_groups.append(subclass.cloud_service_group)
return list(set(cloud_service_groups))

@classmethod
def collect_metrics(cls, cloud_service_group: str):
if not os.path.exists(os.path.join(_METRIC_DIR, cloud_service_group)):
os.mkdir(os.path.join(_METRIC_DIR, cloud_service_group))
for dirname in os.listdir(os.path.join(_METRIC_DIR, cloud_service_group)):
for filename in os.listdir(
os.path.join(_METRIC_DIR, cloud_service_group, dirname)
):
if filename.endswith(".yaml"):
file_path = os.path.join(
_METRIC_DIR, cloud_service_group, dirname, filename
)
info = utils.load_yaml_from_file(file_path)
print(file_path)
if filename == "namespace.yaml":
yield make_response(
namespace=info,
resource_type="inventory.Namespace",
match_keys=[],
)
else:
yield make_response(
metric=info, resource_type="inventory.Metric", match_keys=[]
)

def error_response(
self, error: Exception, resource_type: str = "inventory.CloudService"
) -> dict:
Expand Down
5 changes: 3 additions & 2 deletions src/plugin/manager/issue_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@


class IssueManager(JiraBaseManager):
cloud_service_group = "Projects"
cloud_service_type = "Issue"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.cloud_service_group = "Projects"
self.cloud_service_type = "Issue"
self.metadata_path = "metadata/projects/issue.yaml"
self.project_connector = ProjectConnector()
self.issue_connector = IssueConnector()
Expand Down
5 changes: 3 additions & 2 deletions src/plugin/manager/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@


class ProjectManager(JiraBaseManager):
cloud_service_group = "Projects"
cloud_service_type = "Project"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.cloud_service_group = "Projects"
self.cloud_service_type = "Project"
self.metadata_path = "metadata/projects/project.yaml"
self.project_connector = ProjectConnector()

Expand Down
3 changes: 3 additions & 0 deletions src/plugin/manager/user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@


class MemberManager(JiraBaseManager):
cloud_service_group = "Projects"
cloud_service_type = "Member"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.cloud_service_group = "Projects"
Expand Down
8 changes: 8 additions & 0 deletions src/plugin/metrics/Projects/issue/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
namespace_id: ns-jira-software-projects-issue
name: Projects/Issue
category: ASSET
resource_type: inventory.CloudService:jira_software.Projects.Issue
group: jira_software
icon: https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/jira-icon.png"
version: '1.0'
24 changes: 24 additions & 0 deletions src/plugin/metrics/Projects/issue/projects_issue_count.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
metric_id: metric-jira-software-projects-issue-count
name: Project Count
metric_type: GAUGE
resource_type: inventory.CloudService:jira_software.Projects.Issue
query_options:
group_by:
- key: data.fields.project.name
name: Jira Project
- key: data.fields.status.name
name: Status
default: true
- key: data.fields.assignee.displayName
name: Assignee
- key: data.fields.issuetype.name
name: Issue Type
- key: data.fields.reporter.displayName
name: Reporter
fields:
value:
operator: count
unit: Count
namespace_id: ns-jira-software-projects-issue
version: '1.0'

0 comments on commit 3e647fa

Please sign in to comment.