Skip to content

Commit

Permalink
Merge branch 'main' into fix-lens-in-markdown-serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Sep 1, 2023
2 parents f645474 + 9de752d commit fa203b0
Show file tree
Hide file tree
Showing 177 changed files with 12,696 additions and 3,802 deletions.
5 changes: 5 additions & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ xpack.alerting.rules.run.ruleTypeOverrides:
xpack.alerting.rules.minimumScheduleInterval.enforce: true
xpack.actions.run.maxAttempts: 10

# Disables ESQL in advanced settings (hides it from the UI)
uiSettings:
overrides:
discover:enableESQL: false

# Task Manager
xpack.task_manager.allow_reading_invalid_state: false

Expand Down
4 changes: 2 additions & 2 deletions docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ in the current data view is used.
The columns that appear by default on the *Discover* page. The default is
`_source`.

[[discover:enableSql]]`discover:enableSql`::
experimental[] Allows SQL queries for search.
[[discover:enableESQL]]`discover:enableESQL`::
experimental[] Allows ES|QL queries for search.

[[discover-max-doc-fields-displayed]]`discover:maxDocFieldsDisplayed`::
Specifies the maximum number of fields to show in the document column of the *Discover* table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export {
type IPreflightCheckHelper,
type PreflightCheckNamespacesParams,
type PreflightCheckNamespacesResult,
type PreflightDocParams,
type PreflightDocResult,
type PreflightNSParams,
type PreflightNSResult,
} from './preflight_check';

export interface RepositoryHelpers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export class PreflightCheckHelper {
if (!this.registry.isMultiNamespace(type)) {
throw new Error(`Cannot make preflight get request for non-multi-namespace type '${type}'.`);
}

const { body, statusCode, headers } = await this.client.get<SavedObjectsRawDocSource>(
{
id: this.serializer.generateRawId(undefined, type, id),
Expand Down Expand Up @@ -151,8 +150,83 @@ export class PreflightCheckHelper {
};
}

/**
* Pre-flight check fetching the document regardless of its namespace type for update.
*/
public async preflightGetDocForUpdate({
type,
id,
namespace,
}: PreflightDocParams): Promise<PreflightDocResult> {
const { statusCode, body, headers } = await this.client.get<SavedObjectsRawDocSource>(
{
id: this.serializer.generateRawId(namespace, type, id),
index: this.getIndexForType(type),
},
{ ignore: [404], meta: true }
);

// checking if the 404 is from Elasticsearch
if (isNotFoundFromUnsupportedServer({ statusCode, headers })) {
throw SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError(type, id);
}

const indexFound = statusCode !== 404;
if (indexFound && isFoundGetResponse(body)) {
return {
checkDocFound: 'found',
rawDocSource: body,
};
}

return {
checkDocFound: 'not_found',
};
}

/**
* Pre-flight check to ensure that a multi-namespace object exists in the current namespace for update API.
*/
public preflightCheckNamespacesForUpdate({
type,
namespace,
initialNamespaces,
preflightDocResult,
}: PreflightNSParams): PreflightNSResult {
const { checkDocFound, rawDocSource } = preflightDocResult;
if (!this.registry.isMultiNamespace(type)) {
return {
checkSkipped: true,
};
}

const namespaces = initialNamespaces ?? [SavedObjectsUtils.namespaceIdToString(namespace)];

if (checkDocFound === 'found' && rawDocSource !== undefined) {
if (!rawDocExistsInNamespaces(this.registry, rawDocSource, namespaces)) {
return { checkResult: 'found_outside_namespace', checkSkipped: false };
}
return {
checkResult: 'found_in_namespace',
savedObjectNamespaces:
initialNamespaces ?? getSavedObjectNamespaces(namespace, rawDocSource),
rawDocSource,
checkSkipped: false,
};
}

return {
checkResult: 'not_found',
savedObjectNamespaces: initialNamespaces ?? getSavedObjectNamespaces(namespace),
checkSkipped: false,
};
}

/**
* Pre-flight check to ensure that an upsert which would create a new object does not result in an alias conflict.
*
* If an upsert would result in the creation of a new object, we need to check for alias conflicts too.
* This takes an extra round trip to Elasticsearch, but this won't happen often.
*/
public async preflightCheckForUpsertAliasConflict(
type: string,
Expand Down Expand Up @@ -189,6 +263,39 @@ export interface PreflightCheckNamespacesParams {
initialNamespaces?: string[];
}

/**
* @internal
*/
export interface PreflightNSParams {
/** The object type to fetch */
type: string;
/** The object ID to fetch */
id: string;
/** The current space */
namespace: string | undefined;
/** Optional; for an object that is being created, this specifies the initial namespace(s) it will exist in (overriding the current space) */
initialNamespaces?: string[];
/** Optional; for a pre-fetched object */
preflightDocResult: PreflightDocResult;
}

/**
* @internal
*/
export interface PreflightNSResult {
/** If the object exists, and whether or not it exists in the current space */
checkResult?: 'not_found' | 'found_in_namespace' | 'found_outside_namespace';
/**
* What namespace(s) the object should exist in, if it needs to be created; practically speaking, this will never be undefined if
* checkResult == not_found or checkResult == found_in_namespace
*/
savedObjectNamespaces?: string[];
/** The source of the raw document, if the object already exists */
rawDocSource?: GetResponseFound<SavedObjectsRawDocSource>;
/** Indicates if the namespaces check is called or not. Non-multinamespace types are not shareable */
checkSkipped?: boolean;
}

/**
* @internal
*/
Expand All @@ -203,3 +310,30 @@ export interface PreflightCheckNamespacesResult {
/** The source of the raw document, if the object already exists */
rawDocSource?: GetResponseFound<SavedObjectsRawDocSource>;
}

/**
* @internal
*/
export interface PreflightDocParams {
/** The object type to fetch */
type: string;
/** The object ID to fetch */
id: string;
/** The current space */
namespace: string | undefined;
/**
* optional migration version compatibility.
* {@link SavedObjectsRawDocParseOptions.migrationVersionCompatibility}
*/
migrationVersionCompatibility?: 'compatible' | 'raw';
}

/**
* @internal
*/
export interface PreflightDocResult {
/** If the object exists, and whether or not it exists in the current space */
checkDocFound: 'not_found' | 'found';
/** The source of the raw document, if the object already exists in the server's version (unsafe to use) */
rawDocSource?: GetResponseFound<SavedObjectsRawDocSource>;
}
Loading

0 comments on commit fa203b0

Please sign in to comment.