Skip to content

Commit

Permalink
Extract query parts onto builder functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Fernández Gómez committed Jul 1, 2020
1 parent 8261fa4 commit 62884e0
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,8 @@ async function fetchLogsOverview(
index: logParams.index,
body: {
size: 0,
query: {
range: {
[logParams.timestampField]: {
gt: params.startTime,
lte: params.endTime,
format: 'strict_date_optional_time',
},
},
},
aggs: {
stats: {
terms: {
field: 'event.dataset',
size: 4,
},
},
series: {
date_histogram: {
field: logParams.timestampField,
fixed_interval: params.bucketSize,
},
aggs: {
dataset: {
terms: {
field: 'event.dataset',
size: 4,
},
},
},
},
},
query: buildLogOverviewQuery(logParams, params),
aggs: buildLogOverviewAggregations(logParams, params),
},
},
})
Expand All @@ -130,6 +101,43 @@ async function fetchLogsOverview(
});
}

function buildLogOverviewQuery(logParams: LogParams, params: FetchDataParams) {
return {
range: {
[logParams.timestampField]: {
gt: params.startTime,
lte: params.endTime,
format: 'strict_date_optional_time',
},
},
};
}

function buildLogOverviewAggregations(logParams: LogParams, params: FetchDataParams) {
return {
stats: {
terms: {
field: 'event.dataset',
size: 4,
},
},
series: {
date_histogram: {
field: logParams.timestampField,
fixed_interval: params.bucketSize,
},
aggs: {
dataset: {
terms: {
field: 'event.dataset',
size: 4,
},
},
},
},
};
}

function processLogsOverviewAggregations(aggregations: {
stats: StatsAggregation;
series: SeriesAggregation;
Expand Down

0 comments on commit 62884e0

Please sign in to comment.