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

CG Demo: enabling/disabling certain functionality #556

Draft
wants to merge 41 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
079b64c
CG demo instance
Dec 27, 2021
1bc2609
Demo obfuscation for alerts API
Dec 29, 2021
545f307
Delete package-lock.json
ChartistDev Jan 3, 2022
3a9e6a1
removed unused variable
Jan 3, 2022
ff5918b
resolved merge conflicts
Jan 3, 2022
e1fe3cf
Merge branch 'main' of github.com:chaos-genius/chaos_genius into CG-Demo
Jan 5, 2022
e29be8d
removed is_demo env variable from frontend env
Jan 5, 2022
ee968d9
merge
Jan 5, 2022
502ad21
feat: Add hook to restrict APIs for the demo version
bhargavsk1077 Jan 12, 2022
cf2f5d7
fix: Fix bug in register_hooks function
bhargavsk1077 Jan 12, 2022
9b7fe08
conflicts resolved
Feb 23, 2022
e9fb9e9
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Feb 23, 2022
db972c7
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Feb 24, 2022
d2b91e5
added demo check for report setting time
Feb 24, 2022
9203a61
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Feb 24, 2022
40f8dff
fix:Add get-timecuts-list API to demo whitelist
bhargavsk1077 Feb 24, 2022
f2aa3b1
added restrictions for channel configuration
Feb 24, 2022
6f2755b
Merge branch 'CG-Demo' of github.com:chaos-genius/chaos_genius into C…
Feb 24, 2022
8726496
added GA script
Feb 25, 2022
97d4049
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Mar 17, 2022
2e8311f
added demo obfuscation for retrain model
Mar 17, 2022
4b43a78
Merge branch 'develop' of github.com:chaos-genius/chaos_genius into C…
Mar 23, 2022
35ba6c4
added demo obfuscation for deleting alerts
Mar 23, 2022
c9a69bb
fix: Whitelist APIs based on request method
bhargavsk1077 Mar 24, 2022
912f673
refactor: Change return messages in register_hooks
bhargavsk1077 Mar 25, 2022
73e4c9a
refactor: Use _make_bool for REACT_APP_IS_DEMO
bhargavsk1077 Mar 25, 2022
57b60ef
style: Format DEMO_ENDPOINT_WHITELIST
bhargavsk1077 Mar 25, 2022
12a4149
fix: Add REACT_APP_IS_DEMO to all compose files
bhargavsk1077 Mar 25, 2022
1954e9a
style: format register_hooks function in app.py
bhargavsk1077 Mar 25, 2022
c1baf44
updated demo to 0.6.0
Apr 14, 2022
41636a7
added obfuscation for sycnc schema in Demo
Apr 14, 2022
ce27e67
fix: Add download APIs to whitelist
bhargavsk1077 Apr 14, 2022
0d08b4f
resolved duplicate variables issues
Apr 14, 2022
07e3af1
Merge branch 'CG-Demo' of github.com:chaos-genius/chaos_genius into C…
Apr 14, 2022
8f148ac
fix: Add support timezone API to whitelist
bhargavsk1077 Apr 14, 2022
e3c234c
merge conflict resolved
ChartistDev Jun 14, 2022
e6346c0
chore(demo): add new summary endpoints to whitelist
Samyak2 Jun 14, 2022
a973c10
resolved merge conflict
ChartistDev Jul 5, 2022
fb89c2d
fix(demo): update endpoint whitelist
Samyak2 Jul 5, 2022
300ff77
resolved merge conflicts
ChartistDev Aug 29, 2022
13e58dc
fix(demo): use a single level before_request hook
Samyak2 Aug 29, 2022
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
24 changes: 23 additions & 1 deletion chaos_genius/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import sys
import json

from flask import Flask, render_template
from flask import Flask, render_template, request
from flask.json import jsonify
from flask_cors import CORS

