Skip to content

Commit

Permalink
Merge branch 'main' into lens-flaky-test
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored May 11, 2022
2 parents 4d62d31 + 6527391 commit 882e75d
Show file tree
Hide file tree
Showing 106 changed files with 3,796 additions and 681 deletions.
13 changes: 11 additions & 2 deletions docs/api/alerting/create_rule.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@

Create {kib} rules.

WARNING: This API supports <<token-api-authentication>> only.

[[create-rule-api-request]]
==== Request

`POST <kibana host>:<port>/api/alerting/rule/<id>`

`POST <kibana host>:<port>/s/<space_id>/api/alerting/rule/<id>`

==== {api-description-title}

[WARNING]
====
* This API supports only
<<token-api-authentication,token-based authentication>>.
* When you create a rule, it identifies which roles you have at that point in time.
Thereafter, when the rule performs queries, it uses those security privileges.
If a user with different privileges updates the rule, its behavior might change.
====

[[create-rule-api-path-params]]
==== Path parameters

Expand Down
14 changes: 12 additions & 2 deletions docs/api/alerting/update_rule.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@

Update the attributes for an existing rule.

WARNING: This API supports <<token-api-authentication>> only.

[[update-rule-api-request]]
==== Request

`PUT <kibana host>:<port>/api/alerting/rule/<id>`

`PUT <kibana host>:<port>/s/<space_id>/api/alerting/rule/<id>`

==== {api-description-title}

[WARNING]
====
* This API supports only
<<token-api-authentication,token-based authentication>>.
* When you update a rule, it identifies which roles you have at that point in time.
Thereafter, when the rule performs queries, it uses those security privileges.
If you have different privileges than the user that created or most recently
updated the rule, you might change its behavior.
====

[[update-rule-api-path-params]]
==== Path parameters

