Skip to content

Commit

Permalink
[6.8] Fixes session timeout (#91070) (#91888)
Browse files Browse the repository at this point in the history
* Fix calls to `/api/monitoring/v1/clusters` and `/api/monitoring/v1/elasticsearch_settings/check/cluster`

Seen on page: /app/monitoring

* Fix calls to `/api/index_management/indices/reload`

Seen on page: /app/kibana#/management/elasticsearch/index_management/indices

* Fix calls to `/api/cross_cluster_replication/follower_indices`

Seen on page: /app/kibana#/management/elasticsearch/cross_cluster_replication/follower_indices

* Fix calls to `/api/cross_cluster_replication/auto_follow_patterns`

Seen on page: /app/kibana#/management/elasticsearch/cross_cluster_replication/auto_follow_patterns

* Fix calls to `/api/remote_clusters`

Seen on page: /app/kibana#/management/elasticsearch/remote_clusters/list

* Fix calls to `/api/watcher/watches`

Seen on page: /app/kibana#/management/elasticsearch/watcher/watches

* Fix calls to `/api/rollup/jobs`

Seen on page: /app/kibana#/management/elasticsearch/rollup_jobs/job_list
  • Loading branch information
jportner authored Feb 19, 2021
1 parent 9dfaf56 commit 9297226
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import chrome from 'ui/chrome';
import { addSystemApiHeader } from 'ui/system_api';
import {
API_BASE_PATH,
API_REMOTE_CLUSTERS_BASE_PATH,
Expand Down Expand Up @@ -35,9 +36,10 @@ export function setHttpClient(client, $deffered) {
const extractData = (response) => response.data;

/* Auto Follow Pattern */
export const loadAutoFollowPatterns = () => (
httpClient.get(`${apiPrefix}/auto_follow_patterns`).then(extractData)
);
export const loadAutoFollowPatterns = (asSystemRequest) => {
const headers = asSystemRequest ? addSystemApiHeader({}) : undefined;
return httpClient.get(`${apiPrefix}/auto_follow_patterns`, { headers }).then(extractData);
};

export const getAutoFollowPattern = (id) => (
httpClient.get(`${apiPrefix}/auto_follow_patterns/${encodeURIComponent(id)}`).then(extractData)
Expand All @@ -62,9 +64,10 @@ export const deleteAutoFollowPattern = (id) => {
};

/* Follower Index */
export const loadFollowerIndices = () => (
httpClient.get(`${apiPrefix}/follower_indices`).then(extractData)
);
export const loadFollowerIndices = (asSystemRequest) => {
const headers = asSystemRequest ? addSystemApiHeader({}) : undefined;
return httpClient.get(`${apiPrefix}/follower_indices`, { headers }).then(extractData);
};

export const getFollowerIndex = (id) => (
httpClient.get(`${apiPrefix}/follower_indices/${encodeURIComponent(id)}`).then(extractData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const loadAutoFollowPatterns = (isUpdating = false) =>
scope,
status: isUpdating ? API_STATUS.UPDATING : API_STATUS.LOADING,
handler: async () => (
await loadAutoFollowPatternsRequest()
await loadAutoFollowPatternsRequest(isUpdating)
),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const loadFollowerIndices = (isUpdating = false) =>
scope,
status: isUpdating ? API_STATUS.UPDATING : API_STATUS.LOADING,
handler: async () => (
await loadFollowerIndicesRequest()
await loadFollowerIndicesRequest(isUpdating)
),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const mapDispatchToProps = (dispatch) => {
loadIndices: () => {
dispatch(loadIndices());
},
reloadIndices: () => {
dispatch(reloadIndices());
reloadIndices: (options) => {
dispatch(reloadIndices(undefined, options));
}
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export class IndexTableUi extends Component {
}
componentDidMount() {
this.props.loadIndices();
this.interval = setInterval(this.props.reloadIndices, REFRESH_RATE_INDEX_LIST);
this.interval = setInterval(
() => this.props.reloadIndices({ asSystemRequest: true }),
REFRESH_RATE_INDEX_LIST
);
const { filterChanged, filterFromURI } = this.props;
if (filterFromURI) {
const decodedFilter = decodeURIComponent(filterFromURI);
Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/index_management/public/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import chrome from 'ui/chrome';
import { addSystemApiHeader } from 'ui/system_api';
let httpClient;
export const setHttpClient = (client) => {
httpClient = client;
Expand All @@ -19,11 +20,12 @@ export async function loadIndices() {
return response.data;
}

export async function reloadIndices(indexNames) {
export async function reloadIndices(indexNames, { asSystemRequest } = {}) {
const body = {
indexNames
};
const response = await httpClient.post(`${apiPrefix}/indices/reload`, body);
const headers = asSystemRequest ? addSystemApiHeader({}) : undefined;
const response = await httpClient.post(`${apiPrefix}/indices/reload`, body, { headers });
return response.data;
}

Expand Down Expand Up @@ -126,4 +128,4 @@ export async function loadIndexData(type, indexName) {
case 'Stats':
return loadIndexStats(indexName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { loadIndices } from './load_indices';
import { toastNotifications } from 'ui/notify';

export const reloadIndicesSuccess = createAction('INDEX_MANAGEMENT_RELOAD_INDICES_SUCCESS');
export const reloadIndices = (indexNames) => async (dispatch, getState) => {
export const reloadIndices = (indexNames, options) => async (dispatch, getState) => {
let indices;
indexNames = indexNames || getIndexNamesForCurrentPage(getState());
try {
indices = await request(indexNames);
indices = await request(indexNames, options);
} catch (error) {
// an index has been deleted
// or the user does not have privileges for one of the indices on the current page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { addSystemApiHeader } from 'ui/system_api';

export class SettingsChecker {
constructor($http) {
this.$http = $http;
Expand Down Expand Up @@ -43,7 +45,9 @@ export class SettingsChecker {

async executeCheck() {
try {
const { data } = await this.$http.get(this.getApi());
const { data } = await this.$http.get(this.getApi(), {
headers: addSystemApiHeader({}),
});
const { found, reason } = data;

return { found, reason };
Expand Down
20 changes: 13 additions & 7 deletions x-pack/plugins/monitoring/public/services/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { uiModules } from 'ui/modules';
import { ajaxErrorHandlersProvider } from 'plugins/monitoring/lib/ajax_error_handler';
import { timefilter } from 'ui/timefilter';
import { addSystemApiHeader } from 'ui/system_api';
import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../common/constants';

function formatClusters(clusters) {
Expand All @@ -32,13 +33,18 @@ uiModule.service('monitoringClusters', ($injector) => {
}

const $http = $injector.get('$http');
return $http.post(url, {
ccs,
timeRange: {
min: min.toISOString(),
max: max.toISOString()
}
})
return $http
.post(
url,
{
ccs,
timeRange: {
min: min.toISOString(),
max: max.toISOString(),
},
},
{ headers: addSystemApiHeader({}) }
)
.then(response => response.data)
.then(data => {
if (clusterUuid) {
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/remote_clusters/public/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
*/

import chrome from 'ui/chrome';
import { addSystemApiHeader } from 'ui/system_api';
let httpClient;
export const setHttpClient = (client) => {
httpClient = client;
};
const apiPrefix = chrome.addBasePath('/api/remote_clusters');

export async function loadClusters() {
const response = await httpClient.get(`${apiPrefix}`);
export async function loadClusters({ asSystemRequest } = {}) {
const headers = asSystemRequest ? addSystemApiHeader({}) : undefined;
const response = await httpClient.get(`${apiPrefix}`, { headers });
return response.data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
export const refreshClusters = () => async (dispatch) => {
let clusters;
try {
clusters = await sendLoadClustersRequest();
clusters = await sendLoadClustersRequest({ asSystemRequest: true });
} catch (error) {
return showApiWarning(error, i18n.translate('xpack.remoteClusters.refreshAction.errorTitle', {
defaultMessage: 'Error refreshing remote clusters',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const mapDispatchToProps = (dispatch) => {
loadJobs: () => {
dispatch(loadJobs());
},
refreshJobs: () => {
dispatch(refreshJobs());
refreshJobs: (options) => {
dispatch(refreshJobs(options));
},
openDetailPanel: (jobId) => {
dispatch(openDetailPanel({ jobId: jobId }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export class JobListUi extends Component {
}

componentDidMount() {
this.interval = setInterval(this.props.refreshJobs, REFRESH_RATE_MS);
this.interval = setInterval(
() => this.props.refreshJobs({ asSystemRequest: true }),
REFRESH_RATE_MS
);
}

componentWillUnmount() {
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/rollup/public/crud_app/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
*/

import chrome from 'ui/chrome';
import { addSystemApiHeader } from 'ui/system_api';
import { getHttp } from './http_provider';

const apiPrefix = chrome.addBasePath('/api/rollup');

export async function loadJobs() {
const { data: { jobs } } = await getHttp().get(`${apiPrefix}/jobs`);
export async function loadJobs({ asSystemRequest } = {}) {
const headers = asSystemRequest ? addSystemApiHeader({}) : undefined;
const { data: { jobs } } = await getHttp().get(`${apiPrefix}/jobs`, { headers });
return jobs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
REFRESH_JOBS_SUCCESS,
} from '../action_types';

export const refreshJobs = () => async (dispatch) => {
export const refreshJobs = (options) => async (dispatch) => {
let jobs;
try {
jobs = await sendLoadJobsRequest();
jobs = await sendLoadJobsRequest(options);
} catch (error) {
return showApiWarning(error, i18n.translate('xpack.rollupJobs.refreshAction.errorTitle', {
defaultMessage: 'Error refreshing rollup jobs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ app.directive('watchList', function ($injector, i18n) {
this.pager = pagerFactory.create(this.watches.length, PAGINATION.PAGE_SIZE, 1);

// Reload watches periodically
const refreshInterval = $interval(() => this.loadWatches(), REFRESH_INTERVALS.WATCH_LIST);
const refreshInterval = $interval(() => this.loadWatches({
asSystemRequest: true,
}), REFRESH_INTERVALS.WATCH_LIST);
$scope.$on('$destroy', () => $interval.cancel(refreshInterval));

// react to watch and ui changes
Expand All @@ -81,8 +83,8 @@ app.directive('watchList', function ($injector, i18n) {
return this.selectedWatches.length > 0;
}

loadWatches = () => {
watchesService.getWatchList()
loadWatches = ({ asSystemRequest } = {}) => {
watchesService.getWatchList({ asSystemRequest })
.then(watches => {
this.watches = watches;
this.forbidden = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import chrome from 'ui/chrome';
import { addSystemApiHeader } from 'ui/system_api';
import { ROUTES } from '../../../common/constants';
import { Watch } from 'plugins/watcher/models/watch';

Expand All @@ -14,8 +15,9 @@ export class WatchesService {
this.basePath = chrome.addBasePath(ROUTES.API_ROOT);
}

getWatchList() {
return this.$http.get(`${this.basePath}/watches`)
getWatchList({ asSystemRequest } = {}) {
const headers = asSystemRequest ? addSystemApiHeader({}) : undefined;
return this.$http.get(`${this.basePath}/watches`, { headers })
.then(response => response.data.watches)
.then(watches => watches.map(watch => {
return Watch.fromUpstreamJson(watch);
Expand Down

0 comments on commit 9297226

Please sign in to comment.