Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1074 from chaos-genius/enable-analytics-endpoint
Browse files Browse the repository at this point in the history
feat(enable-anomaly): enables an anomaly by modifying the run_anomaly flag
  • Loading branch information
Samyak2 authored Aug 1, 2022
2 parents 78fb1c1 + 5d54645 commit 8ff2f82
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion chaos_genius/views/anomaly_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def kpi_anomaly_retraining(kpi_id: int):


@blueprint.route("/<int:kpi_id>/disable-anomaly", methods=["GET", "POST"])
def disable_anomaly(kpi_id):
def disable_anomaly(kpi_id):
"""API end point which disables analytics by modifying the run_anomaly flag."""
kpi = cast(Kpi, Kpi.get_by_id(kpi_id))
if kpi is not None:
Expand All @@ -412,6 +412,26 @@ def disable_anomaly(kpi_id):
return jsonify({"msg": message, "status": status})


@blueprint.route("/<int:kpi_id>/enable-anomaly", methods=["GET", "POST"])
def enable_anomaly(kpi_id):
"""API end point which enables analytics by modifying the run_anomaly flag."""
kpi = cast(Kpi, Kpi.get_by_id(kpi_id))
if kpi is not None:
if (not kpi.run_anomaly) and kpi.anomaly_params:
kpi.run_anomaly = True
kpi.update(commit=True)
message = f"Enabled Analytics for KPI ID: {kpi_id}"
status = "success"
else:
message = f"Falied to Enable Analytics for KPI ID: {kpi_id}"
status = "failure"
else:
message = f"KPI {kpi_id} could not be retreived"
status = "failure"
logger.info(message)
return jsonify({"msg": message, "status": status})


def _get_dimensions_values(
kpi_id: int, end_date: datetime, period=90
) -> List[Dict[str, Any]]:
Expand Down

0 comments on commit 8ff2f82

Please sign in to comment.