This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #956 from chaos-genius/develop
release: v0.7.0
- Loading branch information
Showing
63 changed files
with
2,663 additions
and
1,032 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM gitpod/workspace-postgres | ||
|
||
# Install Redis. | ||
RUN sudo apt-get update && \ | ||
sudo apt-get install -y redis-server && \ | ||
sudo rm -rf /var/lib/apt/lists/* | ||
|
||
ENV PYTHONUSERBASE=/workspace/.pip-modules | ||
ENV PATH=$PYTHONUSERBASE/bin:$PATH | ||
ENV PIP_USER=yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CHAOSGENIUS_WEBAPP_URL=CHAOSGENIUS_WEBAPP_URL_HERE | ||
|
||
DATABASE_URL_CG_DB=postgresql+psycopg2://gitpod@localhost/postgres | ||
|
||
CELERY_RESULT_BACKEND=redis://localhost:6379/1 | ||
CELERY_BROKER_URL=redis://localhost:6379/1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
image: | ||
file: .gitpod.dockerfile | ||
|
||
# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/ | ||
tasks: | ||
# modify .bashrc here. | ||
# `PGHOSTADDR` is set to the Postgres server running on Gitpod. pyscopg2 picks up this | ||
# variable and connects to that DB instead of the one we specify through data sources | ||
# for some reason. So we unset this. | ||
# See `DATABASE_URL_CG_DB` in `.gitpod.env` for the credentials to the Postgres server | ||
# running inside Gitpod. | ||
- before: printf 'unset PGHOSTADDR\n' >> $HOME/.bashrc && exit | ||
|
||
# the backend server | ||
- name: API Server | ||
init: | | ||
pip install wheel | ||
pip install -r requirements/dev.txt | ||
# notify that backend requirements have finished installing | ||
gp sync-done backend-reqs | ||
command: | | ||
cp .gitpod.env .env.local | ||
# get the URL for port 5000 exposed through Gitpod and use it as the WEBAPP_URL | ||
# TODO: links to "View KPI", etc. won't work since they are on port 3000 | ||
sed -i "s~CHAOSGENIUS_WEBAPP_URL_HERE~`gp url 5000`~g" ".env.local" | ||
# start postgres server | ||
pg_start | ||
# apply migrations | ||
flask db upgrade | ||
# notify that backend has been setup completely | ||
gp sync-done backend-setup | ||
bash dev_server.sh | ||
- name: Webapp | ||
init: | | ||
cd frontend | ||
npm install | ||
command: | | ||
cd frontend | ||
# BASE_URL is set to port 5000 exposed through gitpod | ||
REACT_APP_BASE_URL=`gp url 5000` npm start | ||
- name: Redis | ||
command: redis-server | ||
|
||
- name: Workers and Scheduler | ||
# TODO: is the await needed here? | ||
init: gp sync-await backend-reqs | ||
command: | | ||
# wait all of backend setup (incl. migrations, env vars) to be completed | ||
gp sync-await backend-setup | ||
bash dev_workers.sh | ||
ports: | ||
# webapp | ||
- port: 3000 | ||
onOpen: open-browser | ||
visibility: "public" | ||
# backend server | ||
- port: 5000 | ||
visibility: "public" | ||
|
||
vscode: | ||
extensions: | ||
- "ms-python.python" | ||
- "samuelcolvin.jinjahtml" | ||
|
||
github: | ||
prebuilds: | ||
# add a check to pull requests (defaults to true) | ||
addCheck: false | ||
# add a "Review in Gitpod" button as a comment to pull requests (defaults to false) | ||
addComment: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,96 @@ | ||
# -*- coding: utf-8 -*- | ||
"""alert controlller.""" | ||
from typing import Any, Dict, List, Literal, Optional, Sequence, Tuple, overload | ||
|
||
from flask_sqlalchemy import Pagination | ||
|
||
from chaos_genius.databases.models.alert_model import Alert | ||
|
||
ALERT_CHANNELS = { | ||
"email": "E-mail", | ||
"slack": "Slack", | ||
} | ||
"""A mapping of channel types and a readable name for them.""" | ||
|
||
def get_alert_list(frequency: str = None, as_obj: bool = False): | ||
"""get the list of the alerts | ||
|
||
Args: | ||
frequency (str, optional): schedular frequency for which | ||
alert need to tested. Defaults to None. | ||
as_obj (bool, optional): send the list as Alert object. | ||
Defaults to False. | ||
@overload | ||
def get_alert_list( | ||
frequency: Optional[str] = None, | ||
as_obj: Literal[False] = False, | ||
page_num_size: Optional[None] = None, | ||
extra_filters: Optional[Sequence] = None, | ||
) -> List[Dict[str, Any]]: | ||
... | ||
|
||
|
||
@overload | ||
def get_alert_list( | ||
frequency: Optional[str] = None, | ||
as_obj: Literal[True] = True, | ||
page_num_size: Optional[None] = None, | ||
extra_filters: Optional[Sequence] = None, | ||
) -> List[Alert]: | ||
... | ||
|
||
|
||
# TODO: find a way to specify the type inside Pagination i.e, type of Pagination.items | ||
@overload | ||
def get_alert_list( | ||
frequency: Optional[str] = None, | ||
as_obj: bool = False, | ||
page_num_size: Tuple[int, int] = (0, 0), | ||
extra_filters: Optional[Sequence] = None, | ||
) -> Pagination: | ||
... | ||
|
||
|
||
Returns: | ||
list: List of the alerts | ||
def get_alert_list( | ||
frequency: Optional[str] = None, | ||
as_obj: bool = False, | ||
page_num_size: Optional[Tuple[int, int]] = None, | ||
extra_filters: Optional[Sequence] = None, | ||
): | ||
"""Retrieve all alerts. | ||
Args: | ||
frequency: alert frequency to filter on. If not provided, all | ||
alerts are retrieved. | ||
as_obj: returns a list of Alert objects if True, otherwise a | ||
list of Dicts representing the alerts is returned. | ||
page_num_size: if provided, returns a Pagination object instead of the whole | ||
list. This is a tuple of (page, per_page). The items inside the Pagination | ||
object are either Alert objects or Dicts based on as_obj. | ||
extra_filters: SQLalchemy filters added to the query if provided. | ||
""" | ||
filters = [Alert.alert_status == True] | ||
filters = [Alert.alert_status == True] # noqa: E712 | ||
if frequency: | ||
filters.extend([Alert.alert_frequency == frequency]) | ||
data = Alert.query.filter(*filters).order_by(Alert.id.desc()).all() | ||
if as_obj: | ||
results = data | ||
if extra_filters is not None: | ||
filters.extend([filter for filter in extra_filters if filter is not None]) | ||
|
||
query = Alert.query.filter(*filters).order_by(Alert.created_at.desc()) | ||
|
||
if page_num_size is not None: | ||
page, per_page = page_num_size | ||
alerts_paginated: Pagination = query.paginate(page=page, per_page=per_page) | ||
if not as_obj: | ||
alerts_paginated.items = [alert.as_dict for alert in alerts_paginated.items] | ||
return alerts_paginated | ||
else: | ||
results = [point.as_dict for point in data] | ||
return results | ||
alerts: List[Alert] = query.all() | ||
|
||
if not as_obj: | ||
alerts_dict: List[Dict[str, Any]] = [alert.as_dict for alert in alerts] | ||
return alerts_dict | ||
|
||
def get_alert_info(id: int): | ||
"""alert info for any given alert id | ||
return alerts | ||
|
||
Args: | ||
id (int): alert id | ||
""" | ||
alert = Alert.get_by_id(id) | ||
|
||
def get_alert_info(alert_id: int) -> Dict[str, Any]: | ||
"""Retrieve Alert object by ID.""" | ||
alert = Alert.get_by_id(alert_id) | ||
|
||
if not alert: | ||
raise Exception("Alert ID doesn't exist") | ||
raise Exception(f"Alert with ID {alert_id} does not exist.") | ||
else: | ||
return alert.as_dict |
Oops, something went wrong.