Skip to content
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

[Monitoring] Use server side pagination for Logstash Pipelines page #46587

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
636cce5
Basic version working for cluster pipelines
chrisronline Sep 20, 2019
55f30cb
More support
chrisronline Sep 21, 2019
1f12bbb
Refactoring
chrisronline Sep 25, 2019
c728dbd
Merge remote-tracking branch 'elastic/master' into monitoring/logstas…
chrisronline Sep 25, 2019
d8b7616
Fixes
chrisronline Sep 25, 2019
93df33f
Merge remote-tracking branch 'elastic/master' into monitoring/logstas…
chrisronline Sep 25, 2019
d633131
Fix sorting issues
chrisronline Sep 25, 2019
ce049c5
Reduce the number of buckets too
chrisronline Sep 25, 2019
9de98a9
Fix tests
chrisronline Sep 26, 2019
4c3e8dd
This is actually not helping - it seems that the filter in the query …
chrisronline Sep 26, 2019
0c97b1c
Add more data for metric.debug
chrisronline Sep 26, 2019
ec92e89
Support sorting on throughput and node count
chrisronline Sep 30, 2019
947de0b
Merge branch 'master' into monitoring/logstash_pipelines_pagination
elasticmachine Sep 30, 2019
b5c345f
Fix broken test
chrisronline Sep 30, 2019
5a95a9f
Use getMetrics and support with numOfBuckets parameter
chrisronline Sep 30, 2019
fe1c598
Fix test for realz
chrisronline Sep 30, 2019
33b7233
Merge remote-tracking branch 'elastic/master' into monitoring/logstas…
chrisronline Oct 1, 2019
4497a2a
Fix logstash management pages by introducing a new api to just retrie…
chrisronline Oct 1, 2019
56c92b4
We need this to go back to 1000 but it doesn't affect the number of c…
chrisronline Oct 1, 2019
76e357c
Fix issue with pagination data when filtering
chrisronline Oct 1, 2019
bc1f4d1
Fix sorting by id not working
chrisronline Oct 2, 2019
11476ec
Merge in master
chrisronline Oct 2, 2019
0711b30
Make this a little more sturdy
chrisronline Oct 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EuiPage, EuiLink, EuiPageBody, EuiPageContent, EuiPanel, EuiSpacer, Eui
import { formatMetric } from '../../../lib/format_number';
import { ClusterStatus } from '../cluster_status';
import { Sparkline } from 'plugins/monitoring/components/sparkline';
import { EuiMonitoringTable } from '../../table';
import { EuiMonitoringSSPTable } from '../../table';
import { i18n } from '@kbn/i18n';

