This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.tsx
68 lines (64 loc) · 2.01 KB
/
index.tsx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
import { CanaryMetricSetQueryConfig } from '../domain/Kayenta';
import { MetricSourceIntegration } from './MetricSourceIntegration';
import NewRelic from './NewRelic';
import SignalFx from './SignalFx';
import Prometheus from './Prometheus';
import Datadog from './Datadog';
const MIN_TO_MS_CONVERSION: number = 60000;
/**
* The list of enabled metric source integrations
*/
// prettier-ignore
const enabledMetricSources: MetricSourceIntegration<CanaryMetricSetQueryConfig>[] = [
NewRelic,
SignalFx,
Prometheus,
Datadog
];
/**
* A Map of metric source integration types to metric source integrations
*/
// prettier-ignore
export const metricSourceIntegrations: () => KvMap<MetricSourceIntegration<CanaryMetricSetQueryConfig>> = () => {
return enabledMetricSources.reduce((result, metricsSource) => {
result[metricsSource.type] = metricsSource;
return result;
},
{} as KvMap<MetricSourceIntegration<CanaryMetricSetQueryConfig>>
);
};
/**
* The list of metric source types
*/
export const metricSourceTypes: () => string[] = () => {
return enabledMetricSources.map(metricSourceIntegration => metricSourceIntegration.type);
};
/**
* Calculates time labels for metric graphs based on start, length of canary, and number of data points
*/
export const defaultGraphDataMapper = (
lifetime: number,
dataPointCount: number,
startTimeMillis: number,
stepMillis: number
): {
controlTimeLabels: number[];
experimentTimeLabels?: number[];
} => {
let controlTimeLabels: number[] = [];
let scale: number;
const lifetimeMillis: number = lifetime * MIN_TO_MS_CONVERSION;
if (lifetime > 0 && dataPointCount > 0) {
scale = Math.round(lifetimeMillis / dataPointCount);
} else {
scale = stepMillis;
}
for (let i = 0, j = startTimeMillis; i < dataPointCount; i++, j += scale) {
controlTimeLabels.push(j);
}
if (controlTimeLabels.length === 0) {
controlTimeLabels.push(startTimeMillis);
controlTimeLabels.push(startTimeMillis + lifetimeMillis);
}
return { controlTimeLabels };
};