Skip to content

Commit

Permalink
Merge branch 'main' into #3371
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp authored Jul 24, 2024
2 parents 408a3af + aa90561 commit 7774ba8
Show file tree
Hide file tree
Showing 120 changed files with 4,525 additions and 551 deletions.
2 changes: 1 addition & 1 deletion .buildkite/ftr_oblt_stateful_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enabled:
- x-pack/test/api_integration/apis/synthetics/config.ts
- x-pack/test/api_integration/apis/slos/config.ts
- x-pack/test/api_integration/apis/uptime/config.ts
- x-pack/test/api_integration/apis/entity_manager/config.ts
- x-pack/test/apm_api_integration/basic/config.ts
- x-pack/test/apm_api_integration/cloud/config.ts
- x-pack/test/apm_api_integration/rules/config.ts
Expand All @@ -48,4 +49,3 @@ enabled:
- x-pack/test/observability_ai_assistant_functional/enterprise/config.ts
- x-pack/test/profiling_api_integration/cloud/config.ts
- x-pack/test/functional/apps/apm/config.ts

4 changes: 2 additions & 2 deletions .buildkite/scripts/steps/checks/yarn_deduplicate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set -euo pipefail
source .buildkite/scripts/common/util.sh

echo "--- Check yarn.lock for duplicated modules"
node scripts/yarn_deduplicate
node scripts/yarn_deduplicate && yarn kbn bootstrap

check_for_changed_files 'node scripts/yarn_deduplicate' false 'TO FIX: Run node '"'"'scripts/yarn_deduplicate && yarn kbn bootstrap'"'"' locally, or add an exception to src/dev/yarn_deduplicate/index.ts and then commit the changes and push to your branch'
check_for_changed_files 'node scripts/yarn_deduplicate' true 'TO FIX: Run node '"'"'scripts/yarn_deduplicate && yarn kbn bootstrap'"'"' locally, or add an exception to src/dev/yarn_deduplicate/index.ts and then commit the changes and push to your branch'
37 changes: 0 additions & 37 deletions docs/setup/upgrade/rollback-migration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,3 @@ POST _snapshot/my_repository/my_snapshot_2099.05.06/_restore
--------------------------------------------
<1> Exclude all indices and data streams from the restore operation to ensure that only the {kib} system indices included in the {kib} feature state will be restored.
. Start all {kib} instances on the older version you want to rollback to.

[float]
==== (Not supported) Roll back without a backup snapshot

WARNING: Rolling back without a backup snapshot is not supported and will be removed in a future version of {kib}.

. To make sure no {kib} instances are performing an upgrade migration, shut down all {kib} instances.
. {ref}/snapshots-take-snapshot.html[Take a snapshot] that includes the `kibana` feature state. By default, snapshots include the `kibana` feature state.
. Delete the version-specific indices created by the failed upgrade migration.
+
For example, to rollback from a failed upgrade
to v7.12.0, enter:
+
[source,sh]
--------------------------------------------
DELETE /.kibana_7.12.0_*,.kibana_task_manager_7.12.0_*
--------------------------------------------

. Inspect the output of `GET /_cat/aliases`.
+
If the `.kibana` or `.kibana_task_manager` aliases are missing, you must create them manually.
Find the latest index from the output of `GET /_cat/indices` and create the missing alias to point to the latest index.
For example, if the `.kibana` alias is missing, and the latest index is `.kibana_3`, create a new alias using:
+
[source,sh]
--------------------------------------------
POST /.kibana_3/_aliases/.kibana
--------------------------------------------

. To remove the write block from the roll back indices, enter:
+
[source,sh]
--------------------------------------------
PUT /.kibana,.kibana_task_manager/_settings {"index.blocks.write": false}
--------------------------------------------

. Start {kib} on the older version you want to roll back to.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class HapiResponseAdapter {
return response;
}

