Welcome to mirror list, hosted at ThFree Co, Russian Federation.

validators.js « monitoring « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05a9d8b9db5c76de1e16e2c3f204923b20ce6558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { isSafeURL } from '~/lib/utils/url_utility';

const isRunbookUrlValid = (runbookUrl) => {
  if (!runbookUrl) {
    return true;
  }
  return isSafeURL(runbookUrl);
};

// 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)",
//     runbookUrl: "https://www.gitlab.com/my-project/-/wikis/runbook"
//   }
// }
export function alertsValidator(value) {
  return Object.keys(value).every((key) => {
    const alert = value[key];
    return (
      alert.alert_path &&
      key === alert.alert_path &&
      alert.metricId &&
      typeof alert.metricId === 'string' &&
      alert.operator &&
      typeof alert.threshold === 'number' &&
      isRunbookUrlValid(alert.runbookUrl)
    );
  });
}

// 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(
    (query) =>
      query.metricId && typeof query.metricId === 'string' && typeof query.label === 'string',
  );
}