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

Remove the es_admin proxy #13000

Merged
merged 2 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion src/core_plugins/elasticsearch/lib/create_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function createPath(prefix, path) {
export function createProxy(server, method, path, config) {
const proxies = new Map([
['/elasticsearch', server.plugins.elasticsearch.getCluster('data')],
['/es_admin', server.plugins.elasticsearch.getCluster('admin')]
]);

const responseHandler = function (err, upstreamResponse, request, reply) {
Expand Down
4 changes: 4 additions & 0 deletions src/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { mkdirp as mkdirpNode } from 'mkdirp';
import manageUuid from './server/lib/manage_uuid';
import search from './server/routes/api/search';
import settings from './server/routes/api/settings';
import { adminIndicesApi } from './server/routes/api/admin_indices';
import { scrollSearchApi } from './server/routes/api/scroll_search';
import { importApi } from './server/routes/api/import';
import { exportApi } from './server/routes/api/export';
import scripts from './server/routes/api/scripts';
Expand Down Expand Up @@ -143,6 +145,8 @@ export default function (kibana) {
search(server);
settings(server);
scripts(server);
adminIndicesApi(server);
scrollSearchApi(server);
importApi(server);
exportApi(server);
registerSuggestionsApi(server);
Expand Down
10 changes: 1 addition & 9 deletions src/core_plugins/kibana/public/dashboard/__tests__/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,13 @@ describe('dashboard panel', function () {

function init(mockDocResponse) {
ngMock.module('kibana');
ngMock.inject(($rootScope, $compile, Private, esAdmin) => {
ngMock.inject(($rootScope, $compile, Private) => {
Private.swap(SavedObjectsClientProvider, () => {
return {
get: sinon.stub().returns(Promise.resolve(mockDocResponse))
};
});

sinon.stub(esAdmin.indices, 'getFieldMapping').returns(Promise.resolve({
'.kibana': {
mappings: {
visualization: {}
}
}
}));

parentScope = $rootScope.$new();
parentScope.saveState = sinon.stub();
parentScope.createChildUiState = sinon.stub().returns(mockUiState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ savedObjectManagementRegistry.register({
});

// This is the only thing that gets injected into controllers
module.service('savedDashboards', function (SavedDashboard, kbnIndex, esAdmin, kbnUrl, $http) {
return new SavedObjectLoader(SavedDashboard, kbnIndex, esAdmin, kbnUrl, $http);
module.service('savedDashboards', function (SavedDashboard, kbnIndex, kbnUrl, $http) {
return new SavedObjectLoader(SavedDashboard, kbnIndex, kbnUrl, $http);
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ savedObjectManagementRegistry.register({
title: 'searches'
});

module.service('savedSearches', function (Promise, config, kbnIndex, esAdmin, createNotifier, SavedSearch, kbnUrl, $http) {
const savedSearchLoader = new SavedObjectLoader(SavedSearch, kbnIndex, esAdmin, kbnUrl, $http);
module.service('savedSearches', function (Promise, config, kbnIndex, createNotifier, SavedSearch, kbnUrl, $http) {
const savedSearchLoader = new SavedObjectLoader(SavedSearch, kbnIndex, kbnUrl, $http);
// Customize loader properties since adding an 's' on type doesn't work for type 'search' .
savedSearchLoader.loaderProperties = {
name: 'searches',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ savedObjectManagementRegistry.register({
title: 'visualizations'
});

app.service('savedVisualizations', function (Promise, esAdmin, kbnIndex, SavedVis, Private, Notifier, kbnUrl, $http) {
app.service('savedVisualizations', function (Promise, kbnIndex, SavedVis, Private, Notifier, kbnUrl, $http) {
const visTypes = Private(VisTypesRegistryProvider);
const notify = new Notifier({
location: 'Saved Visualization Service'
});

const saveVisualizationLoader = new SavedObjectLoader(SavedVis, kbnIndex, esAdmin, kbnUrl, $http);
const saveVisualizationLoader = new SavedObjectLoader(SavedVis, kbnIndex, kbnUrl, $http);

saveVisualizationLoader.mapHitSource = function (source, id) {
source.id = id;
Expand Down
50 changes: 50 additions & 0 deletions src/core_plugins/kibana/server/routes/api/admin_indices/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import handleESError from '../../../lib/handle_es_error';

export function adminIndicesApi(server) {
server.route({
path: '/api/kibana/legacy_admin_indices',
method: ['GET'],
handler: (req, reply) => {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const params = {
index: req.query.index,
format: 'json',
ignore: 404,
};
return callWithRequest(req, 'cat.indices', params)
.then(reply)
.catch(error => reply(handleESError(error)));
}
});

server.route({
path: '/api/kibana/legacy_admin_aliases',
method: ['GET'],
handler: (req, reply) => {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const params = {
index: req.query.index,
allowNoIndices: true,
ignore: 404,
};
return callWithRequest(req, 'indices.getAlias', params)
.then(reply)
.catch(error => reply(handleESError(error)));
}
});

server.route({
path: '/api/kibana/legacy_admin_index_template',
method: ['GET'],
handler: (req, reply) => {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const params = {
name: req.query.name,
ignore: 404,
};
return callWithRequest(req, 'indices.getTemplate', params)
.then(reply)
.catch(error => reply(handleESError(error)));
}
});
}
34 changes: 34 additions & 0 deletions src/core_plugins/kibana/server/routes/api/scroll_search/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import handleESError from '../../../lib/handle_es_error';

export function scrollSearchApi(server) {
server.route({
path: '/api/kibana/legacy_scroll_start',
method: ['POST'],
handler: (req, reply) => {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const { index, size, body } = req.payload;
const params = {
index,
size,
body,
scroll: '1m',
sort: '_doc',
};
return callWithRequest(req, 'search', params)
.then(reply)
.catch(error => reply(handleESError(error)));
}
});

server.route({
path: '/api/kibana/legacy_scroll_continue',
method: ['POST'],
handler: (req, reply) => {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const { scrollId } = req.payload;
return callWithRequest(req, 'scroll', { scrollId })
.then(reply)
.catch(error => reply(handleESError(error)));
}
});
}
4 changes: 2 additions & 2 deletions src/core_plugins/timelion/public/services/saved_sheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ savedObjectManagementRegistry.register({
});

// This is the only thing that gets injected into controllers
module.service('savedSheets', function (Promise, SavedSheet, kbnIndex, esAdmin, kbnUrl, $http) {
const savedSheetLoader = new SavedObjectLoader(SavedSheet, kbnIndex, esAdmin, kbnUrl, $http);
module.service('savedSheets', function (Promise, SavedSheet, kbnIndex, kbnUrl, $http) {
const savedSheetLoader = new SavedObjectLoader(SavedSheet, kbnIndex, kbnUrl, $http);
savedSheetLoader.urlFor = function (id) {
return kbnUrl.eval('#/{{id}}', { id: id });
};
Expand Down
5 changes: 0 additions & 5 deletions src/ui/public/chrome/api/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ export function initAngularApi(chrome, internals) {
a.href = chrome.addBasePath('/elasticsearch');
return a.href;
}()))
.value('esAdminUrl', (function () {
const a = document.createElement('a');
a.href = chrome.addBasePath('/es_admin');
return a.href;
}()))
.config(chrome.$setupXsrfRequestInterceptor)
.config(['$compileProvider', function ($compileProvider) {
if (!internals.devMode) {
Expand Down
25 changes: 1 addition & 24 deletions src/ui/public/courier/__tests__/saved_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,10 @@ describe('Saved Object', function () {

let SavedObject;
let IndexPattern;
let esAdminStub;
let esDataStub;
let savedObjectsClientStub;
let window;

/**
* Some default es stubbing to avoid timeouts and allow a default type of 'dashboard'.
*/
function mockEsService() {
// Allows the type 'dashboard' to be used.
// Unfortunately we need to use bluebird here instead of native promises because there is
// a call to finally.
sinon.stub(esAdminStub.indices, 'getFieldMapping').returns(BluebirdPromise.resolve({
'.kibana' : {
'mappings': {
'dashboard': {}
}
}
}));

// Necessary to avoid a timeout condition.
sinon.stub(esAdminStub.indices, 'putMapping').returns(BluebirdPromise.resolve());
}

/**
* Returns a fake doc response with the given index and id, of type dashboard
* that can be used to stub es calls.
Expand Down Expand Up @@ -94,15 +74,12 @@ describe('Saved Object', function () {
})
);

beforeEach(ngMock.inject(function (es, esAdmin, Private, $window) {
beforeEach(ngMock.inject(function (es, Private, $window) {
SavedObject = Private(SavedObjectProvider);
IndexPattern = Private(IndexPatternProvider);
esAdminStub = esAdmin;
esDataStub = es;
savedObjectsClientStub = Private(SavedObjectsClientProvider);
window = $window;

mockEsService();
}));

describe('save', function () {
Expand Down
5 changes: 2 additions & 3 deletions src/ui/public/courier/data_source/_doc_send_to_es.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { VersionConflict, RequestFailure } from 'ui/errors';
import { RequestQueueProvider } from 'ui/courier/_request_queue';
import { FetchProvider } from 'ui/courier/fetch/fetch';

export function DocSendToEsProvider(Promise, Private, es, esAdmin, kbnIndex) {
export function DocSendToEsProvider(Promise, Private, es) {
const requestQueue = Private(RequestQueueProvider);
const courierFetch = Private(FetchProvider);

Expand All @@ -33,8 +33,7 @@ export function DocSendToEsProvider(Promise, Private, es, esAdmin, kbnIndex) {
params.version = doc._getVersion();
}

const client = [].concat(params.index).includes(kbnIndex) ? esAdmin : es;
return client[method](params)
return es[method](params)
.then(function (resp) {
if (resp.status === 409) throw new VersionConflict(resp);

Expand Down
6 changes: 2 additions & 4 deletions src/ui/public/courier/fetch/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IsRequestProvider } from './is_request';
import { MergeDuplicatesRequestProvider } from './merge_duplicate_requests';
import { ReqStatusProvider } from './req_status';

export function CallClientProvider(Private, Promise, esAdmin, es) {
export function CallClientProvider(Private, Promise, es) {

const isRequest = Private(IsRequestProvider);
const mergeDuplicateRequests = Private(MergeDuplicatesRequestProvider);
Expand Down Expand Up @@ -115,9 +115,7 @@ export function CallClientProvider(Private, Promise, esAdmin, es) {
throw ABORTED;
}

const id = strategy.id;
const client = (id && id.includes('admin')) ? esAdmin : es;
return (esPromise = client[strategy.clientMethod]({ body }));
return (esPromise = es[strategy.clientMethod]({ body }));
})
.then(function (clientResp) {
return strategy.getResponses(clientResp);
Expand Down
5 changes: 2 additions & 3 deletions src/ui/public/courier/saved_object/saved_object_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { StringUtils } from 'ui/utils/string_utils';
import { SavedObjectsClient } from 'ui/saved_objects';

export class SavedObjectLoader {
constructor(SavedObjectClass, kbnIndex, esAdmin, kbnUrl, $http) {
constructor(SavedObjectClass, kbnIndex, kbnUrl, $http) {
this.type = SavedObjectClass.type;
this.Class = SavedObjectClass;
this.lowercaseType = this.type.toLowerCase();
this.kbnIndex = kbnIndex;
this.kbnUrl = kbnUrl;
this.esAdmin = esAdmin;

this.scanner = new Scanner(esAdmin, {
this.scanner = new Scanner($http, {
index: kbnIndex,
type: this.lowercaseType
});
Expand Down
12 changes: 0 additions & 12 deletions src/ui/public/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,4 @@ uiModules
apiVersion: esApiVersion,
plugins
});
})

//Elasticsearch client used for managing Kibana's state. Connects to the /es-admin proxy,
//Always uses the base elasticsearch configuartion
.service('esAdmin', function (esFactory, esAdminUrl, esApiVersion, esRequestTimeout) {
return esFactory({
host: esAdminUrl,
log: 'info',
requestTimeout: esRequestTimeout,
apiVersion: esApiVersion,
plugins
});
});
43 changes: 25 additions & 18 deletions src/ui/public/indices/__tests__/get_indices.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,35 @@ describe('GetIndices', function () {
let getIndices;

beforeEach(ngMock.module('kibana', ($provide) => {
indicesResponse = [
{ index: '.kibana' },
{ index: '.monitoring-es-2' },
{ index: '.monitoring-es-3' },
{ index: '.monitoring-es-4' },
{ index: '.monitoring-es-5' }
];
indicesResponse = {
data: [
{ index: '.kibana' },
{ index: '.monitoring-es-2' },
{ index: '.monitoring-es-3' },
{ index: '.monitoring-es-4' },
{ index: '.monitoring-es-5' }
]
};
aliasesResponse = {
'.monitoring-es-1': {
aliases: {
'.monitoring-es-active': {}
data: {
'.monitoring-es-1': {
aliases: {
'.monitoring-es-active': {}
}
}
}
};

$provide.service('esAdmin', function () {
$provide.service('$http', function () {
return {
cat: {
indices: async () => indicesResponse
},
indices: {
getAlias: async () => aliasesResponse
async get(path) {
if (path.includes('aliases')) {
return aliasesResponse;
}
if (path.includes('indices')) {
return indicesResponse;
}
throw new Error(`Unexpected path to $http.get(): ${path}`);
}
};
});
Expand All @@ -54,8 +61,8 @@ describe('GetIndices', function () {
const aliasesResponseCopy = Object.assign({}, aliasesResponse);
aliasesResponse = { status: 404 };
const indices = await getIndices();
expect(indices.length).to.be(indicesResponse.length);
indicesResponse.forEach((indexObj, idx) => {
expect(indices.length).to.be(indicesResponse.data.length);
indicesResponse.data.forEach((indexObj, idx) => {
expect(indices[idx]).to.be(indexObj.index);
});
aliasesResponse = aliasesResponseCopy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ describe('GetTemplateIndexPatterns', function () {
},
};

$provide.service('esAdmin', function () {
$provide.service('$http', function () {
return {
indices: {
getTemplate: async function () {
return response;
}
async get() {
return { data: response };
}
};
});
Expand Down
Loading