Skip to content

Commit

Permalink
use infered type in aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Oct 26, 2020
1 parent 13981c0 commit 5ea830c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { mergeMap, map, catchError } from 'rxjs/operators';
import { Logger } from 'src/core/server';
import { JsonObject } from 'src/plugins/kibana_utils/common';
import { keyBy, mapValues } from 'lodash';
import { ESSearchResponse } from '../../../apm/typings/elasticsearch';
import { AggregatedStatProvider } from './runtime_statistics_aggregator';
import { ConcreteTaskInstance } from '../task';
import { parseIntervalAsSecond, asInterval, parseIntervalAsMillisecond } from '../lib/intervals';
import { AggregationResultOf } from '../../../apm/typings/elasticsearch/aggregations';
import { HealthStatus } from './monitoring_stats_stream';
Expand Down Expand Up @@ -109,7 +107,7 @@ export function createWorkloadAggregator(

return timer(0, refreshInterval).pipe(
mergeMap(() =>
taskStore.aggregate<WorkloadAggregation>({
taskStore.aggregate({
aggs: {
taskType: {
terms: { field: 'task.taskType' },
Expand Down Expand Up @@ -166,7 +164,7 @@ export function createWorkloadAggregator(
},
})
),
map((result: ESSearchResponse<ConcreteTaskInstance, { body: WorkloadAggregation }>) => {
map((result) => {
const {
aggregations,
hits: {
Expand All @@ -185,22 +183,13 @@ export function createWorkloadAggregator(
throw new Error(`Invalid workload: ${JSON.stringify(result)}`);
}

const taskTypes = (aggregations.taskType as AggregationResultOf<
WorkloadAggregation['aggs']['taskType'],
{}
>).buckets;
const schedules = (aggregations.schedule as AggregationResultOf<
WorkloadAggregation['aggs']['schedule'],
{}
>).buckets;
const taskTypes = aggregations.taskType.buckets;
const schedules = aggregations.schedule.buckets;

const {
overdue: { doc_count: overdue },
scheduleDensity: { buckets: [scheduleDensity] = [] } = {},
} = aggregations.idleTasks as AggregationResultOf<
WorkloadAggregation['aggs']['idleTasks'],
{}
>;
} = aggregations.idleTasks;

const summary: WorkloadStat = {
count,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/task_manager/server/task_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export class TaskStore {
aggs,
query,
size = 0,
}: AggregationOpts) {
}: TSearchRequest): Promise<ESSearchResponse<ConcreteTaskInstance, { body: TSearchRequest }>> {
const { body } = await this.esClient.search<
ESSearchResponse<ConcreteTaskInstance, { body: TSearchRequest }>
>({
Expand Down

0 comments on commit 5ea830c

Please sign in to comment.