from chaos_genius import commands
from chaos_genius.logger import configure_logger
from chaos_genius.settings import REACT_APP_IS_DEMO
from chaos_genius.utils.utils import DEMO_ENDPOINT_WHITELIST
from chaos_genius.views import (
data_source_view,
kpi_view,
Expand Down Expand Up @@ -45,6 +48,7 @@ def create_app(config_object="chaos_genius.settings"):
app.config.from_object(config_object)
register_extensions(app)
register_blueprints(app)
register_hooks(app)
register_errorhandlers(app)
register_shellcontext(app)
register_commands(app)
Expand Down Expand Up @@ -114,6 +118,24 @@ def shell_context():
app.shell_context_processor(shell_context)


def register_hooks(app):
@app.before_request
def authenticate():
Samyak2 marked this conversation as resolved.
Show resolved Hide resolved

if REACT_APP_IS_DEMO:
@app.before_request
def before_request():
if request.endpoint not in DEMO_ENDPOINT_WHITELIST:
return jsonify({"status":"failure",
"message":"Endpoint not accessable in demo version"})
else:
if request.method not in DEMO_ENDPOINT_WHITELIST[request.endpoint]:
return jsonify({"status":"failure",
"message":"Method not allowed in demo version"})
Samyak2 marked this conversation as resolved.
Show resolved Hide resolved
Samyak2 marked this conversation as resolved.
Show resolved Hide resolved
else:
pass
Samyak2 marked this conversation as resolved.
Show resolved Hide resolved


def register_commands(app):
"""Register Click commands."""
app.cli.add_command(commands.test)
Expand Down
5 changes: 5 additions & 0 deletions chaos_genius/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def _make_bool(val: Union[str, bool]) -> bool:

CHAOSGENIUS_ENTERPRISE_EDITION_KEY = os.getenv("CHAOSGENIUS_ENTERPRISE_EDITION_KEY")

REACT_APP_IS_DEMO = os.getenv("REACT_APP_IS_DEMO")
if REACT_APP_IS_DEMO == 'true':
REACT_APP_IS_DEMO = True
else:
REACT_APP_IS_DEMO = False
Samyak2 marked this conversation as resolved.
Show resolved Hide resolved
"""Dynamic Third Party Data Sources"""
SOURCE_GOOGLE_ANALYTICS = _make_bool(os.getenv("SOURCE_GOOGLE_ANALYTICS", default=True))
SOURCE_GOOGLE_SHEETS = _make_bool(os.getenv("SOURCE_GOOGLE_SHEETS", default=True))
Expand Down
55 changes: 55 additions & 0 deletions chaos_genius/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,58 @@ def latest_git_commit_hash() -> str:
)
except (subprocess.CalledProcessError, FileNotFoundError):
return ""

DEMO_ENDPOINT_WHITELIST = {"alert.alert_meta_info":["GET"],
Samyak2 marked this conversation as resolved.
Show resolved Hide resolved
"alert.get_alert_info_by_id":["GET"],
"alert.disable_alert":["GET"],
"alert.enable_alert":["GET"],
"alert.list_alert":["GET"],
"anomaly_data.anomaly_settings_status":["GET"],
"anomaly_data.kpi_anomaly_data_quality":["GET"],
"anomaly_data.kpi_anomaly_detection":["GET"],
"anomaly_data.kpi_anomaly_drilldown":["GET"],
"anomaly_data.kpi_anomaly_params":["GET"],
"anomaly_data.kpi_anomaly_params_meta":["GET"],
"anomaly_data.kpi_subdim_anomaly":["GET"],
"anomaly_data.list_anomaly_data":["GET"],
"api_data_source.data_source":["GET"],
"api_data_source.data_source_meta_info":["GET"],
"api_data_source.get_data_source_info":["GET"],
"api_data_source.list_data_source_type":["GET"],
# "api_data_source.log_data_source",
"api_data_source.metadata_data_source":["POST"],
"api_data_source.test_data_source_connection":["GET"],
"api_data_source.check_views_availability":["POST"],
"api_data_source.get_schema_list":["POST"],
"api_data_source.get_schema_tables":["POST"],
"api_data_source.get_table_info":["POST"],
"api_kpi.kpi":["GET"],
"api_kpi.get_all_kpis":["GET"],
"api_kpi.get_kpi_info":["GET"],
"api_kpi.kpi_get_dimensions":["GET"],
"api_kpi.get_timecuts_list":["GET"],
"api_kpi.kpi_meta_info":["GET"],
"api_rca.kpi_get_aggregation":["GET"],
"api_rca.kpi_get_line_data":["GET"],
"api_rca.kpi_rca_analysis":["GET"],
"api_rca.kpi_rca_hierarchical_data":["GET"],
"config_settings.get_all_config":["GET"],
"config_settings.get_config":["POST"],
"config_settings.set_config":["POST"],
"config_settings.get_config_meta_data":["GET"],
"config_settings.get_onboarding_status":["GET"],
"config_settings.global_config":["GET"],
# "config_settings.global_settings",
"config_settings.multidim_status":["GET"],
"config_settings.edit_config_setting":["PUT"],
"dashboard.get_dashboard_list":["GET"],
"dashboard.get_dashboard":["GET"],
# "meta.static",
# "public.api_view",
# "public.home",
# "public.static",
# "static",
# "status.static",
# "status.task_monitor_view",
"meta.version_view":["GET"]}

