Skip to content

Commit

Permalink
Register function
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Sep 23, 2020
1 parent 4d89044 commit 2e59614
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/plugins/data/common/search/aggs/buckets/shard_delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@

import { BucketAggType } from './bucket_agg_type';
import { BaseAggParams } from '../types';
import { aggShardDelayFnName } from './shard_delay_fn';

export const SHARD_DELAY_AGG_NAME = 'shard_delay';

export interface AggParamsShardDelay extends BaseAggParams {
delay: number;
delay?: number;
}

export const getShardDelayBucketAgg = () =>
new BucketAggType({
name: SHARD_DELAY_AGG_NAME,
title: 'Shard Delay',
expressionName: aggShardDelayFnName,
createFilter: () => ({ match_all: {} }),
customLabels: false,
params: [
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/data/common/search/aggs/buckets/shard_delay_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ import { AggExpressionType, AggConfigSerialized } from '../';
import { getParsedValue } from '../utils/get_parsed_value';
import { AggParamsShardDelay, SHARD_DELAY_AGG_NAME } from './shard_delay';

const fnName = 'aggShardDelay';
export const aggShardDelayFnName = 'aggShardDelay';

type Input = any;
type AggArgs = AggParamsShardDelay & Pick<AggConfigSerialized, 'id' | 'enabled' | 'schema'>;

type Arguments = Assign<AggArgs, { delay?: number }>;

type Output = AggExpressionType;
type FunctionDefinition = ExpressionFunctionDefinition<typeof fnName, Input, Arguments, Output>;
type FunctionDefinition = ExpressionFunctionDefinition<
typeof aggShardDelayFnName,
Input,
Arguments,
Output
>;

export const aggShardDelay = (): FunctionDefinition => ({
name: fnName,
name: aggShardDelayFnName,
help: i18n.translate('data.search.aggs.function.buckets.shardDelay.help', {
defaultMessage: 'Generates a serialized agg config for a Shard Delay agg',
}),
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
SHARD_DELAY_AGG_NAME,
getShardDelayBucketAgg,
} from '../../common/search/aggs/buckets/shard_delay';
import { aggShardDelay } from '../../common/search/aggs/buckets/shard_delay_fn';

/** @internal */
export interface SearchServiceSetupDependencies {
Expand Down Expand Up @@ -89,6 +90,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {

if (this.initializerContext.config.get().search.aggs.shardDelay.enabled) {
aggs.types.registerBucket(SHARD_DELAY_AGG_NAME, getShardDelayBucketAgg);
expressions.registerFunction(aggShardDelay);
}

return {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
SHARD_DELAY_AGG_NAME,
} from '../../common/search/aggs/buckets/shard_delay';
import { ConfigSchema } from '../../config';
import { aggShardDelay } from '../../common/search/aggs/buckets/shard_delay_fn';

type StrategyMap<
SearchStrategyRequest extends IEsSearchRequest = IEsSearchRequest,
Expand Down Expand Up @@ -117,6 +118,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
.then((value) => {
if (value.search.aggs.shardDelay.enabled) {
aggs.types.registerBucket(SHARD_DELAY_AGG_NAME, getShardDelayBucketAgg);
registerFunction(aggShardDelay);
}
});

Expand Down

0 comments on commit 2e59614

Please sign in to comment.