-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[7.6] [TSVB] Fix memory leak #65684
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
Closed
Closed
[7.6] [TSVB] Fix memory leak #65684
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
timroes
approved these changes
May 8, 2020
Contributor
|
Diff against 7.6.2 build. RETRACTED (see further comments for up to date diff) |
Contributor
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
Contributor
|
Diff against 7.6.2 release: diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/helpers/index.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/helpers/index.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/helpers/index.js 2020-03-26 08:23:00.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/helpers/index.js 2020-05-08 15:56:56.000000000 +0200
@@ -3,6 +3,12 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
+Object.defineProperty(exports, "overwrite", {
+ enumerable: true,
+ get: function () {
+ return _overwrite.overwrite;
+ }
+});
exports.helpers = void 0;
var _bucket_transform = require("./bucket_transform");
@@ -27,6 +33,8 @@
var _parse_settings = require("./parse_settings");
+var _overwrite = require("./overwrite");
+
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/helpers/overwrite.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/helpers/overwrite.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/helpers/overwrite.js 1970-01-01 01:00:00.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/helpers/overwrite.js 2020-05-08 15:56:56.000000000 +0200
@@ -0,0 +1,169 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.isPlainObject = isPlainObject;
+exports.set = set;
+exports.overwrite = overwrite;
+
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+function isObjectInner(val) {
+ return val != null && typeof val === 'object' && Array.isArray(val) === false;
+}
+
+function isObjectObject(o) {
+ return isObjectInner(o) === true && Object.prototype.toString.call(o) === '[object Object]';
+}
+
+function isPlainObject(o) {
+ if (isObjectObject(o) === false) return false; // If has modified constructor
+
+ const ctor = o.constructor;
+ if (typeof ctor !== 'function') return false; // If has modified prototype
+
+ const prot = ctor.prototype;
+ if (isObjectObject(prot) === false) return false; // If constructor does not have an Object-specific method
+
+ if (prot.hasOwnProperty('isPrototypeOf') === false) {
+ return false;
+ } // Most likely a plain Object
+
+
+ return true;
+}
+
+function isObject(val) {
+ return val !== null && (typeof val === 'object' || typeof val === 'function');
+}
+
+function createKey(pattern, options) {
+ let id = pattern;
+
+ if (typeof options === 'undefined') {
+ return id + '';
+ }
+
+ const keys = Object.keys(options);
+
+ for (let i = 0; i < keys.length; i++) {
+ const key = keys[i];
+ id += ';' + key + '=' + String(options[key]);
+ }
+
+ return id;
+}
+
+function isValidKey(key) {
+ return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';
+}
+
+function set(target, path, value, options) {
+ if (!isObject(target)) {
+ return target;
+ }
+
+ const opts = options || {};
+ const isArray = Array.isArray(path);
+
+ if (!isArray && typeof path !== 'string') {
+ return target;
+ }
+
+ let merge = opts.merge;
+
+ if (merge && typeof merge !== 'function') {
+ merge = Object.assign;
+ }
+
+ const keys = (isArray ? path : split(path, opts)).filter(isValidKey);
+ const len = keys.length;
+ const orig = target;
+
+ if (!options && keys.length === 1) {
+ result(target, keys[0], value, merge);
+ return target;
+ }
+
+ for (let i = 0; i < len; i++) {
+ const prop = keys[i];
+
+ if (!isObject(target[prop])) {
+ target[prop] = {};
+ }
+
+ if (i === len - 1) {
+ result(target, prop, value, merge);
+ break;
+ }
+
+ target = target[prop];
+ }
+
+ return orig;
+}
+
+function result(target, path, value, merge) {
+ if (merge && isPlainObject(target[path]) && isPlainObject(value)) {
+ target[path] = merge({}, target[path], value);
+ } else {
+ target[path] = value;
+ }
+}
+
+function split(path, options) {
+ const id = createKey(path, options);
+ if (set.memo[id]) return set.memo[id];
+ const char = options && options.separator ? options.separator : '.';
+ let keys = [];
+ const res = [];
+
+ if (options && typeof options.split === 'function') {
+ keys = options.split(path);
+ } else {
+ keys = path.split(char);
+ }
+
+ for (let i = 0; i < keys.length; i++) {
+ let prop = keys[i];
+
+ while (prop && prop.slice(-1) === '\\' && keys[i + 1] != null) {
+ prop = prop.slice(0, -1) + char + keys[++i];
+ }
+
+ res.push(prop);
+ }
+
+ set.memo[id] = res;
+ return res;
+}
+
+set.memo = {};
+/**
+ * Set path in obj. Behaves like lodash `set`
+ * @param obj The object to mutate
+ * @param path The path of the sub-property to set
+ * @param val The value to set the sub-property to
+ */
+
+function overwrite(obj, path, val) {
+ set(obj, path, undefined);
+ set(obj, path, val);
+}
\ No newline at end of file
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/annotations/date_histogram.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/annotations/date_histogram.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/annotations/date_histogram.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/annotations/date_histogram.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,15 +5,13 @@
});
exports.dateHistogram = dateHistogram;
-var _lodash = _interopRequireDefault(require("lodash"));
-
var _server = require("../../../../../../data/server");
var _get_bucket_size = require("../../helpers/get_bucket_size");
var _get_timerange = require("../../helpers/get_timerange");
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+var _helpers = require("../../helpers");
/*
* Licensed to Elasticsearch B.V. under one or more contributor
@@ -45,8 +43,7 @@
to
} = (0, _get_timerange.getTimerange)(req);
const timezone = capabilities.searchTimezone;
-
- _lodash.default.set(doc, `aggs.${annotation.id}.date_histogram`, {
+ (0, _helpers.overwrite)(doc, `aggs.${annotation.id}.date_histogram`, {
field: timeField,
min_doc_count: 0,
time_zone: timezone,
@@ -56,7 +53,6 @@
},
...(0, _server.dateHistogramInterval)(intervalString)
});
-
return next(doc);
};
}
\ No newline at end of file
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/annotations/top_hits.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/annotations/top_hits.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/annotations/top_hits.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/annotations/top_hits.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,9 +5,7 @@
});
exports.topHits = topHits;
-var _lodash = _interopRequireDefault(require("lodash"));
-
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+var _helpers = require("../../helpers");
/*
* Licensed to Elasticsearch B.V. under one or more contributor
@@ -31,8 +29,7 @@
return next => doc => {
const fields = annotation.fields && annotation.fields.split(/[,\s]+/) || [];
const timeField = annotation.time_field;
-
- _lodash.default.set(doc, `aggs.${annotation.id}.aggs.hits.top_hits`, {
+ (0, _helpers.overwrite)(doc, `aggs.${annotation.id}.aggs.hits.top_hits`, {
sort: [{
[timeField]: {
order: 'desc'
@@ -43,7 +40,6 @@
},
size: 5
});
-
return next(doc);
};
}
\ No newline at end of file
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/date_histogram.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/date_histogram.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/date_histogram.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/date_histogram.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.dateHistogram = dateHistogram;
-var _lodash = require("lodash");
+var _helpers = require("../../helpers");
var _server = require("../../../../../../data/server");
@@ -52,7 +52,7 @@
to
} = (0, _offset_time.offsetTime)(req, series.offset_time);
const timezone = capabilities.searchTimezone;
- (0, _lodash.set)(doc, `aggs.${series.id}.aggs.timeseries.date_histogram`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.timeseries.date_histogram`, {
field: timeField,
min_doc_count: 0,
time_zone: timezone,
@@ -64,14 +64,14 @@
});
};
- const getDateHistogramForEntireTimerangeMode = () => (0, _lodash.set)(doc, `aggs.${series.id}.aggs.timeseries.auto_date_histogram`, {
+ const getDateHistogramForEntireTimerangeMode = () => (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.timeseries.auto_date_histogram`, {
field: timeField,
buckets: 1
});
(0, _get_timerange_mode.isLastValueTimerangeMode)(panel, series) ? getDateHistogramForLastBucketMode() : getDateHistogramForEntireTimerangeMode(); // master
- (0, _lodash.set)(doc, `aggs.${series.id}.meta`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.meta`, {
timeField,
intervalString,
bucketSize,
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/filter_ratios.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/filter_ratios.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/filter_ratios.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/filter_ratios.js 2020-05-08 15:56:56.000000000 +0200
@@ -7,9 +7,7 @@
var _bucket_transform = require("../../helpers/bucket_transform");
-var _lodash = _interopRequireDefault(require("lodash"));
-
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+var _helpers = require("../../helpers");
/*
* Licensed to Elasticsearch B.V. under one or more contributor
@@ -35,20 +33,18 @@
return next => doc => {
if (series.metrics.some(filter)) {
series.metrics.filter(filter).forEach(metric => {
- _lodash.default.set(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}-numerator.filter`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}-numerator.filter`, {
query_string: {
query: metric.numerator || '*',
analyze_wildcard: true
}
});
-
- _lodash.default.set(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}-denominator.filter`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}-denominator.filter`, {
query_string: {
query: metric.denominator || '*',
analyze_wildcard: true
}
});
-
let numeratorPath = `${metric.id}-numerator>_count`;
let denominatorPath = `${metric.id}-denominator>_count`;
@@ -67,16 +63,13 @@
const aggBody = {
metric: metricAgg
};
-
- _lodash.default.set(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}-numerator.aggs`, aggBody);
-
- _lodash.default.set(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}-denominator.aggs`, aggBody);
-
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}-numerator.aggs`, aggBody);
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}-denominator.aggs`, aggBody);
numeratorPath = `${metric.id}-numerator>metric`;
denominatorPath = `${metric.id}-denominator>metric`;
}
- _lodash.default.set(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}`, {
bucket_script: {
buckets_path: {
numerator: numeratorPath,
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/metric_buckets.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/metric_buckets.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/metric_buckets.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/metric_buckets.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.metricBuckets = metricBuckets;
-var _lodash = _interopRequireDefault(require("lodash"));
+var _helpers = require("../../helpers");
var _get_bucket_size = require("../../helpers/get_bucket_size");
@@ -13,8 +13,6 @@
var _get_interval_and_timefield = require("../../get_interval_and_timefield");
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
@@ -47,8 +45,7 @@
if (fn) {
try {
const bucket = fn(metric, series.metrics, intervalString);
-
- _lodash.default.set(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}`, bucket);
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.timeseries.aggs.${metric.id}`, bucket);
} catch (e) {// meh
}
}
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/normalize_query.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/normalize_query.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/normalize_query.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/normalize_query.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,6 +5,12 @@
});
exports.normalizeQuery = normalizeQuery;
+var _helpers = require("../../helpers");
+
+var _lodash = _interopRequireDefault(require("lodash"));
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
@@ -23,13 +29,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-const {
- set,
- get,
- isEmpty
-} = require('lodash');
-
-const isEmptyFilter = (filter = {}) => Boolean(filter.match_all) && isEmpty(filter.match_all);
+const isEmptyFilter = (filter = {}) => Boolean(filter.match_all) && _lodash.default.isEmpty(filter.match_all);
const hasSiblingPipelineAggregation = (aggs = {}) => Object.keys(aggs).length > 1;
/* For grouping by the 'Everything', the splitByEverything request processor
@@ -43,12 +43,13 @@
function removeEmptyTopLevelAggregation(doc, series) {
- const filter = get(doc, `aggs.${series.id}.filter`);
+ const filter = _lodash.default.get(doc, `aggs.${series.id}.filter`);
if (isEmptyFilter(filter) && !hasSiblingPipelineAggregation(doc.aggs[series.id].aggs)) {
- const meta = get(doc, `aggs.${series.id}.meta`);
- set(doc, `aggs`, doc.aggs[series.id].aggs);
- set(doc, `aggs.timeseries.meta`, meta);
+ const meta = _lodash.default.get(doc, `aggs.${series.id}.meta`);
+
+ (0, _helpers.overwrite)(doc, `aggs`, doc.aggs[series.id].aggs);
+ (0, _helpers.overwrite)(doc, `aggs.timeseries.meta`, meta);
}
return doc;
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/sibling_buckets.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/sibling_buckets.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/sibling_buckets.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/sibling_buckets.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.siblingBuckets = siblingBuckets;
-var _lodash = _interopRequireDefault(require("lodash"));
+var _helpers = require("../../helpers");
var _get_bucket_size = require("../../helpers/get_bucket_size");
@@ -13,8 +13,6 @@
var _get_interval_and_timefield = require("../../get_interval_and_timefield");
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
@@ -47,8 +45,7 @@
if (fn) {
try {
const bucket = fn(metric, series.metrics, bucketSize);
-
- _lodash.default.set(doc, `aggs.${series.id}.aggs.${metric.id}`, bucket);
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs.${metric.id}`, bucket);
} catch (e) {// meh
}
}
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_everything.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_everything.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_everything.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_everything.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,9 +5,7 @@
});
exports.splitByEverything = splitByEverything;
-var _lodash = _interopRequireDefault(require("lodash"));
-
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+var _helpers = require("../../helpers");
/*
* Licensed to Elasticsearch B.V. under one or more contributor
@@ -30,7 +28,7 @@
function splitByEverything(req, panel, series) {
return next => doc => {
if (series.split_mode === 'everything' || series.split_mode === 'terms' && !series.terms_field) {
- _lodash.default.set(doc, `aggs.${series.id}.filter.match_all`, {});
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.filter.match_all`, {});
}
return next(doc);
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_filter.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_filter.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_filter.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_filter.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.splitByFilter = splitByFilter;
-var _lodash = require("lodash");
+var _helpers = require("../../helpers");
var _server = require("../../../../../../../../plugins/data/server");
@@ -33,7 +33,7 @@
return next(doc);
}
- (0, _lodash.set)(doc, `aggs.${series.id}.filter`, _server.esQuery.buildEsQuery(indexPattern, [series.filter], [], esQueryConfig));
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.filter`, _server.esQuery.buildEsQuery(indexPattern, [series.filter], [], esQueryConfig));
return next(doc);
};
}
\ No newline at end of file
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_filters.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_filters.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_filters.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_filters.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.splitByFilters = splitByFilters;
-var _lodash = require("lodash");
+var _helpers = require("../../helpers");
var _server = require("../../../../../../../../plugins/data/server");
@@ -33,7 +33,7 @@
series.split_filters.forEach(filter => {
const builtEsQuery = _server.esQuery.buildEsQuery(indexPattern, [filter.filter], [], esQueryConfig);
- (0, _lodash.set)(doc, `aggs.${series.id}.filters.filters.${filter.id}`, builtEsQuery);
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.filters.filters.${filter.id}`, builtEsQuery);
});
}
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_terms.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_terms.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_terms.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/series/split_by_terms.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.splitByTerms = splitByTerms;
-var _lodash = require("lodash");
+var _helpers = require("../../helpers");
var _basic_aggs = require("../../../../../common/basic_aggs");
@@ -36,33 +36,33 @@
if (series.split_mode === 'terms' && series.terms_field) {
const direction = series.terms_direction || 'desc';
const metric = series.metrics.find(item => item.id === series.terms_order_by);
- (0, _lodash.set)(doc, `aggs.${series.id}.terms.field`, series.terms_field);
- (0, _lodash.set)(doc, `aggs.${series.id}.terms.size`, series.terms_size);
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.terms.field`, series.terms_field);
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.terms.size`, series.terms_size);
if (series.terms_include) {
- (0, _lodash.set)(doc, `aggs.${series.id}.terms.include`, series.terms_include);
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.terms.include`, series.terms_include);
}
if (series.terms_exclude) {
- (0, _lodash.set)(doc, `aggs.${series.id}.terms.exclude`, series.terms_exclude);
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.terms.exclude`, series.terms_exclude);
}
if (metric && metric.type !== 'count' && ~_basic_aggs.basicAggs.indexOf(metric.type)) {
const sortAggKey = `${series.terms_order_by}-SORT`;
const fn = _bucket_transform.bucketTransform[metric.type];
const bucketPath = (0, _get_buckets_path.getBucketsPath)(series.terms_order_by, series.metrics).replace(series.terms_order_by, sortAggKey);
- (0, _lodash.set)(doc, `aggs.${series.id}.terms.order`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.terms.order`, {
[bucketPath]: direction
});
- (0, _lodash.set)(doc, `aggs.${series.id}.aggs`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.aggs`, {
[sortAggKey]: fn(metric)
});
} else if (['_key', '_count'].includes(series.terms_order_by)) {
- (0, _lodash.set)(doc, `aggs.${series.id}.terms.order`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.terms.order`, {
[series.terms_order_by]: direction
});
} else {
- (0, _lodash.set)(doc, `aggs.${series.id}.terms.order`, {
+ (0, _helpers.overwrite)(doc, `aggs.${series.id}.terms.order`, {
_count: direction
});
}
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/date_histogram.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/date_histogram.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/date_histogram.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/date_histogram.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.dateHistogram = dateHistogram;
-var _lodash = require("lodash");
+var _helpers = require("../../helpers");
var _server = require("../../../../../../data/server");
@@ -59,7 +59,7 @@
const timezone = capabilities.searchTimezone;
panel.series.forEach(column => {
const aggRoot = (0, _calculate_agg_root.calculateAggRoot)(doc, column);
- (0, _lodash.set)(doc, `${aggRoot}.timeseries.date_histogram`, {
+ (0, _helpers.overwrite)(doc, `${aggRoot}.timeseries.date_histogram`, {
field: timeField,
min_doc_count: 0,
time_zone: timezone,
@@ -69,7 +69,7 @@
},
...(0, _server.dateHistogramInterval)(intervalString)
});
- (0, _lodash.set)(doc, aggRoot.replace(/\.aggs$/, '.meta'), {
+ (0, _helpers.overwrite)(doc, aggRoot.replace(/\.aggs$/, '.meta'), {
timeField,
intervalString,
bucketSize
@@ -80,11 +80,11 @@
const getDateHistogramForEntireTimerangeMode = () => {
panel.series.forEach(column => {
const aggRoot = (0, _calculate_agg_root.calculateAggRoot)(doc, column);
- (0, _lodash.set)(doc, `${aggRoot}.timeseries.auto_date_histogram`, {
+ (0, _helpers.overwrite)(doc, `${aggRoot}.timeseries.auto_date_histogram`, {
field: timeField,
buckets: 1
});
- (0, _lodash.set)(doc, aggRoot.replace(/\.aggs$/, '.meta'), meta);
+ (0, _helpers.overwrite)(doc, aggRoot.replace(/\.aggs$/, '.meta'), meta);
});
};
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/filter_ratios.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/filter_ratios.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/filter_ratios.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/filter_ratios.js 2020-05-08 15:56:56.000000000 +0200
@@ -7,12 +7,10 @@
var _bucket_transform = require("../../helpers/bucket_transform");
-var _lodash = _interopRequireDefault(require("lodash"));
+var _helpers = require("../../helpers");
var _calculate_agg_root = require("./calculate_agg_root");
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
@@ -40,20 +38,18 @@
if (column.metrics.some(filter)) {
column.metrics.filter(filter).forEach(metric => {
- _lodash.default.set(doc, `${aggRoot}.timeseries.aggs.${metric.id}-numerator.filter`, {
+ (0, _helpers.overwrite)(doc, `${aggRoot}.timeseries.aggs.${metric.id}-numerator.filter`, {
query_string: {
query: metric.numerator || '*',
analyze_wildcard: true
}
});
-
- _lodash.default.set(doc, `${aggRoot}.timeseries.aggs.${metric.id}-denominator.filter`, {
+ (0, _helpers.overwrite)(doc, `${aggRoot}.timeseries.aggs.${metric.id}-denominator.filter`, {
query_string: {
query: metric.denominator || '*',
analyze_wildcard: true
}
});
-
let numeratorPath = `${metric.id}-numerator>_count`;
let denominatorPath = `${metric.id}-denominator>_count`;
@@ -64,16 +60,13 @@
field: metric.field
})
};
-
- _lodash.default.set(doc, `${aggRoot}.timeseries.aggs.${metric.id}-numerator.aggs`, aggBody);
-
- _lodash.default.set(doc, `${aggBody}.timeseries.aggs.${metric.id}-denominator.aggs`, aggBody);
-
+ (0, _helpers.overwrite)(doc, `${aggRoot}.timeseries.aggs.${metric.id}-numerator.aggs`, aggBody);
+ (0, _helpers.overwrite)(doc, `${aggBody}.timeseries.aggs.${metric.id}-denominator.aggs`, aggBody);
numeratorPath = `${metric.id}-numerator>metric`;
denominatorPath = `${metric.id}-denominator>metric`;
}
- _lodash.default.set(doc, `${aggRoot}.timeseries.aggs.${metric.id}`, {
+ (0, _helpers.overwrite)(doc, `${aggRoot}.timeseries.aggs.${metric.id}`, {
bucket_script: {
buckets_path: {
numerator: numeratorPath,
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/metric_buckets.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/metric_buckets.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/metric_buckets.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/metric_buckets.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.metricBuckets = metricBuckets;
-var _lodash = _interopRequireDefault(require("lodash"));
+var _helpers = require("../../helpers");
var _get_bucket_size = require("../../helpers/get_bucket_size");
@@ -15,8 +15,6 @@
var _calculate_agg_root = require("./calculate_agg_root");
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
@@ -51,8 +49,7 @@
if (fn) {
try {
const bucket = fn(metric, column.metrics, intervalString);
-
- _lodash.default.set(doc, `${aggRoot}.timeseries.aggs.${metric.id}`, bucket);
+ (0, _helpers.overwrite)(doc, `${aggRoot}.timeseries.aggs.${metric.id}`, bucket);
} catch (e) {// meh
}
}
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/normalize_query.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/normalize_query.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/normalize_query.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/normalize_query.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,6 +5,12 @@
});
exports.normalizeQuery = normalizeQuery;
+var _lodash = _interopRequireDefault(require("lodash"));
+
+var _helpers = require("../../helpers");
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
@@ -23,14 +29,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-const {
- set,
- get,
- isEmpty,
- forEach
-} = require('lodash');
-
-const isEmptyFilter = (filter = {}) => Boolean(filter.match_all) && isEmpty(filter.match_all);
+const isEmptyFilter = (filter = {}) => Boolean(filter.match_all) && _lodash.default.isEmpty(filter.match_all);
const hasSiblingPipelineAggregation = (aggs = {}) => Object.keys(aggs).length > 1;
/* Last query handler in the chain. You can use this handler
@@ -43,23 +42,27 @@
function normalizeQuery() {
return () => doc => {
- const series = get(doc, 'aggs.pivot.aggs');
+ const series = _lodash.default.get(doc, 'aggs.pivot.aggs');
+
const normalizedSeries = {};
- forEach(series, (value, seriesId) => {
- const filter = get(value, `filter`);
+
+ _lodash.default.forEach(series, (value, seriesId) => {
+ const filter = _lodash.default.get(value, `filter`);
if (isEmptyFilter(filter) && !hasSiblingPipelineAggregation(value.aggs)) {
- const agg = get(value, 'aggs.timeseries');
- const meta = { ...get(value, 'meta'),
+ const agg = _lodash.default.get(value, 'aggs.timeseries');
+
+ const meta = { ..._lodash.default.get(value, 'meta'),
seriesId
};
- set(normalizedSeries, `${seriesId}`, agg);
- set(normalizedSeries, `${seriesId}.meta`, meta);
+ (0, _helpers.overwrite)(normalizedSeries, `${seriesId}`, agg);
+ (0, _helpers.overwrite)(normalizedSeries, `${seriesId}.meta`, meta);
} else {
- set(normalizedSeries, `${seriesId}`, value);
+ (0, _helpers.overwrite)(normalizedSeries, `${seriesId}`, value);
}
});
- set(doc, 'aggs.pivot.aggs', normalizedSeries);
+
+ (0, _helpers.overwrite)(doc, 'aggs.pivot.aggs', normalizedSeries);
return doc;
};
}
\ No newline at end of file
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/pivot.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/pivot.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/pivot.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/pivot.js 2020-05-08 15:56:56.000000000 +0200
@@ -7,6 +7,8 @@
var _lodash = require("lodash");
+var _helpers = require("../../helpers");
+
var _basic_aggs = require("../../../../../common/basic_aggs");
var _get_buckets_path = require("../../helpers/get_buckets_path");
@@ -38,35 +40,35 @@
} = req.payload.state;
if (panel.pivot_id) {
- (0, _lodash.set)(doc, 'aggs.pivot.terms.field', panel.pivot_id);
- (0, _lodash.set)(doc, 'aggs.pivot.terms.size', panel.pivot_rows);
+ (0, _helpers.overwrite)(doc, 'aggs.pivot.terms.field', panel.pivot_id);
+ (0, _helpers.overwrite)(doc, 'aggs.pivot.terms.size', panel.pivot_rows);
if (sort) {
const series = panel.series.find(item => item.id === sort.column);
const metric = series && (0, _lodash.last)(series.metrics);
if (metric && metric.type === 'count') {
- (0, _lodash.set)(doc, 'aggs.pivot.terms.order', {
+ (0, _helpers.overwrite)(doc, 'aggs.pivot.terms.order', {
_count: sort.order
});
} else if (metric && _basic_aggs.basicAggs.includes(metric.type)) {
const sortAggKey = `${metric.id}-SORT`;
const fn = _bucket_transform.bucketTransform[metric.type];
const bucketPath = (0, _get_buckets_path.getBucketsPath)(metric.id, series.metrics).replace(metric.id, sortAggKey);
- (0, _lodash.set)(doc, `aggs.pivot.terms.order`, {
+ (0, _helpers.overwrite)(doc, `aggs.pivot.terms.order`, {
[bucketPath]: sort.order
});
- (0, _lodash.set)(doc, `aggs.pivot.aggs`, {
+ (0, _helpers.overwrite)(doc, `aggs.pivot.aggs`, {
[sortAggKey]: fn(metric)
});
} else {
- (0, _lodash.set)(doc, 'aggs.pivot.terms.order', {
+ (0, _helpers.overwrite)(doc, 'aggs.pivot.terms.order', {
_key: (0, _lodash.get)(sort, 'order', 'asc')
});
}
}
} else {
- (0, _lodash.set)(doc, 'aggs.pivot.filter.match_all', {});
+ (0, _helpers.overwrite)(doc, 'aggs.pivot.filter.match_all', {});
}
return next(doc);
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/sibling_buckets.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/sibling_buckets.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/sibling_buckets.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/sibling_buckets.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.siblingBuckets = siblingBuckets;
-var _lodash = _interopRequireDefault(require("lodash"));
+var _helpers = require("../../helpers");
var _get_bucket_size = require("../../helpers/get_bucket_size");
@@ -15,8 +15,6 @@
var _calculate_agg_root = require("./calculate_agg_root");
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
@@ -51,8 +49,7 @@
if (fn) {
try {
const bucket = fn(metric, column.metrics, bucketSize);
-
- _lodash.default.set(doc, `${aggRoot}.${metric.id}`, bucket);
+ (0, _helpers.overwrite)(doc, `${aggRoot}.${metric.id}`, bucket);
} catch (e) {// meh
}
}
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/split_by_everything.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/split_by_everything.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/split_by_everything.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/split_by_everything.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.splitByEverything = splitByEverything;
-var _lodash = require("lodash");
+var _helpers = require("../../helpers");
var _server = require("../../../../../../../../plugins/data/server");
@@ -31,9 +31,9 @@
return next => doc => {
panel.series.filter(c => !(c.aggregate_by && c.aggregate_function)).forEach(column => {
if (column.filter) {
- (0, _lodash.set)(doc, `aggs.pivot.aggs.${column.id}.filter`, _server.esQuery.buildEsQuery(indexPattern, [column.filter], [], esQueryConfig));
+ (0, _helpers.overwrite)(doc, `aggs.pivot.aggs.${column.id}.filter`, _server.esQuery.buildEsQuery(indexPattern, [column.filter], [], esQueryConfig));
} else {
- (0, _lodash.set)(doc, `aggs.pivot.aggs.${column.id}.filter.match_all`, {});
+ (0, _helpers.overwrite)(doc, `aggs.pivot.aggs.${column.id}.filter.match_all`, {});
}
});
return next(doc);
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/split_by_terms.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/split_by_terms.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/split_by_terms.js 2020-03-26 08:23:01.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/request_processors/table/split_by_terms.js 2020-05-08 15:56:56.000000000 +0200
@@ -5,7 +5,7 @@
});
exports.splitByTerms = splitByTerms;
-var _lodash = require("lodash");
+var _helpers = require("../../helpers");
var _server = require("../../../../../../../../plugins/data/server");
@@ -30,11 +30,11 @@
function splitByTerms(req, panel, esQueryConfig, indexPattern) {
return next => doc => {
panel.series.filter(c => c.aggregate_by && c.aggregate_function).forEach(column => {
- (0, _lodash.set)(doc, `aggs.pivot.aggs.${column.id}.terms.field`, column.aggregate_by);
- (0, _lodash.set)(doc, `aggs.pivot.aggs.${column.id}.terms.size`, 100);
+ (0, _helpers.overwrite)(doc, `aggs.pivot.aggs.${column.id}.terms.field`, column.aggregate_by);
+ (0, _helpers.overwrite)(doc, `aggs.pivot.aggs.${column.id}.terms.size`, 100);
if (column.filter) {
- (0, _lodash.set)(doc, `aggs.pivot.aggs.${column.id}.column_filter.filter`, _server.esQuery.buildEsQuery(indexPattern, [column.filter], [], esQueryConfig));
+ (0, _helpers.overwrite)(doc, `aggs.pivot.aggs.${column.id}.column_filter.filter`, _server.esQuery.buildEsQuery(indexPattern, [column.filter], [], esQueryConfig));
}
});
return next(doc);
diff -urN src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.js src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.js
--- src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.js 2020-03-26 08:23:00.000000000 +0100
+++ src/legacy/core_plugins/vis_type_timeseries/server/lib/vis_data/table/process_bucket.js 2020-05-08 15:56:56.000000000 +0200
@@ -15,6 +15,8 @@
var _lodash = require("lodash");
+var _helpers = require("../helpers");
+
var _get_active_series = require("../helpers/get_active_series");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -48,7 +50,7 @@
const timeseries = {
buckets: (0, _lodash.get)(bucket, `${series.id}.buckets`)
};
- (0, _lodash.set)(bucket, series.id, {
+ (0, _helpers.overwrite)(bucket, series.id, {
meta,
timeseries
}); |
Contributor
|
✔️ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Applying recent TSVB changes to 7.6
Checklist
Delete any items that are not applicable to this PR.
For maintainers