Expand Down
2 changes: 1 addition & 1 deletion docs/setup/upgrade/resolving-migration-failures.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Upgrade migrations fail because routing allocation is disabled or restricted (`c

[source,sh]
--------------------------------------------
Unable to complete saved object migrations for the [.kibana] index: [unsupported_cluster_routing_allocation] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue. To proceed, please remove the cluster routing allocation settings with PUT /_cluster/settings {"transient": {"cluster.routing.allocation.enable": null}, "persistent": {"cluster.routing.allocation.enable": null}}
Unable to complete saved object migrations for the [.kibana] index: [incompatible_cluster_routing_allocation] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue. To proceed, please remove the cluster routing allocation settings with PUT /_cluster/settings {"transient": {"cluster.routing.allocation.enable": null}, "persistent": {"cluster.routing.allocation.enable": null}}
--------------------------------------------

To get around the issue, remove the transient and persisted routing allocation settings:
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ pageLoadAssetSize:
eventAnnotation: 19334
screenshotting: 22870
synthetics: 40958
expressionXY: 29000
expressionXY: 30000
kibanaUsageCollection: 16463
8 changes: 6 additions & 2 deletions src/core/server/saved_objects/migrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ index.

### New control state
1. Two conditions have to be met before migrations begin:
1. If replica allocation is set as a persistent or transient setting to "perimaries", "new_primaries" or "none" fail the migration. Without replica allocation enabled or not set to 'all', the migration will timeout when waiting for index yellow status before bulk indexing. The check only considers persistent and transient settings and does not take static configuration in `elasticsearch.yml` into account. If `cluster.routing.allocation.enable` is configured in `elaticsearch.yml` and not set to the default of 'all', the migration will timeout. Static settings can only be returned from the `nodes/info` API.
`FATAL`
1. The Elasticsearch shard allocation cluster setting `cluster.routing.allocation.enable` needs to be unset or set to 'all'. When set to 'primaries', 'new_primaries' or 'none', the migration will timeout when waiting for index yellow status before bulk indexing because the replica cannot be allocated.

As per the Elasticsearch docs https://www.elastic.co/guide/en/elasticsearch/reference/8.2/restart-cluster.html#restart-cluster-rolling when Cloud performs a rolling restart such as during an upgrade, it will temporarily disable shard allocation. Kibana therefore keeps retrying the INIT step to wait for shard allocation to be enabled again.

The check only considers persistent and transient settings and does not take static configuration in `elasticsearch.yml` into account since there are no known use cases for doing so. If `cluster.routing.allocation.enable` is configured in `elaticsearch.yml` and not set to the default of 'all', the migration will timeout. Static settings can only be returned from the `nodes/info` API.
`INIT`

2. If `.kibana` is pointing to an index that belongs to a later version of
Kibana .e.g. a 7.11.0 instance found the `.kibana` alias pointing to
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/saved_objects/migrations/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export {
export type { RetryableEsClientError };

// actions/* imports
export type { InitActionParams, UnsupportedClusterRoutingAllocation } from './initialize_action';
export type { InitActionParams, IncompatibleClusterRoutingAllocation } from './initialize_action';
export { initAction } from './initialize_action';

export type { FetchIndexResponse, FetchIndicesParams } from './fetch_indices';
Expand Down Expand Up @@ -87,7 +87,7 @@ export type {
export { updateAndPickupMappings } from './update_and_pickup_mappings';

import type { UnknownDocsFound } from './check_for_unknown_docs';
import type { UnsupportedClusterRoutingAllocation } from './initialize_action';
import type { IncompatibleClusterRoutingAllocation } from './initialize_action';

export type {
CheckForUnknownDocsParams,
Expand Down Expand Up @@ -151,7 +151,7 @@ export interface ActionErrorTypeMap {
documents_transform_failed: DocumentsTransformFailed;
request_entity_too_large_exception: RequestEntityTooLargeException;
unknown_docs_found: UnknownDocsFound;
unsupported_cluster_routing_allocation: UnsupportedClusterRoutingAllocation;
incompatible_cluster_routing_allocation: IncompatibleClusterRoutingAllocation;
index_not_yellow_timeout: IndexNotYellowTimeout;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ export interface InitActionParams {
indices: string[];
}

export interface UnsupportedClusterRoutingAllocation {
type: 'unsupported_cluster_routing_allocation';
message: string;
export interface IncompatibleClusterRoutingAllocation {
type: 'incompatible_cluster_routing_allocation';
}

export const checkClusterRoutingAllocationEnabledTask =
({
client,
}: {
client: ElasticsearchClient;
}): TaskEither.TaskEither<RetryableEsClientError | UnsupportedClusterRoutingAllocation, {}> =>
}): TaskEither.TaskEither<RetryableEsClientError | IncompatibleClusterRoutingAllocation, {}> =>
() => {
return client.cluster
.getSettings({
Expand All @@ -54,9 +53,7 @@ export const checkClusterRoutingAllocationEnabledTask =

if (!clusterRoutingAllocationEnabledIsAll) {
return Either.left({
type: 'unsupported_cluster_routing_allocation' as const,
message:
'[unsupported_cluster_routing_allocation] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue.',
type: 'incompatible_cluster_routing_allocation' as const,
});
} else {
return Either.right({});
Expand All @@ -69,7 +66,7 @@ export const initAction = ({
client,
indices,
}: InitActionParams): TaskEither.TaskEither<
RetryableEsClientError | UnsupportedClusterRoutingAllocation,
RetryableEsClientError | IncompatibleClusterRoutingAllocation,
FetchIndexResponse
> => {
return pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ describe('migration actions', () => {
Object {
"_tag": "Left",
"left": Object {
"message": "[unsupported_cluster_routing_allocation] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue.",
"type": "unsupported_cluster_routing_allocation",
"type": "incompatible_cluster_routing_allocation",
},
}
`);
Expand All @@ -188,8 +187,7 @@ describe('migration actions', () => {
Object {
"_tag": "Left",
"left": Object {
"message": "[unsupported_cluster_routing_allocation] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue.",
"type": "unsupported_cluster_routing_allocation",
"type": "incompatible_cluster_routing_allocation",
},
}
`);
Expand All @@ -209,8 +207,7 @@ describe('migration actions', () => {
Object {
"_tag": "Left",
"left": Object {
"message": "[unsupported_cluster_routing_allocation] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue.",
"type": "unsupported_cluster_routing_allocation",
"type": "incompatible_cluster_routing_allocation",
},
}
`);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ElasticsearchClient } from '../../../elasticsearch';
import { LogRecord } from '@kbn/logging';
import { retryAsync } from '../test_helpers/retry_async';

const logFilePath = Path.join(__dirname, 'unsupported_cluster_routing_allocation.log');
const logFilePath = Path.join(__dirname, 'incompatible_cluster_routing_allocation.log');

