Skip to content

Commit

Permalink
Merge branch '7.x' of github.com:elastic/kibana into backport/7.x/pr-…
Browse files Browse the repository at this point in the history
…52893

* '7.x' of github.com:elastic/kibana:
  [Console] Fix OSS build (elastic#53885) (elastic#54094)
  [Console] Console with better SQL support (elastic#51446) (elastic#54091)
  Fix suggested value for time_zone in range query (elastic#53841) (elastic#54092)
  [APM] Show errors on the timeline instead of under the transaction (elastic#53756) (elastic#54109)
  use NP deprecations in uiSettings (elastic#53755) (elastic#54009)
  adding message to transaction and span metadata (elastic#54017) (elastic#54090)

# Conflicts:
#	x-pack/legacy/plugins/console_extensions/spec/overrides/sql.query.json
  • Loading branch information
jloleysens committed Jan 7, 2020
2 parents a40140d + 50a5274 commit f349d77
Show file tree
Hide file tree
Showing 81 changed files with 2,917 additions and 1,453 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"fast-deep-equal": "^3.1.1",
"file-loader": "4.2.0",
"font-awesome": "4.7.0",
"fp-ts": "^2.3.1",
"getos": "^3.1.0",
"glob": "^7.1.2",
"glob-all": "^3.1.0",
Expand All @@ -185,6 +186,7 @@
"hoek": "^5.0.4",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.2",
"immer": "^1.5.0",
"inert": "^5.1.0",
"inline-style": "^2.0.0",
"joi": "^13.5.2",
Expand Down
1 change: 0 additions & 1 deletion src/core/server/config/deprecation/core_deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export const coreDeprecationProvider: ConfigDeprecationProvider = ({
}) => [
unusedFromRoot('savedObjects.indexCheckTimeout'),
unusedFromRoot('server.xsrf.token'),
unusedFromRoot('uiSettings.enabled'),
renameFromRoot('optimize.lazy', 'optimize.watch'),
renameFromRoot('optimize.lazyPort', 'optimize.watchPort'),
renameFromRoot('optimize.lazyHost', 'optimize.watchHost'),
Expand Down
11 changes: 0 additions & 11 deletions src/core/server/http/http_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ export const config = {
validate: match(validBasePathRegex, "must start with a slash, don't end with one"),
})
),
defaultRoute: schema.maybe(
schema.string({
validate(value) {
if (!value.startsWith('/')) {
return 'must start with a slash';
}
},
})
),
cors: schema.conditional(
schema.contextRef('dev'),
true,
Expand Down Expand Up @@ -149,7 +140,6 @@ export class HttpConfig {
public maxPayload: ByteSizeValue;
public basePath?: string;
public rewriteBasePath: boolean;
public defaultRoute?: string;
public ssl: SslConfig;
public compression: { enabled: boolean; referrerWhitelist?: string[] };
public csp: ICspConfig;
Expand All @@ -171,7 +161,6 @@ export class HttpConfig {
this.socketTimeout = rawHttpConfig.socketTimeout;
this.rewriteBasePath = rawHttpConfig.rewriteBasePath;
this.ssl = new SslConfig(rawHttpConfig.ssl || {});
this.defaultRoute = rawHttpConfig.defaultRoute;
this.compression = rawHttpConfig.compression;
this.csp = new CspConfig(rawCspConfig);
this.xsrf = rawHttpConfig.xsrf;
Expand Down
1 change: 0 additions & 1 deletion src/core/server/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const createSetupContractMock = () => {
getAuthHeaders: jest.fn(),
},
isTlsEnabled: false,
config: {},
};
setupContract.createCookieSessionStorageFactory.mockResolvedValue(
sessionStorageMock.createFactory()
Expand Down
4 changes: 0 additions & 4 deletions src/core/server/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ export class HttpService implements CoreService<InternalHttpServiceSetup, HttpSe
contextName: T,
provider: RequestHandlerContextProvider<T>
) => this.requestHandlerContext!.registerContext(pluginOpaqueId, contextName, provider),

config: {
defaultRoute: config.defaultRoute,
},
};

return contract;
Expand Down
10 changes: 0 additions & 10 deletions src/core/server/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,6 @@ export interface InternalHttpServiceSetup
contextName: T,
provider: RequestHandlerContextProvider<T>
) => RequestHandlerContextContainer;
config: {
/**
* @internalRemarks
* Deprecated part of the server config, provided until
* https://github.com/elastic/kibana/issues/40255
*
* @deprecated
* */
defaultRoute?: string;
};
}

/** @public */
Expand Down
18 changes: 18 additions & 0 deletions src/core/server/internal_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
* under the License.
*/

import { Type } from '@kbn/config-schema';

import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { ConfigDeprecationProvider } from './config';
import { ContextSetup } from './context';
import { InternalElasticsearchServiceSetup } from './elasticsearch';
import { InternalHttpServiceSetup } from './http';
Expand Down Expand Up @@ -47,3 +50,18 @@ export interface InternalCoreStart {
savedObjects: InternalSavedObjectsServiceStart;
uiSettings: InternalUiSettingsServiceStart;
}

/**
* @internal
*/
export interface ServiceConfigDescriptor<T = any> {
path: string;
/**
* Schema to use to validate the configuration.
*/
schema: Type<T>;
/**
* Provider for the {@link ConfigDeprecation} to apply to the plugin configuration.
*/
deprecations?: ConfigDeprecationProvider;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export class LegacyObjectToConfigAdapter extends ObjectToConfigAdapter {
return {
autoListen: configValue.autoListen,
basePath: configValue.basePath,
defaultRoute: configValue.defaultRoute,
cors: configValue.cors,
customResponseHeaders: configValue.customResponseHeaders,
host: configValue.host,
Expand Down
4 changes: 4 additions & 0 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ export class Server {
];

this.configService.addDeprecationProvider(rootConfigPath, coreDeprecationProvider);
this.configService.addDeprecationProvider(
uiSettingsConfig.path,
uiSettingsConfig.deprecations!
);

for (const [path, schema] of schemas) {
await this.configService.setSchema(path, schema);
Expand Down
36 changes: 28 additions & 8 deletions src/core/server/ui_settings/ui_settings_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,35 @@
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { ConfigDeprecationProvider } from 'src/core/server';
import { ServiceConfigDescriptor } from '../internal_types';

export type UiSettingsConfigType = TypeOf<typeof config.schema>;
const deprecations: ConfigDeprecationProvider = ({ unused, renameFromRoot }) => [
unused('enabled'),
renameFromRoot('server.defaultRoute', 'uiSettings.overrides.defaultRoute'),
];

export const config = {
const configSchema = schema.object({
overrides: schema.object(
{
defaultRoute: schema.maybe(
schema.string({
validate(value) {
if (!value.startsWith('/')) {
return 'must start with a slash';
}
},
})
),
},
{ allowUnknowns: true }
),
});

export type UiSettingsConfigType = TypeOf<typeof configSchema>;

export const config: ServiceConfigDescriptor<UiSettingsConfigType> = {
path: 'uiSettings',
schema: schema.object({
overrides: schema.object({}, { allowUnknowns: true }),
// Deprecation is implemented in LP.
// We define schema here not to fail on the validation step.
enabled: schema.maybe(schema.boolean()),
}),
schema: configSchema,
deprecations,
};
22 changes: 0 additions & 22 deletions src/core/server/ui_settings/ui_settings_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { MockUiSettingsClientConstructor } from './ui_settings_service.test.mock

import { UiSettingsService } from './ui_settings_service';
import { httpServiceMock } from '../http/http_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { savedObjectsClientMock } from '../mocks';
import { mockCoreContext } from '../core_context.mock';

Expand Down Expand Up @@ -69,27 +68,6 @@ describe('uiSettings', () => {
expect(MockUiSettingsClientConstructor.mock.calls[0][0].overrides).toEqual(overrides);
});

it('passes overrides with deprecated "server.defaultRoute"', async () => {
const service = new UiSettingsService(coreContext);
const httpSetupWithDefaultRoute = httpServiceMock.createSetupContract();
httpSetupWithDefaultRoute.config.defaultRoute = '/defaultRoute';
const setup = await service.setup({ http: httpSetupWithDefaultRoute });
setup.asScopedToClient(savedObjectsClient);

expect(MockUiSettingsClientConstructor.mock.calls[0][0].overrides).toEqual({
...overrides,
defaultRoute: '/defaultRoute',
});

expect(loggingServiceMock.collect(coreContext.logger).warn).toMatchInlineSnapshot(`
Array [
Array [
"Config key \\"server.defaultRoute\\" is deprecated. It has been replaced with \\"uiSettings.overrides.defaultRoute\\"",
],
]
`);
});

it('passes a copy of set defaults to UiSettingsClient', async () => {
const service = new UiSettingsService(coreContext);
const setup = await service.setup(setupDeps);
Expand Down
18 changes: 3 additions & 15 deletions src/core/server/ui_settings/ui_settings_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export class UiSettingsService
public async setup(deps: SetupDeps): Promise<InternalUiSettingsServiceSetup> {
registerRoutes(deps.http.createRouter(''));
this.log.debug('Setting up ui settings service');
this.overrides = await this.getOverrides(deps);
const config = await this.config$.pipe(first()).toPromise();
this.overrides = config.overrides;

return {
register: this.register.bind(this),
asScopedToClient: this.getScopedClientFactory(),
Expand Down Expand Up @@ -95,18 +97,4 @@ export class UiSettingsService
this.uiSettingsDefaults.set(key, value);
});
}

private async getOverrides(deps: SetupDeps) {
const config = await this.config$.pipe(first()).toPromise();
const overrides: Record<string, any> = config.overrides;
// manually implemented deprecation until New platform Config service
// supports them https://github.com/elastic/kibana/issues/40255
if (typeof deps.http.config.defaultRoute !== 'undefined') {
overrides.defaultRoute = deps.http.config.defaultRoute;
this.log.warn(
'Config key "server.defaultRoute" is deprecated. It has been replaced with "uiSettings.overrides.defaultRoute"'
);
}
return overrides;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* 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 ace from 'brace';

const { TextHighlightRules } = ace.acequire('ace/mode/text_highlight_rules');
const oop = ace.acequire('ace/lib/oop');

export const ElasticsearchSqlHighlightRules = function(this: any) {
// See https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-commands.html
const keywords =
'describe|between|in|like|not|and|or|desc|select|from|where|having|group|by|order' +
'asc|desc|pivot|for|in|as|show|columns|include|frozen|tables|escape|limit|rlike|all|distinct|is';

const builtinConstants = 'true|false';

// See https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-syntax-show-functions.html
const builtinFunctions =
'avg|count|first|first_value|last|last_value|max|min|sum|kurtosis|mad|percentile|percentile_rank|skewness' +
'|stddev_pop|sum_of_squares|var_pop|histogram|case|coalesce|greatest|ifnull|iif|isnull|least|nullif|nvl' +
'|curdate|current_date|current_time|current_timestamp|curtime|dateadd|datediff|datepart|datetrunc|date_add' +
'|date_diff|date_part|date_trunc|day|dayname|dayofmonth|dayofweek|dayofyear|day_name|day_of_month|day_of_week' +
'|day_of_year|dom|dow|doy|hour|hour_of_day|idow|isodayofweek|isodow|isoweek|isoweekofyear|iso_day_of_week|iso_week_of_year' +
'|iw|iwoy|minute|minute_of_day|minute_of_hour|month|monthname|month_name|month_of_year|now|quarter|second|second_of_minute' +
'|timestampadd|timestampdiff|timestamp_add|timestamp_diff|today|week|week_of_year|year|abs|acos|asin|atan|atan2|cbrt' +
'|ceil|ceiling|cos|cosh|cot|degrees|e|exp|expm1|floor|log|log10|mod|pi|power|radians|rand|random|round|sign|signum|sin' +
'|sinh|sqrt|tan|truncate|ascii|bit_length|char|character_length|char_length|concat|insert|lcase|left|length|locate' +
'|ltrim|octet_length|position|repeat|replace|right|rtrim|space|substring|ucase|cast|convert|database|user|st_astext|st_aswkt' +
'|st_distance|st_geometrytype|st_geomfromtext|st_wkttosql|st_x|st_y|st_z|score';

// See https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-data-types.html
const dataTypes =
'null|boolean|byte|short|integer|long|double|float|half_float|scaled_float|keyword|text|binary|date|ip|object|nested|time' +
'|interval_year|interval_month|interval_day|interval_hour|interval_minute|interval_second|interval_year_to_month' +
'inteval_day_to_hour|interval_day_to_minute|interval_day_to_second|interval_hour_to_minute|interval_hour_to_second' +
'interval_minute_to_second|geo_point|geo_shape|shape';

const keywordMapper = this.createKeywordMapper(
{
keyword: [keywords, builtinFunctions, builtinConstants, dataTypes].join('|'),
},
'identifier',
true
);

this.$rules = {
start: [
{
token: 'comment',
regex: '--.*$',
},
{
token: 'comment',
start: '/\\*',
end: '\\*/',
},
{
token: 'string', // " string
regex: '".*?"',
},
{
token: 'constant', // ' string
regex: "'.*?'",
},
{
token: 'string', // ` string (apache drill)
regex: '`.*?`',
},
{
token: 'entity.name.function', // float
regex: '[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b',
},
{
token: keywordMapper,
regex: '[a-zA-Z_$][a-zA-Z0-9_$]*\\b',
},
{
token: 'keyword.operator',
regex: '⇐|<⇒|\\*|\\.|\\:\\:|\\+|\\-|\\/|\\/\\/|%|&|\\^|~|<|>|<=|=>|==|!=|<>|=',
},
{
token: 'paren.lparen',
regex: '[\\(]',
},
{
token: 'paren.rparen',
regex: '[\\)]',
},
{
token: 'text',
regex: '\\s+',
},
],
};
this.normalizeRules();
};

oop.inherits(ElasticsearchSqlHighlightRules, TextHighlightRules);
Loading

0 comments on commit f349d77

Please sign in to comment.