Skip to content

Commit

Permalink
Changing from rate to growth_rate; adding message to aggregation form;
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Apr 2, 2020
1 parent fcb6827 commit e1cea8e
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ const metricAggs = [
}),
value: 'filter_ratio',
},
{
label: i18n.translate('visTypeTimeseries.aggSelect.metricsAggs.growthRateLabel', {
defaultMessage: 'Growth Rate',
}),
value: 'growth_rate',
},
{
label: i18n.translate('visTypeTimeseries.aggSelect.metricsAggs.maxLabel', {
defaultMessage: 'Max',
Expand Down Expand Up @@ -115,12 +121,6 @@ const metricAggs = [
}),
value: 'variance',
},
{
label: i18n.translate('visTypeTimeseries.aggSelect.metricsAggs.rateLabel', {
defaultMessage: 'Rate',
}),
value: 'rate',
},
];

const pipelineAggs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import {
EuiFieldText,
EuiFormRow,
EuiSpacer,
EuiText,
EuiLink,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { KBN_FIELD_TYPES } from '../../../../../../plugins/data/public';

export const RateAgg = props => {
export const GrowthRateAgg = props => {
const defaults = { unit: '' };
const model = { ...defaults, ...props.model };

Expand All @@ -63,7 +65,7 @@ export const RateAgg = props => {
<EuiFlexItem>
<EuiFormLabel htmlFor={htmlId('aggregation')}>
<FormattedMessage
id="visTypeTimeseries.rate.aggregationLabel"
id="visTypeTimeseries.growthRate.aggregationLabel"
defaultMessage="Aggregation"
/>
</EuiFormLabel>
Expand All @@ -81,7 +83,10 @@ export const RateAgg = props => {
<EuiFormRow
id={htmlId('field')}
label={
<FormattedMessage id="visTypeTimeseries.rate.fieldLabel" defaultMessage="Field" />
<FormattedMessage
id="visTypeTimeseries.growthRate.fieldLabel"
defaultMessage="Field"
/>
}
fullWidth
>
Expand All @@ -102,7 +107,7 @@ export const RateAgg = props => {
id={htmlId('units')}
label={
<FormattedMessage
id="visTypeTimeseries.rate.unitsLabel"
id="visTypeTimeseries.growthRate.unitsLabel"
defaultMessage="Units (1s, 1m, etc)"
description="1s and 1m are required values and must not be translated."
/>
Expand All @@ -113,11 +118,30 @@ export const RateAgg = props => {
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="s" />
<EuiText size="xs" color="subdued">
<p>
<FormattedMessage
id="visTypeTimeseries.growthRate.helpText"
defaultMessage="This aggregation should only be applied to {link}, it is a shortcut for applying max, derivative and positive only to a field."
values={{
link: (
<EuiLink href="https://en.wikipedia.org/wiki/Monotonic_function" target="_BLANK">
<FormattedMessage
id="visTypeTimeseries.growthRate.helpTextLink"
defaultMessage="monotonically increasing numbers"
/>
</EuiLink>
),
}}
/>
</p>
</EuiText>
</AggRow>
);
};

RateAgg.propTypes = {
GrowthRateAgg.propTypes = {
disableDelete: PropTypes.bool,
fields: PropTypes.object,
model: PropTypes.object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { PercentileRankAgg } from '../aggs/percentile_rank';
import { Static } from '../aggs/static';
import { MathAgg } from '../aggs/math';
import { TopHitAgg } from '../aggs/top_hit';
import { RateAgg } from '../aggs/rate';
import { GrowthRateAgg } from '../aggs/growth_rate';

export const aggToComponent = {
count: StandardAgg,
Expand Down Expand Up @@ -66,5 +66,5 @@ export const aggToComponent = {
static: Static,
math: MathAgg,
top_hit: TopHitAgg,
rate: RateAgg,
growth_rate: GrowthRateAgg,
};
4 changes: 3 additions & 1 deletion src/plugins/vis_type_timeseries/common/agg_lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export const lookup = {
defaultMessage: 'Static Value',
}),
top_hit: i18n.translate('visTypeTimeseries.aggLookup.topHitLabel', { defaultMessage: 'Top Hit' }),
rate: i18n.translate('visTypeTimeseries.aggLookup.rateLabel', { defaultMessage: 'Rate' }),
growth_rate: i18n.translate('visTypeTimeseries.aggLookup.growthRateLabel', {
defaultMessage: 'Growth Rate',
}),
};

const pipeline = [
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/vis_type_timeseries/common/calculate_label.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ export function calculateLabel(metric, metrics) {
defaultMessage: 'Filter Ratio',
});
}
if (metric.type === 'rate') {
return i18n.translate('visTypeTimeseries.calculateLabel.rateLabel', {
defaultMessage: 'Rate',
if (metric.type === 'growth_rate') {
return i18n.translate('visTypeTimeseries.calculateLabel.growthRateLabel', {
defaultMessage: 'Growth Rate of {field}',
values: { field: metric.field },
});
}
if (metric.type === 'static') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ import { getIntervalAndTimefield } from '../../get_interval_and_timefield';
import { bucketTransform } from '../../helpers/bucket_transform';
import { set } from 'lodash';

export const filter = metric => metric.type === 'rate';
export const filter = metric => metric.type === 'growth_rate';

export const createRate = (doc, intervalString, aggRoot) => metric => {
export const createGrowthRate = (doc, intervalString, aggRoot) => metric => {
const maxFn = bucketTransform.max;
const derivativeFn = bucketTransform.derivative;
const positiveOnlyFn = bucketTransform.positive_only;

const maxMetric = { id: `${metric.id}-rate-max`, type: 'max', field: metric.field };
const maxMetric = { id: `${metric.id}-growth-rate-max`, type: 'max', field: metric.field };
const derivativeMetric = {
id: `${metric.id}-rate-derivative`,
id: `${metric.id}-growth-rate-derivative`,
type: 'derivative',
field: `${metric.id}-rate-max`,
field: `${metric.id}-growth-rate-max`,
unit: metric.unit,
};
const positiveOnlyMetric = {
id: metric.id,
type: 'positive_only',
field: `${metric.id}-rate-derivative`,
field: `${metric.id}-growth-rate-derivative`,
};

const fakeSeriesMetrics = [maxMetric, derivativeMetric, positiveOnlyMetric];
Expand All @@ -48,19 +48,19 @@ export const createRate = (doc, intervalString, aggRoot) => metric => {
const derivativeBucket = derivativeFn(derivativeMetric, fakeSeriesMetrics, intervalString);
const positiveOnlyBucket = positiveOnlyFn(positiveOnlyMetric, fakeSeriesMetrics, intervalString);

set(doc, `${aggRoot}.timeseries.aggs.${metric.id}-rate-max`, maxBucket);
set(doc, `${aggRoot}.timeseries.aggs.${metric.id}-rate-derivative`, derivativeBucket);
set(doc, `${aggRoot}.timeseries.aggs.${metric.id}-growth-rate-max`, maxBucket);
set(doc, `${aggRoot}.timeseries.aggs.${metric.id}-growth-rate-derivative`, derivativeBucket);
set(doc, `${aggRoot}.timeseries.aggs.${metric.id}`, positiveOnlyBucket);
};

export function rate(req, panel, series, esQueryConfig, indexPatternObject, capabilities) {
export function growthRate(req, panel, series, esQueryConfig, indexPatternObject, capabilities) {
return next => doc => {
const { interval } = getIntervalAndTimefield(panel, series, indexPatternObject);
const { intervalString } = getBucketSize(req, interval, capabilities);
if (series.metrics.some(filter)) {
series.metrics
.filter(filter)
.forEach(createRate(doc, intervalString, `aggs.${series.id}.aggs`));
.forEach(createGrowthRate(doc, intervalString, `aggs.${series.id}.aggs`));
return next(doc);
}
return next(doc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { rate } from './rate';
import { growthRate } from './growth_rate';
describe('rate(req, panel, series)', () => {
let panel;
let series;
Expand All @@ -34,7 +34,7 @@ describe('rate(req, panel, series)', () => {
metrics: [
{
id: 'metric-1',
type: 'rate',
type: 'growth_rate',
field: 'system.network.out.bytes',
unit: '1s',
},
Expand All @@ -52,32 +52,32 @@ describe('rate(req, panel, series)', () => {

test('calls next when finished', () => {
const next = jest.fn();
rate(req, panel, series)(next)({});
growthRate(req, panel, series)(next)({});
expect(next.mock.calls.length).toEqual(1);
});

test('returns rate aggs', () => {
test('returns growth rate aggs', () => {
const next = doc => doc;
const doc = rate(req, panel, series)(next)({});
const doc = growthRate(req, panel, series)(next)({});
expect(doc).toEqual({
aggs: {
test: {
aggs: {
timeseries: {
aggs: {
'metric-1-rate-max': {
'metric-1-growth-rate-max': {
max: { field: 'system.network.out.bytes' },
},
'metric-1-rate-derivative': {
'metric-1-growth-rate-derivative': {
derivative: {
buckets_path: 'metric-1-rate-max',
buckets_path: 'metric-1-growth-rate-max',
gap_policy: 'skip',
unit: '1s',
},
},
'metric-1': {
bucket_script: {
buckets_path: { value: 'metric-1-rate-derivative[normalized_value]' },
buckets_path: { value: 'metric-1-growth-rate-derivative[normalized_value]' },
script: {
source: 'params.value > 0.0 ? params.value : 0.0',
lang: 'painless',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { dateHistogram } from './date_histogram';
import { metricBuckets } from './metric_buckets';
import { siblingBuckets } from './sibling_buckets';
import { ratios as filterRatios } from './filter_ratios';
import { rate } from './rate';
import { growthRate } from './growth_rate';
import { normalizeQuery } from './normalize_query';

export const processors = [
Expand All @@ -39,6 +39,6 @@ export const processors = [
metricBuckets,
siblingBuckets,
filterRatios,
rate,
growthRate,
normalizeQuery,
];
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import { getBucketSize } from '../../helpers/get_bucket_size';
import { getIntervalAndTimefield } from '../../get_interval_and_timefield';
import { calculateAggRoot } from './calculate_agg_root';
import { createRate, filter } from '../series/rate';
import { createGrowthRate, filter } from '../series/growth_rate';

export function rate(req, panel, esQueryConfig, indexPatternObject) {
export function growthRate(req, panel, esQueryConfig, indexPatternObject) {
return next => doc => {
const { interval } = getIntervalAndTimefield(panel, {}, indexPatternObject);
const { intervalString } = getBucketSize(req, interval);
panel.series.forEach(column => {
const aggRoot = calculateAggRoot(doc, column);
column.metrics.filter(filter).forEach(createRate(doc, intervalString, aggRoot));
column.metrics.filter(filter).forEach(createGrowthRate(doc, intervalString, aggRoot));
});
return next(doc);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { metricBuckets } from './metric_buckets';
import { siblingBuckets } from './sibling_buckets';
import { ratios as filterRatios } from './filter_ratios';
import { normalizeQuery } from './normalize_query';
import { rate } from './rate';
import { growthRate } from './growth_rate';

export const processors = [
query,
Expand All @@ -37,6 +37,6 @@ export const processors = [
metricBuckets,
siblingBuckets,
filterRatios,
rate,
growthRate,
normalizeQuery,
];

0 comments on commit e1cea8e

Please sign in to comment.