Skip to content

Commit

Permalink
Merge branch 'master' into optimizer/max_stack_size_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Jan 10, 2020
2 parents 32988ee + bf7c253 commit cb4a64f
Show file tree
Hide file tree
Showing 36 changed files with 2,010 additions and 528 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"packages": [
"packages/*",
"x-pack",
"x-pack/plugins/*",
"x-pack/legacy/plugins/*",
"examples/*",
"test/plugin_functional/plugins/*",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58268,6 +58268,7 @@ function getProjectPaths({

if (!ossOnly) {
projectPaths.push(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(rootPath, 'x-pack'));
projectPaths.push(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(rootPath, 'x-pack/plugins/*'));
projectPaths.push(Object(path__WEBPACK_IMPORTED_MODULE_0__["resolve"])(rootPath, 'x-pack/legacy/plugins/*'));
}

Expand Down
1 change: 1 addition & 0 deletions packages/kbn-pm/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function getProjectPaths({ rootPath, ossOnly, skipKibanaPlugins }: Option

if (!ossOnly) {
projectPaths.push(resolve(rootPath, 'x-pack'));
projectPaths.push(resolve(rootPath, 'x-pack/plugins/*'));
projectPaths.push(resolve(rootPath, 'x-pack/legacy/plugins/*'));
}

Expand Down
39 changes: 34 additions & 5 deletions x-pack/legacy/plugins/maps/public/actions/map_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const SET_LAYER_ERROR_STATUS = 'SET_LAYER_ERROR_STATUS';
export const ADD_WAITING_FOR_MAP_READY_LAYER = 'ADD_WAITING_FOR_MAP_READY_LAYER';
export const CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST = 'CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST';
export const REMOVE_LAYER = 'REMOVE_LAYER';
export const TOGGLE_LAYER_VISIBLE = 'TOGGLE_LAYER_VISIBLE';
export const SET_LAYER_VISIBILITY = 'SET_LAYER_VISIBILITY';
export const MAP_EXTENT_CHANGED = 'MAP_EXTENT_CHANGED';
export const MAP_READY = 'MAP_READY';
export const MAP_DESTROYED = 'MAP_DESTROYED';
Expand Down Expand Up @@ -72,6 +72,7 @@ export const DISABLE_TOOLTIP_CONTROL = 'DISABLE_TOOLTIP_CONTROL';
export const HIDE_TOOLBAR_OVERLAY = 'HIDE_TOOLBAR_OVERLAY';
export const HIDE_LAYER_CONTROL = 'HIDE_LAYER_CONTROL';
export const HIDE_VIEW_CONTROL = 'HIDE_VIEW_CONTROL';
export const SET_WAITING_FOR_READY_HIDDEN_LAYERS = 'SET_WAITING_FOR_READY_HIDDEN_LAYERS';

function getLayerLoadingCallbacks(dispatch, layerId) {
return {
Expand Down Expand Up @@ -252,30 +253,44 @@ export function cleanTooltipStateForLayer(layerId, layerFeatures = []) {
};
}

export function toggleLayerVisible(layerId) {
export function setLayerVisibility(layerId, makeVisible) {
return async (dispatch, getState) => {
//if the current-state is invisible, we also want to sync data
//e.g. if a layer was invisible at start-up, it won't have any data loaded
const layer = getLayerById(layerId, getState());
if (!layer) {

// If the layer visibility is already what we want it to be, do nothing
if (!layer || layer.isVisible() === makeVisible) {
return;
}
const makeVisible = !layer.isVisible();

if (!makeVisible) {
dispatch(cleanTooltipStateForLayer(layerId));
}

await dispatch({
type: TOGGLE_LAYER_VISIBLE,
type: SET_LAYER_VISIBILITY,
layerId,
visibility: makeVisible,
});
if (makeVisible) {
dispatch(syncDataForLayer(layerId));
}
};
}

export function toggleLayerVisible(layerId) {
return async (dispatch, getState) => {
const layer = getLayerById(layerId, getState());
if (!layer) {
return;
}
const makeVisible = !layer.isVisible();

dispatch(setLayerVisibility(layerId, makeVisible));
};
}

export function setSelectedLayer(layerId) {
return async (dispatch, getState) => {
const oldSelectedLayer = getSelectedLayerId(getState());
Expand Down Expand Up @@ -840,3 +855,17 @@ export function hideLayerControl() {
export function hideViewControl() {
return { type: HIDE_VIEW_CONTROL, hideViewControl: true };
}

export function setHiddenLayers(hiddenLayerIds) {
return (dispatch, getState) => {
const isMapReady = getMapReady(getState());

if (!isMapReady) {
dispatch({ type: SET_WAITING_FOR_READY_HIDDEN_LAYERS, hiddenLayerIds });
} else {
getLayerListRaw(getState()).forEach(layer =>
dispatch(setLayerVisibility(layer.id, !hiddenLayerIds.includes(layer.id)))
);
}
};
}
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/maps/public/embeddable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- **hideToolbarOverlay:** (Boolean) Will disable toolbar, which can be used to navigate to coordinate by entering lat/long and zoom values.
- **hideLayerControl:** (Boolean) Will hide useful layer control, which can be used to hide/show a layer to get a refined view of the map.
- **hideViewControl:** (Boolean) Will hide view control at bottom right of the map, which shows lat/lon values based on mouse hover in the map, this is useful to get coordinate value from a particular point in map.
- **hiddenLayers:** (Array of Strings) Array of layer ids that should be hidden. Any other layers will be set to visible regardless of their value in the layerList used to initialize the embeddable

### Creating a Map embeddable from saved object
```
Expand Down
14 changes: 13 additions & 1 deletion x-pack/legacy/plugins/maps/public/embeddable/map_embeddable.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ import {
hideToolbarOverlay,
hideLayerControl,
hideViewControl,
setHiddenLayers,
} from '../actions/map_actions';
import { setReadOnly, setIsLayerTOCOpen, setOpenTOCDetails } from '../actions/ui_actions';
import { getIsLayerTOCOpen, getOpenTOCDetails } from '../selectors/ui_selectors';
import { getInspectorAdapters, setEventHandlers } from '../reducers/non_serializable_instances';
import { getMapCenter, getMapZoom } from '../selectors/map_selectors';
import { getMapCenter, getMapZoom, getHiddenLayerIds } from '../selectors/map_selectors';
import { MAP_SAVED_OBJECT_TYPE } from '../../common/constants';

export class MapEmbeddable extends Embeddable {
Expand Down Expand Up @@ -153,6 +154,9 @@ export class MapEmbeddable extends Embeddable {
}

this._store.dispatch(replaceLayerList(this._layerList));
if (this.input.hiddenLayers) {
this._store.dispatch(setHiddenLayers(this.input.hiddenLayers));
}
this._dispatchSetQuery(this.input);
this._dispatchSetRefreshConfig(this.input);

Expand Down Expand Up @@ -244,5 +248,13 @@ export class MapEmbeddable extends Embeddable {
openTOCDetails,
});
}

const hiddenLayerIds = getHiddenLayerIds(this._store.getState());

if (!_.isEqual(this.input.hiddenLayers, hiddenLayerIds)) {
this.updateInput({
hiddenLayers: hiddenLayerIds,
});
}
}
}
15 changes: 12 additions & 3 deletions x-pack/legacy/plugins/maps/public/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ADD_WAITING_FOR_MAP_READY_LAYER,
CLEAR_WAITING_FOR_MAP_READY_LAYER_LIST,
REMOVE_LAYER,
TOGGLE_LAYER_VISIBLE,
SET_LAYER_VISIBILITY,
MAP_EXTENT_CHANGED,
MAP_READY,
MAP_DESTROYED,
Expand Down Expand Up @@ -46,6 +46,7 @@ import {
HIDE_TOOLBAR_OVERLAY,
HIDE_LAYER_CONTROL,
HIDE_VIEW_CONTROL,
SET_WAITING_FOR_READY_HIDDEN_LAYERS,
} from '../actions/map_actions';

import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from './util';
Expand Down Expand Up @@ -307,8 +308,8 @@ export function map(state = INITIAL_STATE, action) {
...state,
waitingForMapReadyLayerList: [],
};
case TOGGLE_LAYER_VISIBLE:
return updateLayerInList(state, action.layerId, 'visible');
case SET_LAYER_VISIBILITY:
return updateLayerInList(state, action.layerId, 'visible', action.visibility);
case UPDATE_LAYER_STYLE:
const styleLayerId = action.layerId;
return updateLayerInList(state, styleLayerId, 'style', { ...action.style });
Expand Down Expand Up @@ -376,6 +377,14 @@ export function map(state = INITIAL_STATE, action) {
hideViewControl: action.hideViewControl,
},
};
case SET_WAITING_FOR_READY_HIDDEN_LAYERS:
return {
...state,
waitingForMapReadyLayerList: state.waitingForMapReadyLayerList.map(layer => ({
...layer,
visible: !action.hiddenLayerIds.includes(layer.id),
})),
};
default:
return state;
}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/maps/public/selectors/map_selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export const getLayerList = createSelector(
}
);

export const getHiddenLayerIds = createSelector(getLayerListRaw, layers =>
layers.filter(layer => !layer.visible).map(layer => layer.id)
);

export const getSelectedLayer = createSelector(
getSelectedLayerId,
getLayerList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('getPaginatedNodes', () => {
},
},
};
const shardStats = {
const nodesShardCount = {
nodes: {
1: {
shardCount: 10,
Expand All @@ -78,7 +78,7 @@ describe('getPaginatedNodes', () => {
pagination,
sort,
queryText,
{ clusterStats, shardStats }
{ clusterStats, nodesShardCount }
);
expect(nodes).toEqual({
pageOfNodes: [
Expand All @@ -98,7 +98,7 @@ describe('getPaginatedNodes', () => {
pagination,
{ ...sort, field: 'foo', direction: 'desc' },
queryText,
{ clusterStats, shardStats }
{ clusterStats, nodesShardCount }
);
expect(nodes).toEqual({
pageOfNodes: [
Expand All @@ -118,7 +118,7 @@ describe('getPaginatedNodes', () => {
pagination,
sort,
'tw',
{ clusterStats, shardStats }
{ clusterStats, nodesShardCount }
);
expect(nodes).toEqual({
pageOfNodes: [{ name: 'two', uuid: 2, isOnline: false, shardCount: 5, foo: 12 }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { LISTING_METRICS_NAMES, LISTING_METRICS_PATHS } from './nodes_listing_me
* @param {Object} shardStats: per-node information about shards
* @return {Array} node info combined with metrics for each node from handle_response
*/
export async function getNodes(req, esIndexPattern, pageOfNodes, clusterStats, shardStats) {
export async function getNodes(req, esIndexPattern, pageOfNodes, clusterStats, nodesShardCount) {
checkParam(esIndexPattern, 'esIndexPattern in getNodes');

const start = moment.utc(req.payload.timeRange.min).valueOf();
Expand Down Expand Up @@ -104,5 +104,9 @@ export async function getNodes(req, esIndexPattern, pageOfNodes, clusterStats, s
const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring');
const response = await callWithRequest(req, 'search', params);

return handleResponse(response, clusterStats, shardStats, pageOfNodes, { min, max, bucketSize });
return handleResponse(response, clusterStats, nodesShardCount, pageOfNodes, {
min,
max,
bucketSize,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function getPaginatedNodes(
pagination,
sort,
queryText,
{ clusterStats, shardStats }
{ clusterStats, nodesShardCount }
) {
const config = req.server.config();
const size = config.get('xpack.monitoring.max_bucket_size');
Expand All @@ -45,7 +45,7 @@ export async function getPaginatedNodes(
const clusterState = get(clusterStats, 'cluster_state', { nodes: {} });
for (const node of nodes) {
node.isOnline = !isUndefined(get(clusterState, ['nodes', node.uuid]));
node.shardCount = get(shardStats, `nodes[${node.uuid}].shardCount`, 0);
node.shardCount = get(nodesShardCount, `nodes[${node.uuid}].shardCount`, 0);
}

// `metricSet` defines a list of metrics that are sortable in the UI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@ import { uncovertMetricNames } from '../../convert_metric_names';
* Process the response from the get_nodes query
* @param {Object} response: response data from get_nodes
* @param {Object} clusterStats: cluster stats from cluster state document
* @param {Object} shardStats: per-node information about shards
* @param {Object} nodesShardCount: per-node information about shards
* @param {Object} timeOptions: min, max, and bucketSize needed for date histogram creation
* @return {Array} node info combined with metrics for each node
*/
export function handleResponse(response, clusterStats, shardStats, pageOfNodes, timeOptions = {}) {
export function handleResponse(
response,
clusterStats,
nodesShardCount,
pageOfNodes,
timeOptions = {}
) {
if (!get(response, 'hits.hits')) {
return [];
}

const nodeHits = get(response, 'hits.hits', []);
const nodesInfo = mapNodesInfo(nodeHits, clusterStats, shardStats);
const nodesInfo = mapNodesInfo(nodeHits, clusterStats, nodesShardCount);

/*
* Every node bucket is an object with a field for nodeId and fields for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { calculateNodeType, getNodeTypeClassLabel } from '../';
/**
* @param {Array} nodeHits: info about each node from the hits in the get_nodes query
* @param {Object} clusterStats: cluster stats from cluster state document
* @param {Object} shardStats: per-node information about shards
* @param {Object} nodesShardCount: per-node information about shards
* @return {Object} summarized info about each node keyed by nodeId
*/
export function mapNodesInfo(nodeHits, clusterStats, shardStats) {
export function mapNodesInfo(nodeHits, clusterStats, nodesShardCount) {
const clusterState = get(clusterStats, 'cluster_state', { nodes: {} });

return nodeHits.reduce((prev, node) => {
Expand All @@ -35,7 +35,7 @@ export function mapNodesInfo(nodeHits, clusterStats, shardStats) {
isOnline,
nodeTypeLabel: nodeTypeLabel,
nodeTypeClass: nodeTypeClass,
shardCount: get(shardStats, `nodes[${sourceNode.uuid}].shardCount`, 0),
shardCount: get(nodesShardCount, `nodes[${sourceNode.uuid}].shardCount`, 0),
},
};
}, {});
Expand Down
Loading

0 comments on commit cb4a64f

Please sign in to comment.