1export interface Labels {
2  [key: string]: string;
3}
4
5export interface Target {
6  discoveredLabels: Labels;
7  labels: Labels;
8  scrapePool: string;
9  scrapeUrl: string;
10  globalUrl: string;
11  lastError: string;
12  lastScrape: string;
13  lastScrapeDuration: number;
14  health: string;
15  scrapeInterval: string;
16  scrapeTimeout: string;
17}
18
19export interface DroppedTarget {
20  discoveredLabels: Labels;
21}
22
23export interface ScrapePool {
24  upCount: number;
25  targets: Target[];
26}
27
28export interface ScrapePools {
29  [scrapePool: string]: ScrapePool;
30}
31
32export const groupTargets = (targets: Target[]): ScrapePools =>
33  targets.reduce((pools: ScrapePools, target: Target) => {
34    const { health, scrapePool } = target;
35    const up = health.toLowerCase() === 'up' ? 1 : 0;
36    if (!pools[scrapePool]) {
37      pools[scrapePool] = {
38        upCount: 0,
39        targets: [],
40      };
41    }
42    pools[scrapePool].targets.push(target);
43    pools[scrapePool].upCount += up;
44    return pools;
45  }, {});
46
47export const getColor = (health: string): string => {
48  switch (health.toLowerCase()) {
49    case 'up':
50      return 'success';
51    case 'down':
52      return 'danger';
53    default:
54      return 'warning';
55  }
56};
57