async function removeLogFile() {
// ignore errors if it doesn't exist
Expand All @@ -27,7 +27,11 @@ const { startES } = kbnTestServer.createTestServers({
settings: {
es: {
license: 'basic',
dataArchive: Path.join(__dirname, 'archives', '7.7.2_xpack_100k_obj.zip'),
dataArchive: Path.join(
__dirname,
'archives',
'8.0.0_v1_migrations_sample_data_saved_objects.zip'
),
},
},
});
Expand Down Expand Up @@ -77,14 +81,14 @@ let esServer: kbnTestServer.TestElasticsearchUtils;
async function updateRoutingAllocations(
esClient: ElasticsearchClient,
settingType: string = 'persistent',
value: string = 'none'
value: string | null
) {
return await esClient.cluster.putSettings({
[settingType]: { cluster: { routing: { allocation: { enable: value } } } },
});
}

describe('unsupported_cluster_routing_allocation', () => {
describe('incompatible_cluster_routing_allocation', () => {
let client: ElasticsearchClient;
let root: Root;

Expand All @@ -97,7 +101,7 @@ describe('unsupported_cluster_routing_allocation', () => {
await esServer.stop();
});

it('fails with a descriptive message when persistent replica allocation is not enabled', async () => {
it('retries the INIT action with a descriptive message when cluster settings are incompatible', async () => {
const initialSettings = await client.cluster.getSettings({ flat_settings: true });

expect(getClusterRoutingAllocations(initialSettings)).toBe(true);
Expand All @@ -108,48 +112,53 @@ describe('unsupported_cluster_routing_allocation', () => {

expect(getClusterRoutingAllocations(updatedSettings)).toBe(false);

// now try to start Kibana
// Start Kibana
root = createKbnRoot();
await root.preboot();
await root.setup();

await expect(root.start()).rejects.toThrowError(
/Unable to complete saved object migrations for the \[\.kibana.*\] index: \[unsupported_cluster_routing_allocation\] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue\. To proceed, please remove the cluster routing allocation settings with PUT \/_cluster\/settings {\"transient\": {\"cluster\.routing\.allocation\.enable\": null}, \"persistent\": {\"cluster\.routing\.allocation\.enable\": null}}\. Refer to https:\/\/www.elastic.co\/guide\/en\/kibana\/master\/resolve-migrations-failures.html#routing-allocation-disabled for more information on how to resolve the issue\./
);
root.start();

// Wait for the INIT -> INIT action retry
await retryAsync(
async () => {
const logFileContent = await fs.readFile(logFilePath, 'utf-8');
const records = logFileContent
.split('\n')
.filter(Boolean)
.map((str) => JSON5.parse(str)) as LogRecord[];

// Wait for logs of the second failed attempt to be sure we're correctly incrementing retries
expect(
records.find((rec) =>
/^Unable to complete saved object migrations for the \[\.kibana.*\] index: \[unsupported_cluster_routing_allocation\] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue\./.test(
rec.message
rec.message.includes(
`Action failed with '[incompatible_cluster_routing_allocation] Incompatible Elasticsearch cluster settings detected. Remove the persistent and transient Elasticsearch cluster setting 'cluster.routing.allocation.enable' or set it to a value of 'all' to allow migrations to proceed. Refer to https://www.elastic.co/guide/en/kibana/master/resolve-migrations-failures.html#routing-allocation-disabled for more information on how to resolve the issue.'. Retrying attempt 2 in 4 seconds.`
)
)
).toBeDefined();
},
{ retryAttempts: 10, retryDelayMs: 200 }
{ retryAttempts: 20, retryDelayMs: 500 }
);
});

it('fails with a descriptive message when persistent replica allocation is set to "primaries"', async () => {
await updateRoutingAllocations(client, 'persistent', 'primaries');
// Reset the cluster routing allocation settings
await updateRoutingAllocations(client, 'persistent', null);

const updatedSettings = await client.cluster.getSettings({ flat_settings: true });

expect(getClusterRoutingAllocations(updatedSettings)).toBe(false);

// now try to start Kibana
root = createKbnRoot();
await root.preboot();
await root.setup();
// Wait for migrations to succeed
await retryAsync(
async () => {
const logFileContent = await fs.readFile(logFilePath, 'utf-8');
const records = logFileContent
.split('\n')
.filter(Boolean)
.map((str) => JSON5.parse(str)) as LogRecord[];

await expect(root.start()).rejects.toThrowError(
/Unable to complete saved object migrations for the \[\.kibana.*\] index: \[unsupported_cluster_routing_allocation\] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue\. To proceed, please remove the cluster routing allocation settings with PUT \/_cluster\/settings {\"transient\": {\"cluster\.routing\.allocation\.enable\": null}, \"persistent\": {\"cluster\.routing\.allocation\.enable\": null}}\. Refer to https:\/\/www.elastic.co\/guide\/en\/kibana\/master\/resolve-migrations-failures.html#routing-allocation-disabled for more information on how to resolve the issue\./
expect(
records.find((rec) => rec.message.includes('MARK_VERSION_INDEX_READY -> DONE'))
).toBeDefined();
},
{ retryAttempts: 100, retryDelayMs: 500 }
);

await root.shutdown();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('migration v2', () => {
await new Promise((resolve) => setTimeout(resolve, 10000));
});

it.skip('migrates the documents to the highest version', async () => {
it('migrates the documents to the highest version', async () => {
const migratedIndex = `.kibana_${pkg.version}_001`;
const { startES } = kbnTestServer.createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('migration v2', () => {
expect(migratedDocs.length).toBe(1);
const [doc] = migratedDocs;
expect(doc._source.migrationVersion.foo).toBe('7.14.0');
expect(doc._source.coreMigrationVersion).toBe('8.0.0');
expect(doc._source.coreMigrationVersion).toBe(pkg.version);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import {
extractUnknownDocFailureReason,
fatalReasonClusterRoutingAllocationUnsupported,
fatalReasonDocumentExceedsMaxBatchSizeBytes,
} from './extract_errors';

Expand Down Expand Up @@ -55,18 +54,3 @@ describe('fatalReasonDocumentExceedsMaxBatchSizeBytes', () => {
);
});
});

describe('fatalReasonClusterRoutingAllocationUnsupported', () => {
it('generates the correct error message', () => {
const errorMessages = fatalReasonClusterRoutingAllocationUnsupported({
errorMessage: '[some-error] message',
docSectionLink: 'linkToDocsSection',
});
expect(errorMessages.fatalReason).toMatchInlineSnapshot(
`"[some-error] message To proceed, please remove the cluster routing allocation settings with PUT /_cluster/settings {\\"transient\\": {\\"cluster.routing.allocation.enable\\": null}, \\"persistent\\": {\\"cluster.routing.allocation.enable\\": null}}. Refer to linkToDocsSection for more information on how to resolve the issue."`
);
expect(errorMessages.logsErrorMessage).toMatchInlineSnapshot(
`"[some-error] message Ensure that the persistent and transient Elasticsearch configuration option 'cluster.routing.allocation.enable' is not set or set it to a value of 'all'. Refer to linkToDocsSection for more information on how to resolve the issue."`
);
});
});
15 changes: 0 additions & 15 deletions src/core/server/saved_objects/migrations/model/extract_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,3 @@ export const fatalReasonDocumentExceedsMaxBatchSizeBytes = ({
maxBatchSizeBytes: number;
}) =>
`The document with _id "${_id}" is ${docSizeBytes} bytes which exceeds the configured maximum batch size of ${maxBatchSizeBytes} bytes. To proceed, please increase the 'migrations.maxBatchSizeBytes' Kibana configuration option and ensure that the Elasticsearch 'http.max_content_length' configuration option is set to an equal or larger value.`;

/**
* Constructs migration failure message and logs message strings when an unsupported cluster routing allocation is configured.
* The full errorMessage is "[unsupported_cluster_routing_allocation] The elasticsearch cluster has cluster routing allocation incorrectly set for migrations to continue."
*/
export const fatalReasonClusterRoutingAllocationUnsupported = ({
errorMessage,
docSectionLink,
}: {
errorMessage: string;
docSectionLink: string;
}) => ({
fatalReason: `${errorMessage} To proceed, please remove the cluster routing allocation settings with PUT /_cluster/settings {"transient": {"cluster.routing.allocation.enable": null}, "persistent": {"cluster.routing.allocation.enable": null}}. Refer to ${docSectionLink} for more information on how to resolve the issue.`,
logsErrorMessage: `${errorMessage} Ensure that the persistent and transient Elasticsearch configuration option 'cluster.routing.allocation.enable' is not set or set it to a value of 'all'. Refer to ${docSectionLink} for more information on how to resolve the issue.`,
});
Loading

0 comments on commit 882e75d

Please sign in to comment.