1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-15 07:40:07 +02:00
copilot/frontend/src/index.js

121 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-02-24 14:13:10 +02:00
import { IntlProvider } from 'react-intl-redux';
import { Provider } from 'react-redux';
import qs from 'querystring';
import a11y from 'react-a11y';
import ReactDOM from 'react-dom';
import React from 'react';
import Perf from 'react-addons-perf';
2017-02-24 14:13:10 +02:00
import MockStateTesting from '@mock-states/testing';
import MockState from '@mock-states';
2017-03-21 13:11:36 +02:00
import LeakDatasets from './dataset-leak.json';
import NormalDatasets from './dataset-normal.json';
2017-02-24 14:13:10 +02:00
import Store from '@state/store';
import { isProduction } from '@utils';
import Router from '@root/routing';
2016-10-20 04:14:26 +03:00
if ( !isProduction() ) {
2016-10-25 22:36:05 +03:00
a11y(React, {
ReactDOM
});
window.Perf = Perf;
2016-10-25 22:36:05 +03:00
}
2017-03-22 16:41:53 +02:00
const states = {
all: MockState,
testing: MockStateTesting
2017-03-22 19:10:10 +02:00
};
2017-03-22 16:41:53 +02:00
const query = qs.parse(window.location.search.replace(/^\?/, ''));
const mockState = states[query.mock || 'all'];
2017-03-20 21:46:44 +02:00
// node_memory_rss_bytes
// node_memory_heap_total_bytes
// node_memory_heap_used_bytes
// process_heap_bytes
// process_resident_memory_bytes
// process_virtual_memory_bytes
// process_cpu_seconds_total
// process_cpu_system_seconds_total
// process_cpu_user_seconds_total
// node_lag_duration_milliseconds
// http_request_duration_milliseconds
// node_memory_rss_bytes
// node_memory_heap_total_bytes
// node_memory_heap_used_bytes
// process_heap_bytes
// process_resident_memory_bytes
// process_virtual_memory_bytes
// process_cpu_seconds_total
// process_cpu_system_seconds_total
// process_cpu_user_seconds_total
// node_lag_duration_milliseconds
// http_request_duration_milliseconds
2017-03-20 19:43:26 +02:00
2017-03-17 21:27:15 +02:00
// TMP - ensure datasets are at least 2 hrs long - START
import getTwoHourDatasets from './utils/two-hour-metric-datasets';
2017-03-20 21:46:44 +02:00
const leakTwoHourLongDatasets = getTwoHourDatasets(LeakDatasets);
const normalTwoHourLongDatasets = getTwoHourDatasets(NormalDatasets);
2017-03-17 21:27:15 +02:00
// TMP - ensure datasets are at least 2 hrs long - END
// TMP - plug fake metric data - START
2017-03-20 21:46:44 +02:00
const isCrazy = (uuid) => uuid === 'crazy-cpu' ||
uuid === 'crazy-disk' || uuid === 'crazy-memory';
const isCPU = (uuid) => uuid === 'crazy-cpu'
|| uuid === '3e6ee79a-7453-4fc6-b9da-7ae1e41138ec';
const isDisk = (uuid) => uuid === 'crazy-disk'
|| uuid === '4e6ee79a-7453-4fc6-b9da-7ae1e41138ed';
const isMemory = (uuid) => uuid === 'crazy-memory'
|| uuid === '6e6ee79a-7453-4fc6-b9da-7ae1e41138ed';
const getDataset = (twoHourLongDatasets, uuid) => {
if(isCPU(uuid)) {
return twoHourLongDatasets.process_cpu_seconds_total;
}
if(isDisk(uuid)) {
return twoHourLongDatasets.process_heap_bytes.map((sample) =>
[
sample[0],
sample[1]/1024/1024
]
);
2017-03-20 21:46:44 +02:00
}
if(isMemory(uuid)) {
return twoHourLongDatasets.node_memory_heap_used_bytes.map((sample) =>
[
sample[0],
sample[1]/1024/1024
]
);
2017-03-20 21:46:44 +02:00
}
};
const datasets = MockState.metrics.data.datasets.map((dataset, index) => {
const data = isCrazy(dataset.uuid) && dataset.uuid !== 'crazy-cpu' ?
2017-03-20 21:46:44 +02:00
getDataset(leakTwoHourLongDatasets, dataset.uuid) :
getDataset(normalTwoHourLongDatasets, dataset.uuid);
2017-03-17 21:27:15 +02:00
return {
...dataset,
2017-03-20 21:46:44 +02:00
data: data
2017-03-17 21:27:15 +02:00
};
});
2017-03-20 19:43:26 +02:00
mockState.metrics.data.datasets = datasets;
2017-03-17 21:27:15 +02:00
// TMP - plug fake metric data - END
ReactDOM.render(
2017-03-20 19:43:26 +02:00
<Provider store={Store(mockState)}>
2017-02-24 14:13:10 +02:00
<IntlProvider>
{Router}
2017-02-24 14:13:10 +02:00
</IntlProvider>
</Provider>,
document.getElementById('root')
);