Skip to content

Commit

Permalink
Move Opsgenie calculations to blueprint level (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyGis authored Dec 21, 2023
1 parent 0f92c2f commit dd9737f
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 20 deletions.
27 changes: 22 additions & 5 deletions integrations/opsgenie/.port/resources/blueprints.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@
},
"title": "Oncall Users",
"description": "Who is on call for this service"
},
"numOpenIncidents": {
"title": "Number of Open Incidents",
"type": "number"
}
}
},
"required": []
},
Expand All @@ -69,6 +65,27 @@
"type": "number"
}
},
"aggregationProperties":{
"numberOfOpenIncidents":{
"title":"Number of open incidents",
"type":"number",
"target":"opsGenieIncident",
"query":{
"combinator":"and",
"rules":[
{
"property":"status",
"operator":"=",
"value":"open"
}
]
},
"calculationSpec":{
"calculationBy":"entities",
"func":"count"
}
}
},
"relations": {}
},
{
Expand Down
1 change: 0 additions & 1 deletion integrations/opsgenie/.port/resources/port-app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ resources:
oncallTeam: .__team.name
teamMembers: '[.__team.members[].user.username]'
oncallUsers: .__oncalls.onCallRecipients
numOpenIncidents: '[ .__incidents[] | select(.status == "open")] | length'
- kind: alert
selector:
query: 'true'
Expand Down
7 changes: 7 additions & 0 deletions integrations/opsgenie/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- towncrier release notes start -->

# Port_Ocean 0.1.14 (2023-12-21)

### Improvements

- Moved the number of open incidents (numOpenIncidents) calculation from the opsGenieService blueprint to utilize the aggregationProperties capabilities in Ocean (#14)


# Port_Ocean 0.1.13 (2023-12-21)

### Improvements
Expand Down
10 changes: 0 additions & 10 deletions integrations/opsgenie/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ async def get_associated_alerts(
event.attributes[cache_key] = associated_alerts
return associated_alerts

async def get_incidents_by_service(self, service_id: str) -> list[dict[str, Any]]:
incidents = []
async for incident_batch in self.get_paginated_resources(ObjectKind.INCIDENT):
incidents.extend(incident_batch)
return [
incident
for incident in incidents
if service_id in incident["impactedServices"]
]

async def get_impacted_services(
self, impacted_service_ids: list[str]
) -> list[dict[str, Any]]:
Expand Down
4 changes: 1 addition & 3 deletions integrations/opsgenie/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ async def enrich_services_with_team_data(
service: dict[str, Any],
) -> dict[str, Any]:
async with semaphore:
team_data, schedule, related_incidents = await asyncio.gather(
team_data, schedule = await asyncio.gather(
opsgenie_client.get_oncall_team(service["teamId"]),
opsgenie_client.get_schedule_by_team(service["teamId"]),
opsgenie_client.get_incidents_by_service(service["id"]),
)

service["__team"] = team_data
service["__incidents"] = related_incidents
if schedule:
service["__oncalls"] = await opsgenie_client.get_oncall_user(schedule["id"])
return service
Expand Down
2 changes: 1 addition & 1 deletion integrations/opsgenie/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "opsgenie"
version = "0.1.13"
version = "0.1.14"
description = "Ocean integration for OpsGenie"
authors = ["Isaac Coffie <isaac@getport.io>"]

Expand Down
153 changes: 153 additions & 0 deletions integrations/servicenow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

0 comments on commit dd9737f

Please sign in to comment.