mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
update metrics data in ui
This commit is contained in:
parent
22da36158c
commit
8f90989ce6
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const Projection = require('./projection.js');
|
const Projection = require('./projection.js');
|
||||||
const TTLList = require('./ttl-list.js');
|
const TTLList = require('./ttl-list.js');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
module.exports = class UnleashClientMetrics {
|
module.exports = class UnleashClientMetrics {
|
||||||
constructor () {
|
constructor () {
|
||||||
@ -10,11 +11,26 @@ module.exports = class UnleashClientMetrics {
|
|||||||
this.clients = {};
|
this.clients = {};
|
||||||
this.buckets = {};
|
this.buckets = {};
|
||||||
|
|
||||||
this.hourProjectionValue = new Projection();
|
this.lastHourProjection = new Projection();
|
||||||
this.oneHourLruCache = new TTLList();
|
this.lastMinuteProjection = new Projection();
|
||||||
this.oneHourLruCache.on('expire', (toggles) => {
|
|
||||||
|
this.lastHourList = new TTLList({
|
||||||
|
interval: 10000,
|
||||||
|
});
|
||||||
|
this.lastMinuteList = new TTLList({
|
||||||
|
interval: 10000,
|
||||||
|
expireType: 'minutes',
|
||||||
|
expireAmount: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.lastHourList.on('expire', (toggles) => {
|
||||||
Object.keys(toggles).forEach(toggleName => {
|
Object.keys(toggles).forEach(toggleName => {
|
||||||
this.hourProjectionValue.substract(toggleName, toggles[toggleName]);
|
this.lastHourProjection.substract(toggleName, toggles[toggleName]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.lastMinuteList.on('expire', (toggles) => {
|
||||||
|
Object.keys(toggles).forEach(toggleName => {
|
||||||
|
this.lastMinuteProjection.substract(toggleName, toggles[toggleName]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -32,7 +48,10 @@ module.exports = class UnleashClientMetrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTogglesMetrics () {
|
getTogglesMetrics () {
|
||||||
return this.hourProjectionValue.getProjection();
|
return {
|
||||||
|
lastHour: this.lastHourProjection.getProjection(),
|
||||||
|
lastMinute: this.lastMinuteProjection.getProjection(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
addPayload (data) {
|
addPayload (data) {
|
||||||
@ -47,11 +66,13 @@ module.exports = class UnleashClientMetrics {
|
|||||||
|
|
||||||
Object.keys(toggles).forEach((n) => {
|
Object.keys(toggles).forEach((n) => {
|
||||||
const entry = toggles[n];
|
const entry = toggles[n];
|
||||||
this.hourProjectionValue.add(n, entry);
|
this.lastHourProjection.add(n, entry);
|
||||||
|
this.lastMinuteProjection.add(n, entry);
|
||||||
count += (entry.yes + entry.no);
|
count += (entry.yes + entry.no);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.oneHourLruCache.add(toggles, stop);
|
this.lastHourList.add(toggles, stop);
|
||||||
|
this.lastMinuteList.add(toggles, stop);
|
||||||
|
|
||||||
this.addClientCount(appName, instanceId, count);
|
this.addClientCount(appName, instanceId, count);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,13 @@ import Chip from 'react-toolbox/lib/chip';
|
|||||||
|
|
||||||
import style from './feature.scss';
|
import style from './feature.scss';
|
||||||
|
|
||||||
const Feature = ({ feature, onFeatureClick, onFeatureRemove, metrics = { yes: 0, no: 0, hasData: false } }) => {
|
const Feature = ({
|
||||||
|
feature,
|
||||||
|
onFeatureClick,
|
||||||
|
onFeatureRemove,
|
||||||
|
metricsLastHour = { yes: 0, no: 0, hasData: false },
|
||||||
|
metricsLastMinute = { yes: 0, no: 0, hasData: false },
|
||||||
|
}) => {
|
||||||
const { name, description, enabled, strategies, createdAt } = feature;
|
const { name, description, enabled, strategies, createdAt } = feature;
|
||||||
const created = new Date(createdAt);
|
const created = new Date(createdAt);
|
||||||
|
|
||||||
@ -22,7 +28,8 @@ const Feature = ({ feature, onFeatureClick, onFeatureRemove, metrics = { yes: 0,
|
|||||||
];
|
];
|
||||||
|
|
||||||
const leftActions = [
|
const leftActions = [
|
||||||
<Chip><span className={style.yes}>{metrics.yes}</span> / <span className={style.no}>{metrics.no}</span></Chip>,
|
<Chip><span className={style.yes}>{metricsLastHour.yes}</span> / <span className={style.no}>{metricsLastHour.no}</span></Chip>,
|
||||||
|
<Chip><span className={style.yes}>{metricsLastMinute.yes}</span> / <span className={style.no}>{metricsLastMinute.no}</span></Chip>,
|
||||||
<Switch key="left-actions" onChange={() => onFeatureClick(feature)} checked={enabled} />,
|
<Switch key="left-actions" onChange={() => onFeatureClick(feature)} checked={enabled} />,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -38,8 +38,12 @@ export default class FeatureListComponent extends React.Component {
|
|||||||
<List>
|
<List>
|
||||||
<ListSubHeader caption="Feature toggles" />
|
<ListSubHeader caption="Feature toggles" />
|
||||||
{features.map((feature, i) =>
|
{features.map((feature, i) =>
|
||||||
<Feature key={i} metrics={featureMetrics[feature.name]} feature={feature}
|
<Feature key={i}
|
||||||
onFeatureClick={onFeatureClick} onFeatureRemove={onFeatureRemove}/>
|
metricsLastHour={featureMetrics.lastHour[feature.name]}
|
||||||
|
metricsLastMinute={featureMetrics.lastMinute[feature.name]}
|
||||||
|
feature={feature}
|
||||||
|
onFeatureClick={onFeatureClick}
|
||||||
|
onFeatureRemove={onFeatureRemove}/>
|
||||||
)}
|
)}
|
||||||
<ListDivider />
|
<ListDivider />
|
||||||
<ListItem
|
<ListItem
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import { Map as $Map } from 'immutable';
|
import { Map as $Map, fromJS } from 'immutable';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
RECEIVE_FEATURE_METRICS,
|
RECEIVE_FEATURE_METRICS,
|
||||||
} from './feature-metrics-actions';
|
} from './feature-metrics-actions';
|
||||||
|
|
||||||
|
|
||||||
const metrics = (state = new $Map(), action) => {
|
const metrics = (state = fromJS({ lastHour: {}, lastMinute: {} }), action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case RECEIVE_FEATURE_METRICS:
|
case RECEIVE_FEATURE_METRICS:
|
||||||
return new $Map(action.metrics);
|
return state.withMutations((ctx) => {
|
||||||
|
ctx.set('lastHour', new $Map(action.metrics.lastHour));
|
||||||
|
ctx.set('lastMinute', new $Map(action.metrics.lastMinute));
|
||||||
|
return ctx;
|
||||||
|
});
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user