private toError(kibanaResponse: KibanaResponse<ResponseError | Buffer | stream.Readable>) {
private toError(kibanaResponse: KibanaResponse<ResponseError>) {
const { payload } = kibanaResponse;

// Special case for when we are proxying requests and want to enable streaming back error responses opaquely.
Expand Down Expand Up @@ -153,7 +153,12 @@ function getErrorMessage(payload?: ResponseError): string {
if (!payload) {
throw new Error('expected error message to be provided');
}
if (typeof payload === 'string') return payload;
if (typeof payload === 'string') {
return payload;
}
if (isStreamOrBuffer(payload)) {
throw new Error(`can't resolve error message from stream or buffer`);
}
// for ES response errors include nested error reason message. it doesn't contain sensitive data.
if (isElasticsearchResponseError(payload)) {
return `[${payload.message}]: ${
Expand All @@ -164,6 +169,10 @@ function getErrorMessage(payload?: ResponseError): string {
return getErrorMessage(payload.message);
}

function isStreamOrBuffer(payload: ResponseError): payload is stream.Stream | Buffer {
return Buffer.isBuffer(payload) || stream.isReadable(payload as stream.Readable);
}

function getErrorAttributes(payload?: ResponseError): ResponseErrorAttributes | undefined {
return typeof payload === 'object' && 'attributes' in payload ? payload.attributes : undefined;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/http/core-http-server/src/router/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export type ResponseErrorAttributes = Record<string, any>;
*/
export type ResponseError =
| string
| Buffer
| Stream
| Error
| {
message: string | Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import type { Stream } from 'stream';
import type {
CustomHttpResponseOptions,
HttpResponseOptions,
Expand Down Expand Up @@ -139,7 +138,7 @@ export interface KibanaErrorResponseFactory {
* Creates an error response with defined status code and payload.
* @param options - {@link CustomHttpResponseOptions} configures HTTP response headers, error message and other error details to pass to the client
*/
customError(options: CustomHttpResponseOptions<ResponseError | Buffer | Stream>): IKibanaResponse;
customError(options: CustomHttpResponseOptions<ResponseError>): IKibanaResponse;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { timeUnitsToSuggest } from '../../definitions/literals';
import { groupingFunctionDefinitions } from '../../definitions/grouping';
import * as autocomplete from '../autocomplete';
import type { ESQLCallbacks } from '../../shared/types';
import type { EditorContext } from '../types';
import type { EditorContext, SuggestionRawDefinition } from '../types';
import { TIME_SYSTEM_PARAMS } from '../factories';

export interface Integration {
Expand All @@ -28,6 +28,13 @@ export interface Integration {
}>;
}

export type PartialSuggestionWithText = Partial<SuggestionRawDefinition> & { text: string };

export const TIME_PICKER_SUGGESTION: PartialSuggestionWithText = {
text: '',
label: 'Choose from the time picker',
};

export const triggerCharacters = [',', '(', '=', ' '];

export const fields: Array<{ name: string; type: string; suggestedAs?: string }> = [
Expand Down Expand Up @@ -224,7 +231,7 @@ export function getLiteralsByType(_type: string | string[]) {

export function getDateLiteralsByFieldType(_requestedType: string | string[]) {
const requestedType = Array.isArray(_requestedType) ? _requestedType : [_requestedType];
return requestedType.includes('date') ? TIME_SYSTEM_PARAMS : [];
return requestedType.includes('date') ? [TIME_PICKER_SUGGESTION, ...TIME_SYSTEM_PARAMS] : [];
}

export function createCustomCallbackMocks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import {
createCustomCallbackMocks,
createCompletionContext,
getPolicyFields,
PartialSuggestionWithText,
TIME_PICKER_SUGGESTION,
} from './__tests__/helpers';

describe('autocomplete', () => {
type TestArgs = [
string,
string[],
Array<string | PartialSuggestionWithText>,
string?,
number?,
Parameters<typeof createCustomCallbackMocks>?
Expand All @@ -39,7 +41,7 @@ describe('autocomplete', () => {
const _testSuggestionsFn = (
{ only, skip }: { only?: boolean; skip?: boolean } = {},
statement: string,
expected: string[],
expected: Array<string | PartialSuggestionWithText>,
triggerCharacter?: string,
_offset?: number,
customCallbacksArgs: Parameters<typeof createCustomCallbackMocks> = [
Expand All @@ -66,10 +68,20 @@ describe('autocomplete', () => {
callbackMocks
);

const sortedSuggestions = suggestions.map((suggestion) => suggestion.text).sort();
const sortedExpected = expected.sort();
const sortedSuggestionTexts = suggestions.map((suggestion) => suggestion.text).sort();
const sortedExpectedTexts = expected
.map((suggestion) => (typeof suggestion === 'string' ? suggestion : suggestion.text ?? ''))
.sort();

expect(sortedSuggestions).toEqual(sortedExpected);
expect(sortedSuggestionTexts).toEqual(sortedExpectedTexts);
const expectedNonStringSuggestions = expected.filter(
(suggestion) => typeof suggestion !== 'string'
) as PartialSuggestionWithText[];

for (const expectedSuggestion of expectedNonStringSuggestions) {
const suggestion = suggestions.find((s) => s.text === expectedSuggestion.text);
expect(suggestion).toEqual(expect.objectContaining(expectedSuggestion));
}
});
};

Expand Down Expand Up @@ -755,28 +767,30 @@ describe('autocomplete', () => {

const suggestedConstants = param.literalSuggestions || param.literalOptions;

const addCommaIfRequired = (s: string | PartialSuggestionWithText) => {
// don't add commas to the empty string or if there are no more required args
if (!requiresMoreArgs || s === '' || (typeof s === 'object' && s.text === '')) {
return s;
}
return typeof s === 'string' ? `${s},` : { ...s, text: `${s.text},` };
};

testSuggestions(
`from a | eval ${fn.name}(${Array(i).fill('field').join(', ')}${i ? ',' : ''} )`,
suggestedConstants?.length
? suggestedConstants.map((option) => `"${option}"${requiresMoreArgs ? ',' : ''}`)
: [
...getDateLiteralsByFieldType(
getTypesFromParamDefs(acceptsFieldParamDefs)
).map((l) => (requiresMoreArgs ? `${l},` : l)),
...getFieldNamesByType(getTypesFromParamDefs(acceptsFieldParamDefs)).map(
(f) => (requiresMoreArgs ? `${f},` : f)
),
...getDateLiteralsByFieldType(getTypesFromParamDefs(acceptsFieldParamDefs)),
...getFieldNamesByType(getTypesFromParamDefs(acceptsFieldParamDefs)),
...getFunctionSignaturesByReturnType(
'eval',
getTypesFromParamDefs(acceptsFieldParamDefs),
{ evalMath: true },
undefined,
[fn.name]
).map((l) => (requiresMoreArgs ? `${l},` : l)),
...getLiteralsByType(getTypesFromParamDefs(constantOnlyParamDefs)).map((d) =>
requiresMoreArgs ? `${d},` : d
),
],
...getLiteralsByType(getTypesFromParamDefs(constantOnlyParamDefs)),
].map(addCommaIfRequired),
' '
);
testSuggestions(
Expand All @@ -786,23 +800,17 @@ describe('autocomplete', () => {
suggestedConstants?.length
? suggestedConstants.map((option) => `"${option}"${requiresMoreArgs ? ',' : ''}`)
: [
...getDateLiteralsByFieldType(
getTypesFromParamDefs(acceptsFieldParamDefs)
).map((l) => (requiresMoreArgs ? `${l},` : l)),
...getFieldNamesByType(getTypesFromParamDefs(acceptsFieldParamDefs)).map(
(f) => (requiresMoreArgs ? `${f},` : f)
),
...getDateLiteralsByFieldType(getTypesFromParamDefs(acceptsFieldParamDefs)),
...getFieldNamesByType(getTypesFromParamDefs(acceptsFieldParamDefs)),
...getFunctionSignaturesByReturnType(
'eval',
getTypesFromParamDefs(acceptsFieldParamDefs),
{ evalMath: true },
undefined,
[fn.name]
).map((l) => (requiresMoreArgs ? `${l},` : l)),
...getLiteralsByType(getTypesFromParamDefs(constantOnlyParamDefs)).map((d) =>
requiresMoreArgs ? `${d},` : d
),
],
...getLiteralsByType(getTypesFromParamDefs(constantOnlyParamDefs)),
].map(addCommaIfRequired),
' '
);
}
Expand Down Expand Up @@ -860,12 +868,13 @@ describe('autocomplete', () => {
testSuggestions(
'from a | eval var0=date_trunc()',
[
...TIME_SYSTEM_PARAMS.map((t) => `${t},`),
...[...TIME_SYSTEM_PARAMS].map((t) => `${t},`),
...getLiteralsByType('time_literal').map((t) => `${t},`),
...getFunctionSignaturesByReturnType('eval', 'date', { evalMath: true }, undefined, [
'date_trunc',
]).map((t) => `${t},`),
...getFieldNamesByType('date').map((t) => `${t},`),
TIME_PICKER_SUGGESTION,
],
'('
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,39 @@ export function getCompatibleLiterals(commandName: string, types: string[], name
}

export function getDateLiterals() {
return buildConstantsDefinitions(
TIME_SYSTEM_PARAMS,
i18n.translate('kbn-esql-validation-autocomplete.esql.autocomplete.namedParamDefinition', {
defaultMessage: 'Named parameter',
}),
'1A'
);
return [
...buildConstantsDefinitions(
TIME_SYSTEM_PARAMS,
i18n.translate('kbn-esql-validation-autocomplete.esql.autocomplete.namedParamDefinition', {
defaultMessage: 'Named parameter',
}),
'1A'
),
{
label: i18n.translate(
'kbn-esql-validation-autocomplete.esql.autocomplete.chooseFromTimePickerLabel',
{
defaultMessage: 'Choose from the time picker',
}
),
text: '',
kind: 'Issue',
detail: i18n.translate(
'kbn-esql-validation-autocomplete.esql.autocomplete.chooseFromTimePicker',
{
defaultMessage: 'Click to choose',
}
),
sortText: '1A',
command: {
id: 'esql.timepicker.choose',
title: i18n.translate(
'kbn-esql-validation-autocomplete.esql.autocomplete.chooseFromTimePicker',
{
defaultMessage: 'Click to choose',
}
),
},
} as SuggestionRawDefinition,
];
}
Loading

0 comments on commit 7774ba8

Please sign in to comment.