Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Start implementing time offset for metrics #94783

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/plugins/data/common/search/aggs/agg_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SerializedFieldFormat,
} from 'src/plugins/expressions/common';

import moment from 'moment';
import { IAggType } from './agg_type';
import { writeParams } from './agg_params';
import { IAggConfigs } from './agg_configs';
Expand Down Expand Up @@ -172,6 +173,13 @@ export class AggConfig {
return _.get(this.params, key);
}

getTimeShift(): undefined | moment.Duration {
const rawTimeShift = this.getParam('timeShift');
if (!rawTimeShift) return undefined;
const [, amount, unit] = rawTimeShift.match(/(\d+)(\w)/);
return moment.duration(Number(amount), unit);
}

write(aggs?: IAggConfigs) {
return writeParams<AggConfig>(this.type.params, this, aggs);
}
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/data/common/search/aggs/metrics/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export const getCountMetricAgg = () =>
defaultMessage: 'Count',
});
},
params: [
{
name: 'timeShift',
type: 'string',
write: () => {},
},
],
getSerializedFormat(agg) {
return {
id: 'number',
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/data/common/search/aggs/metrics/count_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const aggCount = (): FunctionDefinition => ({
defaultMessage: 'Schema to use for this aggregation',
}),
},
timeShift: {
types: ['string'],
help: '',
},
customLabel: {
types: ['string'],
help: i18n.translate('data.search.aggs.metrics.count.customLabel.help', {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/search/aggs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export interface AggParamsMapping {
[BUCKET_TYPES.TERMS]: AggParamsTerms;
[METRIC_TYPES.AVG]: AggParamsAvg;
[METRIC_TYPES.CARDINALITY]: AggParamsCardinality;
[METRIC_TYPES.COUNT]: BaseAggParams;
[METRIC_TYPES.COUNT]: BaseAggParams & { timeShift?: string };
[METRIC_TYPES.GEO_BOUNDS]: AggParamsGeoBounds;
[METRIC_TYPES.GEO_CENTROID]: AggParamsGeoCentroid;
[METRIC_TYPES.MAX]: AggParamsMax;
Expand Down
Loading