Skip to content

Commit

Permalink
Merge elastic#26006 into rollup
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/legacy/core_plugins/metrics/server/lib/vis_data/annorations/build_request_body.js
#	src/legacy/core_plugins/metrics/server/lib/vis_data/get_annotations.js
#	src/legacy/core_plugins/metrics/server/lib/vis_data/get_series_data.js
#	src/legacy/core_plugins/metrics/server/lib/vis_data/get_table_data.js
#	src/legacy/core_plugins/metrics/server/lib/vis_data/request_processors/annotations/query.js
#	src/legacy/core_plugins/metrics/server/lib/vis_data/series/__tests__/build_request_body.js
#	src/legacy/core_plugins/metrics/server/lib/vis_data/series/build_request_body.js
#	src/legacy/core_plugins/metrics/server/lib/vis_data/series/get_request_params.js
  • Loading branch information
alexwizp committed Jan 31, 2019
1 parent 2656503 commit e9650ae
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
*/
import buildRequestBody from './build_request_body';
import getEsShardTimeout from '../helpers/get_es_shard_timeout';
import { getIndexPatternObject } from '../helpers/get_index_pattern';

export default (req, panel, annotation, capabilities) => {
export default async (req, panel, annotation, esQueryConfig, capabilities) => {
const bodies = [];
const timeout = getEsShardTimeout(req);
const indexPattern = annotation.index_pattern;
const indexPatternObject = await getIndexPatternObject(req, indexPattern);

if (capabilities.batchRequestsSupport) {
const indexPattern = annotation.index_pattern;

bodies.push({
index: indexPattern,
ignoreUnavailable: true,
});
}

bodies.push({
...buildRequestBody(req, panel, annotation, capabilities),
...buildRequestBody(req, panel, annotation, esQueryConfig, indexPatternObject, capabilities),
timeout
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import handleAnnotationResponse from './handle_annotation_response';
import getRequestParams from './annorations/get_request_params';

import SearchStrategiesRegister from '../search_strategies/search_strategies_register';

function validAnnotation(annotation) {
return annotation.index_pattern &&
annotation.time_field &&
Expand All @@ -29,15 +27,14 @@ function validAnnotation(annotation) {
annotation.template;
}

export default async (req, panel, esQueryConfig) => {
export default async (req, panel, esQueryConfig, searchStrategy, capabilities) => {
const indexPattern = panel.index_pattern;
const { searchStrategy, capabilities } = await SearchStrategiesRegister.getViableStrategy(req, indexPattern);
const searchRequest = searchStrategy.getSearchRequest(req, indexPattern);
const annotations = panel.annotations.filter(validAnnotation);

const body = annotations
.map(annotation => getRequestParams(req, panel, annotation, esQueryConfig, capabilities))
.reduce((acc, item) => acc.concat(item), []);
const bodiesPromises = annotations.map(annotation => getRequestParams(req, panel, annotation, esQueryConfig, capabilities));
const body = (await Promise.all(bodiesPromises))
.reduce((acc, items) => acc.concat(items), []);

if (!body.length) return { responses: [] };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ import handleResponseBody from './series/handle_response_body';
import handleErrorResponse from './handle_error_response';
import getAnnotations from './get_annotations';
import SearchStrategiesRegister from '../search_strategies/search_strategies_register';
import { getEsQueryConfig } from './helpers/get_es_query_uisettings';

export async function getSeriesData(req, panel) {
const indexPattern = panel.index_pattern;
const { searchStrategy, capabilities } = await SearchStrategiesRegister.getViableStrategy(req, indexPattern);
const searchRequest = searchStrategy.getSearchRequest(req, indexPattern);
const esQueryConfig = await getEsQueryConfig(req);

const body = panel.series
.map(series => getRequestParams(req, panel, series, capabilities))
const bodiesPromises = panel.series.map(series => getRequestParams(req, panel, series, esQueryConfig, capabilities));
const body = (await Promise.all(bodiesPromises))
.reduce((acc, items) => acc.concat(items), []);

return searchRequest.search({ body })
.then(data => {
const series = data.map(handleResponseBody(panel, esQueryConfig));
const series = data.map(handleResponseBody(panel));
return {
[panel.id]: {
id: panel.id,
Expand All @@ -44,7 +45,7 @@ export async function getSeriesData(req, panel) {
})
.then(resp => {
if (!panel.annotations || panel.annotations.length === 0) return resp;
return getAnnotations(req, panel, esQueryConfig).then(annotations => {
return getAnnotations(req, panel, esQueryConfig, searchStrategy, capabilities).then(annotations => {
resp[panel.id].annotations = annotations;
return resp;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@ import handleErrorResponse from './handle_error_response';
import { get } from 'lodash';
import processBucket from './table/process_bucket';
import SearchStrategiesRegister from '../search_strategies/search_strategies_register';
import { getEsQueryConfig } from './helpers/get_es_query_uisettings';
import { getIndexPatternObject } from './helpers/get_index_pattern';

export async function getTableData(req, panel) {
const indexPattern = panel.index_pattern;
const { searchStrategy } = await SearchStrategiesRegister.getViableStrategy(req, indexPattern);
const { searchStrategy, capabilities } = await SearchStrategiesRegister.getViableStrategy(req, indexPattern);
const searchRequest = searchStrategy.getSearchRequest(req, indexPattern);
const body = buildRequestBody(req, panel);

// todo:
// const indexPatternObject = await getIndexPatternObject(req, indexPatternString);
// const params = {
// index: indexPatternString,
// ignore_throttled: !includeFrozen,
// body: buildRequestBody(req, panel, esQueryConfig, indexPatternObject)
// };
const esQueryConfig = await getEsQueryConfig(req);
const indexPatternObject = await getIndexPatternObject(req, indexPattern);
const body = buildRequestBody(req, panel, esQueryConfig, indexPatternObject, capabilities);

try {
const resp = await searchRequest.search({ body });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import _ from 'lodash';
import getBucketSize from '../../helpers/get_bucket_size';
import getTimerange from '../../helpers/get_timerange';
export default function dateHistogram(req, panel, annotation, capabilities) {
export default function dateHistogram(req, panel, annotation, esQueryConfig, indexPatternObject, capabilities) {
return next => doc => {
const timeField = annotation.time_field;
const { bucketSize, intervalString } = getBucketSize(req, 'auto', capabilities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe('dateHistogram(req, panel, series)', () => {
let series;
let req;
let capabilities;
let config;
let indexPatternObject;

beforeEach(() => {
req = {
payload: {
Expand All @@ -44,18 +47,23 @@ describe('dateHistogram(req, panel, series)', () => {
interval: '10s'
};
series = { id: 'test' };
config = {
allowLeadingWildcards: true,
queryStringOptions: {},
};
indexPatternObject = {};
capabilities = new DefaultSearchCapabilities(req, true);
});

it('calls next when finished', () => {
const next = sinon.spy();
dateHistogram(req, panel, series, capabilities)(next)({});
dateHistogram(req, panel, series, config, indexPatternObject, capabilities)(next)({});
expect(next.calledOnce).to.equal(true);
});

it('returns valid date histogram', () => {
const next = doc => doc;
const doc = dateHistogram(req, panel, series, capabilities)(next)({});
const doc = dateHistogram(req, panel, series, config, indexPatternObject, capabilities)(next)({});
expect(doc).to.eql({
aggs: {
test: {
Expand Down Expand Up @@ -87,7 +95,7 @@ describe('dateHistogram(req, panel, series)', () => {
it('returns valid date histogram (offset by 1h)', () => {
series.offset_time = '1h';
const next = doc => doc;
const doc = dateHistogram(req, panel, series, capabilities)(next)({});
const doc = dateHistogram(req, panel, series, config, indexPatternObject, capabilities)(next)({});
expect(doc).to.eql({
aggs: {
test: {
Expand Down Expand Up @@ -122,7 +130,7 @@ describe('dateHistogram(req, panel, series)', () => {
series.series_time_field = 'timestamp';
series.series_interval = '20s';
const next = doc => doc;
const doc = dateHistogram(req, panel, series, capabilities)(next)({});
const doc = dateHistogram(req, panel, series, config, indexPatternObject, capabilities)(next)({});
expect(doc).to.eql({
aggs: {
test: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import getBucketSize from '../../helpers/get_bucket_size';
import offsetTime from '../../offset_time';
import getIntervalAndTimefield from '../../get_interval_and_timefield';
import { set } from 'lodash';
export default function dateHistogram(req, panel, series, capabilities) {
export default function dateHistogram(req, panel, series, esQueryConfig, indexPatternObject, capabilities) {
return next => doc => {
const { timeField, interval } = getIntervalAndTimefield(panel, series);
const { bucketSize, intervalString } = getBucketSize(req, interval, capabilities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import _ from 'lodash';
import getBucketSize from '../../helpers/get_bucket_size';
import bucketTransform from '../../helpers/bucket_transform';
import getIntervalAndTimefield from '../../get_interval_and_timefield';
export default function metricBuckets(req, panel, series, capabilities) {
export default function metricBuckets(req, panel, series, esQueryConfig, indexPatternObject, capabilities) {
return next => doc => {
const {
interval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import _ from 'lodash';
import getBucketSize from '../../helpers/get_bucket_size';
import bucketTransform from '../../helpers/bucket_transform';
import getIntervalAndTimefield from '../../get_interval_and_timefield';
export default function siblingBuckets(req, panel, series, capabilities) {
export default function siblingBuckets(req, panel, series, esQueryConfig, indexPatternObject, capabilities) {
return next => doc => {
const {
interval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,24 @@ describe('buildRequestBody(req)', () => {
const panel = body.panels[0];
const series = panel.series[0];
const getSearchTimezone = sinon.spy(() => 'UTC');
const getSearchInterval = sinon.spy();
const getValidTimeInterval = sinon.spy(() => '10s');

const capabilities = {
getSearchTimezone,
getSearchInterval,
getValidTimeInterval
};
const config = {
const config = {
allowLeadingWildcards: true,
queryStringOptions: {},
};
const doc = buildRequestBody({ payload: body }, panel, series, config);
const indexPatternObject = {};
const doc = buildRequestBody({ payload: body }, panel, series, config, indexPatternObject, capabilities);
expect(getSearchTimezone.calledOnce).to.equal(true);
expect(doc).to.eql({
size: 0,
query: {
bool: {
filter: [],
must: [
{
range: {
'@timestamp': {
gte: 1485463055881,
lte: 1485463955881,
format: 'epoch_millis'
}
}
},
{
bool: {
must: [
Expand All @@ -124,41 +114,52 @@ describe('buildRequestBody(req)', () => {
],
must_not: []
}
}
]
},
{
range: {
'@timestamp': {
gte: 1485463055881,
lte: 1485463955881,
format: 'epoch_millis'
}
}
},
],
must_not: [],
should: [],
}
},
'aggs': {
'timeseries': {
'aggs': {
aggs: {
timeseries: {
aggs: {
'c9b5f9c1-e403-11e6-be91-6f7688e9fac7': {
'bucket_script': {
'buckets_path': {
'count': '_count'
bucket_script: {
buckets_path: {
count: '_count'
},
'gap_policy': 'skip',
'script': {
'lang': 'expression',
'source': 'count * 1'
gap_policy: 'skip',
script: {
lang: 'expression',
source: 'count * 1'
}
}
}
},
'date_histogram': {
'extended_bounds': {
'max': 1485463955881,
'min': 1485463055881
date_histogram: {
extended_bounds: {
max: 1485463955881,
min: 1485463055881
},
'field': '@timestamp',
'interval': '10s',
'min_doc_count': 0,
'time_zone': 'UTC'
field: '@timestamp',
interval: '10s',
min_doc_count: 0,
time_zone: 'UTC'
},
'meta': {
'bucketSize': 10,
'intervalString': '10s',
'seriesId': 'c9b5f9c0-e403-11e6-be91-6f7688e9fac7',
'timeField': '@timestamp'
meta: {
bucketSize: 10,
intervalString: '10s',
seriesId: 'c9b5f9c0-e403-11e6-be91-6f7688e9fac7',
timeField: '@timestamp'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import buildProcessorFunction from '../build_processor_function';
import processors from '../request_processors/series';

//todo: req, panel, series, esQueryConfig, indexPatter, capabilities
function buildRequestBody(...args) {
const processor = buildProcessorFunction(processors, ...args);
const doc = processor({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@
*/
import buildRequestBody from './build_request_body';
import getEsShardTimeout from '../helpers/get_es_shard_timeout';
import { getIndexPatternObject } from '../helpers/get_index_pattern';

export default (req, panel, series, esQueryConfig, capabilities) => {
export default async (req, panel, series, esQueryConfig, capabilities) => {
const bodies = [];
const indexPatternString = series.override_index_pattern && series.series_index_pattern || panel.index_pattern;
const indexPatternObject = await getIndexPatternObject(req, indexPatternString);
const indexPattern = series.override_index_pattern && series.series_index_pattern || panel.index_pattern;
const indexPatternObject = await getIndexPatternObject(req, indexPattern);
const timeout = getEsShardTimeout(req);

if (capabilities.batchRequestsSupport) {
bodies.push({
index: indexPatternString,
index: indexPattern,
ignoreUnavailable: true,
});
}

bodies.push({
...buildRequestBody(req, panel, series, esQueryConfig, indexPatternObject, capabilities),
timeout
timeout,
});

return bodies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import buildProcessorFunction from '../build_processor_function';
import processors from '../request_processors/table';

function buildRequestBody(req, panel, esQueryConfig, indexPattern) {
const processor = buildProcessorFunction(processors, req, panel, esQueryConfig, indexPattern);
function buildRequestBody(...args) {
const processor = buildProcessorFunction(processors, ...args);
const doc = processor({});
return doc;
}
Expand Down

0 comments on commit e9650ae

Please sign in to comment.