export class PipelineListing extends Component {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class PipelineListing extends Component {
defaultMessage: 'Events Emitted Rate'
}),
field: 'latestThroughput',
sortable: true,
sortable: false,
render: (value, pipeline) => {
const throughput = pipeline.metrics.throughput;
return (
Expand Down Expand Up @@ -86,7 +86,7 @@ export class PipelineListing extends Component {
defaultMessage: 'Number of Nodes'
}),
field: 'latestNodesCount',
sortable: true,
sortable: false,
render: (value, pipeline) => {
const nodesCount = pipeline.metrics.nodesCount;
return (
Expand Down Expand Up @@ -137,6 +137,7 @@ export class PipelineListing extends Component {
sorting,
pagination,
onTableChange,
fetchMoreData,
upgradeMessage,
className
} = this.props;
Expand All @@ -151,7 +152,7 @@ export class PipelineListing extends Component {
</EuiPanel>
<EuiSpacer size="m" />
<EuiPageContent>
<EuiMonitoringTable
<EuiMonitoringSSPTable
className={className || 'logstashNodesTable'}
rows={data}
columns={columns}
Expand All @@ -164,18 +165,15 @@ export class PipelineListing extends Component {
}}
message={upgradeMessage}
pagination={pagination}
fetchMoreData={fetchMoreData}
search={{
box: {
incremental: true,
placeholder: i18n.translate('xpack.monitoring.logstash.filterPipelinesPlaceholder', {
defaultMessage: 'Filter Pipelines…'
})
},
}}
onTableChange={onTableChange}
executeQueryOptions={{
defaultFields: ['id']
}}
/>
</EuiPageContent>
</EuiPageBody>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import {
EuiBasicTable,
EuiSpacer,
EuiSearchBar
} from '@elastic/eui';

export function EuiMonitoringSSPTable({
rows: items,
search = {},
columns: _columns,
onTableChange,
fetchMoreData,
...props
}) {
const [isLoading, setIsLoading] = React.useState(false);
const [queryText, setQueryText] = React.useState('');
const [page, setPage] = React.useState({
index: props.pagination.pageIndex,
size: props.pagination.pageSize
});
const [sort, setSort] = React.useState(props.sorting);

if (search.box && !search.box['data-test-subj']) {
search.box['data-test-subj'] = 'monitoringTableToolBar';
}

const columns = _columns.map(column => {
if (!column['data-test-subj']) {
column['data-test-subj'] = 'monitoringTableHasData';
}

if (!('sortable' in column)) {
column.sortable = true;
}

return column;
});

const onChange = async ({ page, sort }) => {
setPage(page);
setSort({ sort });
setIsLoading(true);
await fetchMoreData({ page, sort: { sort }, queryText });
setIsLoading(false);
onTableChange({ page, sort });
};

const onQueryChange = async ({ queryText }) => {
setQueryText(queryText);
setIsLoading(true);
await fetchMoreData({ page, sort, queryText });
setIsLoading(false);
};

return (
<div data-test-subj={`${props.className}Container`}>
<EuiSearchBar {...search} onChange={onQueryChange}/>
<EuiSpacer size="l"/>
<EuiBasicTable
{...props}
items={items}
onChange={onChange}
loading={isLoading}
columns={columns}
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*/

export { EuiMonitoringTable } from './eui_table';
export { EuiMonitoringSSPTable } from './eui_table_ssp';
export { tableStorageGetter, tableStorageSetter, euiTableStorageGetter, euiTableStorageSetter } from './storage';
11 changes: 8 additions & 3 deletions x-pack/legacy/plugins/monitoring/public/views/base_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class MonitoringViewBaseController {
reactNodeId = null, // WIP: https://github.com/elastic/x-pack-kibana/issues/5198
$scope,
$injector,
options = {}
options = {},
fetchDataImmediately = true
}) {
const titleService = $injector.get('title');
const $executor = $injector.get('$executor');
Expand Down Expand Up @@ -119,7 +120,7 @@ export class MonitoringViewBaseController {
this.updateDataPromise = null;
}
const _api = apiUrlFn ? apiUrlFn() : api;
const promises = [_getPageData($injector, _api)];
const promises = [_getPageData($injector, _api, this.getPaginationRouteOptions())];
const setupMode = getSetupModeState();
if (setupMode.enabled) {
promises.push(updateSetupModeData());
Expand All @@ -132,7 +133,7 @@ export class MonitoringViewBaseController {
});
});
};
this.updateData();
fetchDataImmediately && this.updateData();

$executor.register({
execute: () => this.updateData()
Expand Down Expand Up @@ -175,4 +176,8 @@ export class MonitoringViewBaseController {
render(component, document.getElementById(this.reactNodeId));
}
}

getPaginationRouteOptions() {
return {};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { MonitoringViewBaseController } from './';
import { euiTableStorageGetter, euiTableStorageSetter } from 'plugins/monitoring/components/table';
import { EUI_SORT_ASCENDING } from '../../common/constants';

const PAGE_SIZE_OPTIONS = [5, 10, 20, 50];

/**
* Class to manage common instantiation behaviors in a view controller
* And add persistent state to a table:
Expand Down Expand Up @@ -42,17 +44,20 @@ export class MonitoringViewBaseEuiTableController extends MonitoringViewBaseCont
const setLocalStorageData = euiTableStorageSetter(storageKey);
const { page, sort } = getLocalStorageData(storage);

this.pagination = page || {
initialPageSize: 20,
pageSizeOptions: [5, 10, 20, 50]
this.pagination = {
pageSize: 20,
pageIndex: 0,
pageSizeOptions: PAGE_SIZE_OPTIONS
};

this.sorting = sort || {
sort: {
field: 'name',
direction: EUI_SORT_ASCENDING
if (page) {
if (!PAGE_SIZE_OPTIONS.includes(page.size)) {
page.size = 20;
}
};
this.setPagination(page);
}

this.setSorting(sort);

this.onTableChange = ({ page, sort }) => {
setLocalStorageData(storage, {
Expand All @@ -62,5 +67,53 @@ export class MonitoringViewBaseEuiTableController extends MonitoringViewBaseCont
}
});
};

this.updateData();
}

setPagination(page) {
this.pagination = {
pageSize: page.size,
pageIndex: page.index,
pageSizeOptions: PAGE_SIZE_OPTIONS
};
}

setSorting(sort) {
this.sorting = sort || {
sort: {
field: 'name',
direction: EUI_SORT_ASCENDING
}
};
}

setQueryText(queryText) {
this.queryText = queryText;
}

getPaginationRouteOptions() {
return {
pagination: {
size: this.pagination.pageSize,
index: this.pagination.pageIndex
},
...this.sorting,
queryText: this.queryText,
};
}

getPaginationTableProps(pagination) {
return {
sorting: this.sorting,
pagination: pagination,
onTableChange: this.onTableChange,
fetchMoreData: async ({ page, sort, queryText }) => {
this.setPagination(page);
this.setSorting(sort);
this.setQueryText(queryText);
this.updateData();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { PipelineListing } from '../../../../components/logstash/pipeline_listin
import { DetailStatus } from '../../../../components/logstash/detail_status';
import { CODE_PATH_LOGSTASH } from '../../../../../common/constants';

const getPageData = ($injector) => {
const getPageData = ($injector, _api = undefined, routeOptions = {}) => {
cachedout marked this conversation as resolved.
Show resolved Hide resolved
const $route = $injector.get('$route');
const $http = $injector.get('$http');
const globalState = $injector.get('globalState');
Expand All @@ -39,7 +39,8 @@ const getPageData = ($injector) => {
timeRange: {
min: timeBounds.min.toISOString(),
max: timeBounds.max.toISOString()
}
},
...routeOptions
})
.then(response => response.data)
.catch((err) => {
Expand Down Expand Up @@ -70,7 +71,6 @@ uiRoutes
const routeInit = Private(routeInitProvider);
return routeInit({ codePaths: [CODE_PATH_LOGSTASH] });
},
pageData: getPageData
},
controller: class extends MonitoringViewBaseEuiTableController {
constructor($injector, $scope) {
Expand All @@ -82,9 +82,11 @@ uiRoutes
getPageData,
reactNodeId: 'monitoringLogstashNodePipelinesApp',
$scope,
$injector
$injector,
fetchDataImmediately: false // We want to apply pagination before sending the first request
});


$scope.$watch(() => this.data, data => {
if (!data || !data.nodeSummary) {
return;
Expand All @@ -97,6 +99,11 @@ uiRoutes
}
}));

const pagination = {
...this.pagination,
totalItemCount: data.totalPipelineCount
};

this.renderReact(
<I18nContext>
<PipelineListing
Expand All @@ -106,9 +113,7 @@ uiRoutes
stats={data.nodeSummary}
statusComponent={DetailStatus}
data={data.pipelines}
sorting={this.sorting}
pagination={this.pagination}
onTableChange={this.onTableChange}
{...this.getPaginationTableProps(pagination)}
dateFormat={config.get('dateFormat')}
upgradeMessage={makeUpgradeMessage(data.nodeSummary.version, i18n)}
angular={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CODE_PATH_LOGSTASH } from '../../../../common/constants';
* Logstash Pipelines Listing page
*/

const getPageData = ($injector) => {
const getPageData = ($injector, _api = undefined, routeOptions = {}) => {
const $http = $injector.get('$http');
const globalState = $injector.get('globalState');
const Private = $injector.get('Private');
Expand All @@ -37,7 +37,8 @@ const getPageData = ($injector) => {
timeRange: {
min: timeBounds.min.toISOString(),
max: timeBounds.max.toISOString()
}
},
...routeOptions
})
.then(response => response.data)
.catch((err) => {
Expand All @@ -64,7 +65,6 @@ uiRoutes
const routeInit = Private(routeInitProvider);
return routeInit({ codePaths: [CODE_PATH_LOGSTASH] });
},
pageData: getPageData
},
controller: class LogstashPipelinesList extends MonitoringViewBaseEuiTableController {
constructor($injector, $scope) {
Expand All @@ -74,7 +74,8 @@ uiRoutes
getPageData,
reactNodeId: 'monitoringLogstashPipelinesApp',
$scope,
$injector
$injector,
fetchDataImmediately: false // We want to apply pagination before sending the first request
});

const $route = $injector.get('$route');
Expand All @@ -93,16 +94,19 @@ uiRoutes
? makeUpgradeMessage(pageData.clusterStatus.versions, i18n)
: null;

const pagination = {
...this.pagination,
totalItemCount: pageData.totalPipelineCount
};

super.renderReact(
<I18nContext>
<PipelineListing
className="monitoringLogstashPipelinesTable"
onBrush={(xaxis) => this.onBrush({ xaxis })}
stats={pageData.clusterStatus}
data={pageData.pipelines}
sorting={this.sorting}
pagination={this.pagination}
onTableChange={this.onTableChange}
{...this.getPaginationTableProps(pagination)}
upgradeMessage={upgradeMessage}
dateFormat={config.get('dateFormat')}
angular={{
Expand Down
Loading