1 change: 1 addition & 0 deletions docker-compose.latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
environment:
- *chaosgenius-version
- IN_DOCKER=True
- REACT_APP_IS_DEMO=${REACT_APP_IS_DEMO}
Samyak2 marked this conversation as resolved.
Show resolved Hide resolved
- AIRBYTE_ENABLED=${AIRBYTE_ENABLED}
- FLASK_APP=${FLASK_APP}
- FLASK_ENV=${FLASK_ENV}
Expand Down
13 changes: 13 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-ZTDCWNG9GQ"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-ZTDCWNG9GQ');
</script>
<script src="%PUBLIC_URL%/env.js"></script>
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/AlertTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const RESET_DELETE_DATA = {
type: 'RESET_DELETE_DATA'
};

const AlertTable = ({ alertData, alertSearch }) => {
const AlertTable = ({ alertData, alertSearch, customToast }) => {
const dispatch = useDispatch();

const [isOpen, setIsOpen] = useState(false);
Expand All @@ -51,7 +51,7 @@ const AlertTable = ({ alertData, alertSearch }) => {

const onDeleteConfirmation = (id) => {
store.dispatch(RESET_DELETE_DATA);
dispatch(kpiAlertDeleteById(id));
dispatch(kpiAlertDeleteById(id, customToast));
setIsOpen(false);
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/AlertsForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ const AlertsForm = () => {
};

const dispatchGetAllAlertEmail = (data) => {
dispatch(getAllAlertEmail(data));
dispatch(getAllAlertEmail(data, customToast));
};

const editableStatus = (type) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Analystics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const Analystics = ({ kpi, setAnalystics, onboarding }) => {
scheduler_params_time: schedule
}
};
dispatch(kpiSettingSetup(kpi, data));
dispatch(kpiSettingSetup(kpi, data, customToast));
}
};

Expand Down
32 changes: 31 additions & 1 deletion frontend/src/components/Anomaly/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import AnomalyEmptyState from '../AnomalyEmptyState';
import EmptyAnomalyDrilldown from '../EmptyDrillDown';
import { formatDateTime, getTimezone } from '../../utils/date-helper';
import { HRNumbers } from '../../utils/Formatting/Numbers/humanReadableNumberFormatter';
import { useToast } from 'react-toast-wnm';
import { CustomContent, CustomActions } from '../../utils/toast-helper';
import './anomaly.scss';

import {
Expand Down Expand Up @@ -42,6 +44,34 @@ const RESET = {
};

const Anomaly = ({ kpi, anomalystatus, dashboard }) => {
const toast = useToast();
const customToast = (data) => {
const { type, header, description } = data;
toast({
autoDismiss: true,
enableAnimation: true,
delay: type === 'success' ? '5000' : '30000',
backgroundColor: type === 'success' ? '#effaf5' : '#FEF6F5',
borderRadius: '6px',
color: '#222222',
position: 'bottom-right',
minWidth: '240px',
width: 'auto',
boxShadow: '4px 6px 32px -2px rgba(226, 226, 234, 0.24)',
padding: '17px 14px',
height: 'auto',
border: type === 'success' ? '1px solid #60ca9a' : '1px solid #FEF6F5',
type: type,
actions: <CustomActions />,
content: (
<CustomContent
header={header}
description={description}
failed={type === 'success' ? false : true}
/>
)
});
};
const dispatch = useDispatch();
const history = useHistory();
const [chartData, setChartData] = useState([]);
Expand Down Expand Up @@ -411,7 +441,7 @@ const Anomaly = ({ kpi, anomalystatus, dashboard }) => {
};

const handleRetrain = () => {
dispatch(setRetrain(kpi));
dispatch(setRetrain(kpi, customToast));
};

return (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/DashboardForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ const DashboardForm = ({ setText, setModal, onboarding }) => {
dashboard_name: formData.dashboardname,
kpi_list: formData.kpi
};
dispatch(getUpdateDashboard(payload));
dispatch(getUpdateDashboard(payload, customToast));
} else {
const dashboardData = {
dashboard_name: formData.dashboardname,
kpi_list: formData.kpi
};
dispatch(getCreateDashboard(dashboardData));
dispatch(getCreateDashboard(dashboardData, customToast));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Dashboardcards/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Dashboardcards = ({ dashboarddata, setChange }) => {
};

const onDelete = (value) => {
dispatch(getDashboardDelete({ dashboard_id: value.id }));
dispatch(getDashboardDelete({ dashboard_id: value.id }, customToast));
};

const customToast = (data) => {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/DataSourceForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ const DataSourceForm = ({ onboarding, setModal, setText }) => {
sourceDefinitionId: sourceDefinitionId
}
};
dispatch(createDataSource(bingPayload));
dispatch(createDataSource(bingPayload, customToast));
} else {
const payload = {
connection_type: selectedDatasource.value,
Expand All @@ -427,7 +427,7 @@ const DataSourceForm = ({ onboarding, setModal, setText }) => {
sourceDefinitionId: sourceDefinitionId
}
};
dispatch(createDataSource(payload));
dispatch(createDataSource(payload, customToast));
}
}
};
Expand Down Expand Up @@ -469,7 +469,7 @@ const DataSourceForm = ({ onboarding, setModal, setText }) => {
connectionConfiguration: editedForm
}
};
dispatch(updateDatasourceById(dsId, payload));
dispatch(updateDatasourceById(dsId, payload, customToast));
}
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/DataSourceTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const DataSourceTable = ({ tableData, changeData, search }) => {
const payload = {
data_source_id: datasource.id
};
dispatch(deleteDatasource(payload));
dispatch(deleteDatasource(payload, customToast));
};

