Skip to content

Commit

Permalink
[Console] Fix for _settings and x-pack autocomplete (#60246)
Browse files Browse the repository at this point in the history
* Add settings completion to index create endpoint and clean up.

The cleanup is largely for moving settings data completion to JS
and removing the dynamic logic for loading different ES versions.

This is unused and unnecessary at this point.

* Add new settings JS files and move BOOLEAN to shared file.

* Important fix for loading x-pack console extensions.

After migrating the x-pack console extensions were being loaded
too late and were not being served to the client.

* Reorder imports to convention
  • Loading branch information
jloleysens authored Mar 18, 2020
1 parent 65a111f commit fae9317
Show file tree
Hide file tree
Showing 178 changed files with 163 additions and 230 deletions.
10 changes: 3 additions & 7 deletions src/plugins/console/public/lib/kb/kb.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,9 @@ function loadApisFromJson(
}

export function setActiveApi(api) {
if (_.isString(api)) {
if (!api) {
$.ajax({
url:
'../api/console/api_server?sense_version=' +
encodeURIComponent('@@SENSE_VERSION') +
'&apis=' +
encodeURIComponent(api),
url: '../api/console/api_server',
dataType: 'json', // disable automatic guessing
}).then(
function(data) {
Expand All @@ -169,7 +165,7 @@ export function setActiveApi(api) {
ACTIVE_API = api;
}

setActiveApi('es_6_0');
setActiveApi();

export const _test = {
loadApisFromJson: loadApisFromJson,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/console/server/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export { ProxyConfigCollection } from './proxy_config_collection';
export { proxyRequest } from './proxy_request';
export { getElasticsearchProxyConfig } from './elasticsearch_proxy_config';
export { setHeaders } from './set_headers';
export { addProcessorDefinition, addExtensionSpecFilePath } from './spec_definitions';
export { addProcessorDefinition, addExtensionSpecFilePath, loadSpec } from './spec_definitions';
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@
*/

import Api from './api';
import { getSpec } from './spec';
import { register } from './es_6_0/ingest';
const ES_6_0 = new Api('es_6_0');
const spec = getSpec();
import { getSpec } from './json';
import { register } from './js/ingest';
const ES = new Api('es');

// adding generated specs
Object.keys(spec).forEach(endpoint => {
ES_6_0.addEndpointDescription(endpoint, spec[endpoint]);
});
export const loadSpec = () => {
const spec = getSpec();

//adding globals and custom API definitions
require('./es_6_0/aliases')(ES_6_0);
require('./es_6_0/aggregations')(ES_6_0);
require('./es_6_0/document')(ES_6_0);
require('./es_6_0/filter')(ES_6_0);
require('./es_6_0/globals')(ES_6_0);
register(ES_6_0);
require('./es_6_0/mappings')(ES_6_0);
require('./es_6_0/query')(ES_6_0);
require('./es_6_0/reindex')(ES_6_0);
require('./es_6_0/search')(ES_6_0);
// adding generated specs
Object.keys(spec).forEach(endpoint => {
ES.addEndpointDescription(endpoint, spec[endpoint]);
});

export default ES_6_0;
// adding globals and custom API definitions
require('./js/aliases')(ES);
require('./js/aggregations')(ES);
require('./js/document')(ES);
require('./js/filter')(ES);
require('./js/globals')(ES);
register(ES);
require('./js/mappings')(ES);
require('./js/settings')(ES);
require('./js/query')(ES);
require('./js/reindex')(ES);
require('./js/search')(ES);
};

export default ES;
9 changes: 8 additions & 1 deletion src/plugins/console/server/lib/spec_definitions/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

export declare function addProcessorDefinition(...args: any[]): any;

export declare function resolveApi(senseVersion: string, apis: string[]): object;
export declare function resolveApi(): object;

export declare function addExtensionSpecFilePath(...args: any[]): any;

/**
* A function that synchronously reads files JSON from disk and builds
* the autocomplete structures served to the client. This must be called
* after any extensions have been loaded.
*/
export declare function loadSpec(): any;
6 changes: 4 additions & 2 deletions src/plugins/console/server/lib/spec_definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
* under the License.
*/

export { addProcessorDefinition } from './es_6_0/ingest';
export { addProcessorDefinition } from './js/ingest';

export { addExtensionSpecFilePath } from './spec';
export { addExtensionSpecFilePath } from './json';

export { loadSpec } from './es';

export { resolveApi } from './server';
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

const _ = require('lodash');

const BOOLEAN = {
__one_of: [true, false],
};
import { BOOLEAN } from './shared';

export default function(api) {
api.addEndpointDescription('put_mapping', {
Expand Down
74 changes: 74 additions & 0 deletions src/plugins/console/server/lib/spec_definitions/js/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { BOOLEAN } from './shared';

export default function(api) {
api.addEndpointDescription('put_settings', {
data_autocomplete_rules: {
refresh_interval: '1s',
number_of_shards: 1,
number_of_replicas: 1,
'blocks.read_only': BOOLEAN,
'blocks.read': BOOLEAN,
'blocks.write': BOOLEAN,
'blocks.metadata': BOOLEAN,
term_index_interval: 32,
term_index_divisor: 1,
'translog.flush_threshold_ops': 5000,
'translog.flush_threshold_size': '200mb',
'translog.flush_threshold_period': '30m',
'translog.disable_flush': BOOLEAN,
'cache.filter.max_size': '2gb',
'cache.filter.expire': '2h',
'gateway.snapshot_interval': '10s',
routing: {
allocation: {
include: {
tag: '',
},
exclude: {
tag: '',
},
require: {
tag: '',
},
total_shards_per_node: -1,
},
},
'recovery.initial_shards': {
__one_of: ['quorum', 'quorum-1', 'half', 'full', 'full-1'],
},
'ttl.disable_purge': BOOLEAN,
analysis: {
analyzer: {},
tokenizer: {},
filter: {},
char_filter: {},
},
'cache.query.enable': BOOLEAN,
shadow_replicas: BOOLEAN,
shared_filesystem: BOOLEAN,
data_path: 'path',
codec: {
__one_of: ['default', 'best_compression', 'lucene_default'],
},
},
});
}
22 changes: 22 additions & 0 deletions src/plugins/console/server/lib/spec_definitions/js/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const BOOLEAN = Object.freeze({
__one_of: [true, false],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"indices.put_settings": {
"data_autocomplete_rules": {
"__scope_link": "put_settings"
}
}
}
21 changes: 5 additions & 16 deletions src/plugins/console/server/lib/spec_definitions/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,10 @@
* under the License.
*/

import _ from 'lodash';
import es from './es';

const KNOWN_APIS = ['es_6_0'];

export function resolveApi(senseVersion, apis) {
const result = {};
_.each(apis, function(name) {
{
if (KNOWN_APIS.includes(name)) {
// for now we ignore sense_version. might add it in the api name later
const api = require('./' + name); // eslint-disable-line import/no-dynamic-require
result[name] = api.asJson();
}
}
});

return result;
export function resolveApi() {
return {
es: es.asJson(),
};
}
51 changes: 0 additions & 51 deletions src/plugins/console/server/lib/spec_definitions/server.test.js

This file was deleted.

Loading

0 comments on commit fae9317

Please sign in to comment.