mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Remove premature abstraction (#13042)
This commit is contained in:
parent
eb9f8a5040
commit
f3551a145c
7 changed files with 0 additions and 240 deletions
|
@ -6,7 +6,6 @@ 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';
|
||||
|
@ -145,7 +144,6 @@ export default function (kibana) {
|
|||
search(server);
|
||||
settings(server);
|
||||
scripts(server);
|
||||
adminIndicesApi(server);
|
||||
scrollSearchApi(server);
|
||||
importApi(server);
|
||||
exportApi(server);
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
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)));
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
import expect from 'expect.js';
|
||||
import ngMock from 'ng_mock';
|
||||
import { IndicesGetIndicesProvider } from 'ui/indices/get_indices';
|
||||
|
||||
describe('GetIndices', function () {
|
||||
let indicesResponse;
|
||||
let aliasesResponse;
|
||||
let getIndices;
|
||||
|
||||
beforeEach(ngMock.module('kibana', ($provide) => {
|
||||
indicesResponse = {
|
||||
data: [
|
||||
{ index: '.kibana' },
|
||||
{ index: '.monitoring-es-2' },
|
||||
{ index: '.monitoring-es-3' },
|
||||
{ index: '.monitoring-es-4' },
|
||||
{ index: '.monitoring-es-5' }
|
||||
]
|
||||
};
|
||||
aliasesResponse = {
|
||||
data: {
|
||||
'.monitoring-es-1': {
|
||||
aliases: {
|
||||
'.monitoring-es-active': {}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$provide.service('$http', function () {
|
||||
return {
|
||||
async get(path) {
|
||||
if (path.includes('aliases')) {
|
||||
return aliasesResponse;
|
||||
}
|
||||
if (path.includes('indices')) {
|
||||
return indicesResponse;
|
||||
}
|
||||
throw new Error(`Unexpected path to $http.get(): ${path}`);
|
||||
}
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
beforeEach(ngMock.inject((Private) => {
|
||||
getIndices = Private(IndicesGetIndicesProvider);
|
||||
}));
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(getIndices).to.be.a(Function);
|
||||
});
|
||||
|
||||
it('should rely on the alias endpoint if it returns a non 404', async function () {
|
||||
const indices = await getIndices();
|
||||
expect(indices.length).to.be(2);
|
||||
expect(indices[0]).to.be('.monitoring-es-1');
|
||||
expect(indices[1]).to.be('.monitoring-es-active');
|
||||
});
|
||||
|
||||
it('should fallback to the cat indices endpoint if there are no aliases', async function () {
|
||||
const aliasesResponseCopy = Object.assign({}, aliasesResponse);
|
||||
aliasesResponse = { status: 404 };
|
||||
const indices = await getIndices();
|
||||
expect(indices.length).to.be(indicesResponse.data.length);
|
||||
indicesResponse.data.forEach((indexObj, idx) => {
|
||||
expect(indices[idx]).to.be(indexObj.index);
|
||||
});
|
||||
aliasesResponse = aliasesResponseCopy;
|
||||
});
|
||||
});
|
|
@ -1,56 +0,0 @@
|
|||
import expect from 'expect.js';
|
||||
import ngMock from 'ng_mock';
|
||||
import { IndicesGetTemplateIndexPatternsProvider } from 'ui/indices/get_template_index_patterns';
|
||||
|
||||
describe('GetTemplateIndexPatterns', function () {
|
||||
let response;
|
||||
let getTemplateIndexPatterns;
|
||||
|
||||
beforeEach(ngMock.module('kibana', ($provide) => {
|
||||
response = {
|
||||
'.ml-state': {
|
||||
'index_patterns': [
|
||||
'.ml-state'
|
||||
]
|
||||
},
|
||||
'.watches': {
|
||||
'index_patterns': [
|
||||
'.watches*'
|
||||
]
|
||||
},
|
||||
'.watches2': {
|
||||
'index_patterns': [
|
||||
'.watches*'
|
||||
]
|
||||
},
|
||||
};
|
||||
|
||||
$provide.service('$http', function () {
|
||||
return {
|
||||
async get() {
|
||||
return { data: response };
|
||||
}
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
beforeEach(ngMock.inject((Private) => {
|
||||
getTemplateIndexPatterns = Private(IndicesGetTemplateIndexPatternsProvider);
|
||||
}));
|
||||
|
||||
it('should be a function', function () {
|
||||
expect(getTemplateIndexPatterns).to.be.a(Function);
|
||||
});
|
||||
|
||||
it('should get all index patterns', async function () {
|
||||
const indices = await getTemplateIndexPatterns();
|
||||
expect(indices).to.contain('.ml-state');
|
||||
expect(indices).to.contain('.watches*');
|
||||
});
|
||||
|
||||
it('should prevent duplicates', async function () {
|
||||
const indices = await getTemplateIndexPatterns();
|
||||
expect(indices).to.contain('.watches*');
|
||||
expect(indices.length).to.be(2);
|
||||
});
|
||||
});
|
|
@ -1,37 +0,0 @@
|
|||
import { pluck, reduce, size } from 'lodash';
|
||||
import chrome from 'ui/chrome';
|
||||
|
||||
export function IndicesGetIndicesProvider($http) {
|
||||
const getIndexNamesFromAliasesResponse = json => {
|
||||
// Assume this function won't be called in the event of a 404.
|
||||
return reduce(json, (list, { aliases }, indexName) => {
|
||||
list.push(indexName);
|
||||
if (size(aliases) > 0) {
|
||||
list.push(...Object.keys(aliases));
|
||||
}
|
||||
return list;
|
||||
}, []);
|
||||
};
|
||||
|
||||
const getIndexNamesFromIndicesResponse = json => {
|
||||
if (json.status === 404) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return pluck(json, 'index');
|
||||
};
|
||||
|
||||
return async function getIndices(query) {
|
||||
const aliasesPath = chrome.addBasePath('/api/kibana/legacy_admin_aliases');
|
||||
const aliases = await $http.get(aliasesPath, { index: query });
|
||||
|
||||
// If aliases return 200, they'll include matching indices, too.
|
||||
if (aliases.status === 404) {
|
||||
const indicesPath = chrome.addBasePath('/api/kibana/legacy_admin_indices');
|
||||
const indices = await $http.get(indicesPath, { index: query });
|
||||
return getIndexNamesFromIndicesResponse(indices.data);
|
||||
}
|
||||
|
||||
return getIndexNamesFromAliasesResponse(aliases.data);
|
||||
};
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
import { flatten, pluck, uniq } from 'lodash';
|
||||
import chrome from 'ui/chrome';
|
||||
|
||||
const getIndexPatternsFromResponse = json => {
|
||||
return uniq(flatten(pluck(json, 'index_patterns')));
|
||||
};
|
||||
|
||||
export function IndicesGetTemplateIndexPatternsProvider($http) {
|
||||
return async function getTemplateIndexPatterns(query) {
|
||||
const indexTemplatePath = chrome.addBasePath('/api/kibana/legacy_admin_index_template');
|
||||
const templatesJson = await $http.get(indexTemplatePath, { name: query });
|
||||
return getIndexPatternsFromResponse(templatesJson.data);
|
||||
};
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
import { IndicesGetIndicesProvider } from 'ui/indices/get_indices';
|
||||
import { IndicesGetTemplateIndexPatternsProvider } from 'ui/indices/get_template_index_patterns';
|
||||
import { uiModules } from 'ui/modules';
|
||||
const module = uiModules.get('kibana/indices');
|
||||
|
||||
export function IndicesProvider(Private) {
|
||||
this.getIndices = Private(IndicesGetIndicesProvider);
|
||||
this.getTemplateIndexPatterns = Private(IndicesGetTemplateIndexPatternsProvider);
|
||||
}
|
||||
|
||||
module.service('indices', Private => Private(IndicesProvider));
|
Loading…
Add table
Add a link
Reference in a new issue