const datasourceIcon = (type) => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/EventAlertDestinationForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ const EventAlertDestinationForm = ({
setError(obj);
if (error.alert_channel === '') {
if (path[2] === 'edit') {
dispatch(updateKpiAlert(kpiId, alertFormData));
dispatch(updateKpiAlert(kpiId, alertFormData, customToast));
} else {
dispatch(createKpiAlert(alertFormData));
dispatch(createKpiAlert(alertFormData, customToast));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/KPITable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const KPITable = ({ kpiData, kpiLoading, kpiSearch, changeData }) => {
};

const onDelete = (kpi) => {
dispatch(kpiDisable(kpi.id));
dispatch(kpiDisable(kpi.id, customToast));
};

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/KpiAlertDestinationForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ const KpiAlertDestinationForm = ({
setError(obj);
if (obj.alert_channel === '') {
if (path[2] === 'edit') {
dispatch(updateKpiAlert(kpiId, alertFormData));
dispatch(updateKpiAlert(kpiId, alertFormData, customToast));
} else {
dispatch(createKpiAlert(alertFormData));
dispatch(createKpiAlert(alertFormData, customToast));
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/KpiExplorerForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,15 @@ const KpiExplorerForm = ({ onboarding, setModal, setText }) => {
};

if (data[2] === 'edit' && present) {
dispatch(getUpdatekpi(kpiId, editedFormData));
dispatch(getUpdatekpi(kpiId, editedFormData, customToast));
} else if (data[2] !== 'edit') {
dispatchgetAllKpiExplorerSubmit(kpiInfo);
}
}
};

const dispatchgetAllKpiExplorerSubmit = (kpiInfo) => {
dispatch(getAllKpiExplorerSubmit(kpiInfo));
dispatch(getAllKpiExplorerSubmit(kpiInfo, customToast));
};

const onTestQuery = () => {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/containers/Alerts/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ const Alerts = () => {
</div>
{/* table section */}
<div className="table-section">
<AlertTable alertData={alertData} alertSearch={alertSearch} />
<AlertTable
alertData={alertData}
alertSearch={alertSearch}
customToast={customToast}
/>
</div>
</div>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ const ReportSettings = () => {
};

const onReportSettingsSave = (e) => {
dispatch(saveReportSettingTime(moment(schedule, 'HH:mm')?.format('HH:mm')));
dispatch(
saveReportSettingTime(
moment(schedule, 'HH:mm')?.format('HH:mm'),
customToast
)
);
};

return (
Expand Down
Loading