2020-08-12 02:09:53 -04:00
|
|
|
import { isSafeURL } from '~/lib/utils/url_utility';
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
const isRunbookUrlValid = (runbookUrl) => {
|
2020-08-12 02:09:53 -04:00
|
|
|
if (!runbookUrl) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isSafeURL(runbookUrl);
|
|
|
|
};
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
// Prop validator for alert information, expecting an object like the example below.
|
|
|
|
//
|
|
|
|
// {
|
|
|
|
// '/root/autodevops-deploy/prometheus/alerts/16.json?environment_id=37': {
|
|
|
|
// alert_path: "/root/autodevops-deploy/prometheus/alerts/16.json?environment_id=37",
|
|
|
|
// metricId: '1',
|
|
|
|
// operator: ">",
|
|
|
|
// query: "rate(http_requests_total[5m])[30m:1m]",
|
|
|
|
// threshold: 0.002,
|
|
|
|
// title: "Core Usage (Total)",
|
2020-08-12 02:09:53 -04:00
|
|
|
// runbookUrl: "https://www.gitlab.com/my-project/-/wikis/runbook"
|
2020-04-21 11:21:10 -04:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
export function alertsValidator(value) {
|
2020-12-23 16:10:24 -05:00
|
|
|
return Object.keys(value).every((key) => {
|
2020-04-21 11:21:10 -04:00
|
|
|
const alert = value[key];
|
|
|
|
return (
|
|
|
|
alert.alert_path &&
|
|
|
|
key === alert.alert_path &&
|
|
|
|
alert.metricId &&
|
|
|
|
typeof alert.metricId === 'string' &&
|
|
|
|
alert.operator &&
|
2020-08-12 02:09:53 -04:00
|
|
|
typeof alert.threshold === 'number' &&
|
|
|
|
isRunbookUrlValid(alert.runbookUrl)
|
2020-04-21 11:21:10 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prop validator for query information, expecting an array like the example below.
|
|
|
|
//
|
|
|
|
// [
|
|
|
|
// {
|
|
|
|
// metricId: '16',
|
|
|
|
// label: 'Total Cores'
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// metricId: '17',
|
|
|
|
// label: 'Sub-total Cores'
|
|
|
|
// }
|
|
|
|
// ]
|
|
|
|
export function queriesValidator(value) {
|
|
|
|
return value.every(
|
2020-12-23 16:10:24 -05:00
|
|
|
(query) =>
|
2020-04-21 11:21:10 -04:00
|
|
|
query.metricId && typeof query.metricId === 'string' && typeof query.label === 'string',
|
|
|
|
);
|
|
|
|
}
|