Harkishen Singh 489a9aa7b9
Adds normalization of localhost urls in targets page react (#6794)
* support for globalurls in targets page react

Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>

* fixed tests

Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>

* removed fmts

Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>

* implemented suggestions

Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>

* formatted

Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>

* implemented suggestions. fixed tests.

Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>

* formated go code

Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>

* implemented suggestions

Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
2020-02-17 18:19:15 +01:00

55 lines
1.1 KiB
TypeScript

export interface Labels {
[key: string]: string;
}
export interface Target {
discoveredLabels: Labels;
labels: Labels;
scrapePool: string;
scrapeUrl: string;
globalUrl: string;
lastError: string;
lastScrape: string;
lastScrapeDuration: number;
health: string;
}
export interface DroppedTarget {
discoveredLabels: Labels;
}
export interface ScrapePool {
upCount: number;
targets: Target[];
}
export interface ScrapePools {
[scrapePool: string]: ScrapePool;
}
export const groupTargets = (targets: Target[]): ScrapePools =>
targets.reduce((pools: ScrapePools, target: Target) => {
const { health, scrapePool } = target;
const up = health.toLowerCase() === 'up' ? 1 : 0;
if (!pools[scrapePool]) {
pools[scrapePool] = {
upCount: 0,
targets: [],
};
}
pools[scrapePool].targets.push(target);
pools[scrapePool].upCount += up;
return pools;
}, {});
export const getColor = (health: string): string => {
switch (health.toLowerCase()) {
case 'up':
return 'success';
case 'down':
return 'danger';
default:
return 'warning';
}
};