mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
some cleanup
This commit is contained in:
parent
ade8df4946
commit
f89535f359
@ -8,7 +8,7 @@ module.exports = class UnleashClientMetrics extends EventEmitter {
|
||||
super();
|
||||
this.db = metricsDb;
|
||||
this.highestIdSeen = 0;
|
||||
this.db.getMetricsLastWeek().then(metrics => {
|
||||
this.db.getMetricsLastHour().then(metrics => {
|
||||
this.addMetrics(metrics);
|
||||
this.startPoller();
|
||||
});
|
||||
|
@ -10,12 +10,12 @@ module.exports = function (db) {
|
||||
}
|
||||
|
||||
// Used at startup to load all metrics last week into memory!
|
||||
function getMetricsLastWeek () {
|
||||
function getMetricsLastHour () {
|
||||
return db
|
||||
.select(METRICS_COLUMNS)
|
||||
.from(TABLE)
|
||||
.limit(2000)
|
||||
.whereRaw('created_at > now() - interval \'7 day\'')
|
||||
.whereRaw('created_at > now() - interval \'1 hour\'')
|
||||
.orderBy('created_at', 'asc')
|
||||
.map(mapRow);
|
||||
}
|
||||
@ -39,5 +39,5 @@ module.exports = function (db) {
|
||||
};
|
||||
}
|
||||
|
||||
return { insert, getMetricsLastWeek, getNewMetrics };
|
||||
return { insert, getMetricsLastHour, getNewMetrics };
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ export default class UnleashNav extends Component {
|
||||
{createListItem('/history', 'Event history')}
|
||||
{createListItem('/archive', 'Archived toggles')}
|
||||
{createListItem('/metrics', 'Client metrics')}
|
||||
{createListItem('/Clients', 'Client strategies')}
|
||||
{createListItem('/client-strategies', 'Client strategies')}
|
||||
|
||||
<ListDivider />
|
||||
|
||||
|
@ -1,19 +1,7 @@
|
||||
import { throwIfNotSuccess, headers } from './helper';
|
||||
|
||||
const URI = '/archive';
|
||||
|
||||
const headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
function throwIfNotSuccess (response) {
|
||||
if (!response.ok) {
|
||||
let error = new Error('API call failed');
|
||||
error.status = response.status;
|
||||
throw error;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
function fetchAll () {
|
||||
return fetch(`${URI}/features`)
|
||||
.then(throwIfNotSuccess)
|
||||
|
@ -1,16 +1,9 @@
|
||||
import { throwIfNotSuccess, headers } from './helper';
|
||||
|
||||
const URI = '/client/strategies';
|
||||
|
||||
function throwIfNotSuccess (response) {
|
||||
if (!response.ok) {
|
||||
let error = new Error('API call failed');
|
||||
error.status = response.status;
|
||||
throw error;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
function fetchAll () {
|
||||
return fetch(URI)
|
||||
return fetch(URI, { headers })
|
||||
.then(throwIfNotSuccess)
|
||||
.then(response => response.json());
|
||||
}
|
||||
|
38
packages/unleash-frontend-next/src/data/feature-api.js
Normal file
38
packages/unleash-frontend-next/src/data/feature-api.js
Normal file
@ -0,0 +1,38 @@
|
||||
import { throwIfNotSuccess, headers } from './helper';
|
||||
|
||||
const URI = '/features';
|
||||
|
||||
function fetchAll () {
|
||||
return fetch(URI)
|
||||
.then(throwIfNotSuccess)
|
||||
.then(response => response.json());
|
||||
}
|
||||
|
||||
function create (featureToggle) {
|
||||
return fetch(URI, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(featureToggle),
|
||||
}).then(throwIfNotSuccess);
|
||||
}
|
||||
|
||||
function update (featureToggle) {
|
||||
return fetch(`${URI}/${featureToggle.name}`, {
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: JSON.stringify(featureToggle),
|
||||
}).then(throwIfNotSuccess);
|
||||
}
|
||||
|
||||
function remove (featureToggleName) {
|
||||
return fetch(`${URI}/${featureToggleName}`, {
|
||||
method: 'DELETE',
|
||||
}).then(throwIfNotSuccess);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchAll,
|
||||
create,
|
||||
update,
|
||||
remove,
|
||||
};
|
25
packages/unleash-frontend-next/src/data/helper.js
Normal file
25
packages/unleash-frontend-next/src/data/helper.js
Normal file
@ -0,0 +1,25 @@
|
||||
const defaultErrorMessage = 'Unexptected exception when talking to unleash-api';
|
||||
|
||||
export function throwIfNotSuccess (response) {
|
||||
if (!response.ok) {
|
||||
if (response.status > 400 && response.status < 404) {
|
||||
return new Promise((resolve, reject) => {
|
||||
response.json().then(body => {
|
||||
const errorMsg = body && body.length > 0 ? body[0].msg : defaultErrorMessage;
|
||||
let error = new Error(errorMsg);
|
||||
error.statusCode = response.status;
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return Promise.reject(new Error(defaultErrorMessage));
|
||||
}
|
||||
}
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
|
||||
|
||||
export const headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
@ -1,13 +1,6 @@
|
||||
const URI = '/events';
|
||||
import { throwIfNotSuccess } from './helper';
|
||||
|
||||
function throwIfNotSuccess (response) {
|
||||
if (!response.ok) {
|
||||
let error = new Error('API call failed');
|
||||
error.status = response.status;
|
||||
throw error;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
const URI = '/events';
|
||||
|
||||
function fetchAll () {
|
||||
return fetch(URI)
|
||||
|
@ -1,13 +1,6 @@
|
||||
const URI = '/metrics';
|
||||
import { throwIfNotSuccess } from './helper';
|
||||
|
||||
function throwIfNotSuccess (response) {
|
||||
if (!response.ok) {
|
||||
let error = new Error('API call failed');
|
||||
error.status = response.status;
|
||||
throw error;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
const URI = '/metrics';
|
||||
|
||||
function fetchAll () {
|
||||
return fetch(URI)
|
||||
|
@ -1,19 +1,7 @@
|
||||
import { throwIfNotSuccess, headers } from './helper';
|
||||
|
||||
const URI = '/strategies';
|
||||
|
||||
const headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
function throwIfNotSuccess (response) {
|
||||
if (!response.ok) {
|
||||
let error = new Error('API call failed');
|
||||
error.status = response.status;
|
||||
throw error;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
function fetchAll () {
|
||||
return fetch(URI)
|
||||
.then(throwIfNotSuccess)
|
||||
|
@ -16,7 +16,7 @@ import CreateStrategies from './page/strategies/create';
|
||||
import HistoryPage from './page/history';
|
||||
import Archive from './page/archive';
|
||||
import Metrics from './page/metrics';
|
||||
import Clients from './page/clients';
|
||||
import ClientStrategies from './page/client-strategies';
|
||||
|
||||
const unleashStore = createStore(
|
||||
store,
|
||||
@ -38,7 +38,7 @@ ReactDOM.render(
|
||||
<Route path="/history" component={HistoryPage} />
|
||||
<Route path="/archive" component={Archive} />
|
||||
<Route path="/metrics" component={Metrics} />
|
||||
<Route path="/clients" component={Clients} />
|
||||
<Route path="/client-strategies" component={ClientStrategies} />
|
||||
</Route>
|
||||
</Router>
|
||||
</Provider>, document.getElementById('app'));
|
||||
|
@ -1,4 +1,4 @@
|
||||
import api from './feature-api';
|
||||
import api from '../data/feature-api';
|
||||
const debug = require('debug')('unleash:feature-actions');
|
||||
|
||||
export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE';
|
||||
|
@ -1,61 +0,0 @@
|
||||
const URI = '/features';
|
||||
|
||||
const headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
const defaultErrorMessage = 'Unexptected exception when talking to unleash-api';
|
||||
|
||||
function throwIfNotSuccess (response) {
|
||||
if (!response.ok) {
|
||||
if (response.status > 400 && response.status < 404) {
|
||||
return new Promise((resolve, reject) => {
|
||||
response.json().then(body => {
|
||||
const errorMsg = body && body.length > 0 ? body[0].msg : defaultErrorMessage;
|
||||
let error = new Error(errorMsg);
|
||||
error.statusCode = response.status;
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return Promise.reject(new Error(defaultErrorMessage));
|
||||
}
|
||||
}
|
||||
return Promise.resolve(response);
|
||||
}
|
||||
|
||||
function fetchAll () {
|
||||
return fetch(URI)
|
||||
.then(throwIfNotSuccess)
|
||||
.then(response => response.json());
|
||||
}
|
||||
|
||||
function create (featureToggle) {
|
||||
return fetch(URI, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(featureToggle),
|
||||
}).then(throwIfNotSuccess);
|
||||
}
|
||||
|
||||
function update (featureToggle) {
|
||||
return fetch(`${URI}/${featureToggle.name}`, {
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: JSON.stringify(featureToggle),
|
||||
}).then(throwIfNotSuccess);
|
||||
}
|
||||
|
||||
function remove (featureToggleName) {
|
||||
return fetch(`${URI}/${featureToggleName}`, {
|
||||
method: 'DELETE',
|
||||
}).then(throwIfNotSuccess);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetchAll,
|
||||
create,
|
||||
update,
|
||||
remove,
|
||||
};
|
Loading…
Reference in New Issue
Block a user