Skip to content

Commit

Permalink
Merge branch 'main' into carlosdelest/update-sparse-vector-icon
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest authored Oct 23, 2023
2 parents 8607e21 + 2384636 commit bc5d5d6
Show file tree
Hide file tree
Showing 36 changed files with 562 additions and 217 deletions.
11 changes: 11 additions & 0 deletions docs/api/uptime-api.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[uptime-apis]]
== Uptime APIs

The following APIs are available for Uptime.

* <<get-settings-api, Get settings API>> to get a settings

* <<update-settings-api, Update settings API>> to update the attributes for existing settings

include::uptime/get-settings.asciidoc[leveloffset=+1]
include::uptime/update-settings.asciidoc[leveloffset=+1]
39 changes: 39 additions & 0 deletions docs/api/uptime/get-settings.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[[get-settings-api]]
== Get settings API
++++
<titleabbrev>Get settings</titleabbrev>
++++

Retrieve uptime settings existing settings.

[[get-settings-api-request]]
=== {api-request-title}

`GET <kibana host>:<port>/api/uptime/settings`

`GET <kibana host>:<port>/s/<space_id>/api/uptime/settings`

=== {api-prereq-title}

You must have `read` privileges for the *uptime* feature in *{observability}* section of the
<<kibana-feature-privileges,{kib} feature privileges>>.

The API returns the following:

[source,sh]
--------------------------------------------------
{
"heartbeatIndices": "heartbeat-8*",
"certExpirationThreshold": 30,
"certAgeThreshold": 730,
"defaultConnectors": [
"08990f40-09c5-11ee-97ae-912b222b13d4",
"db25f830-2318-11ee-9391-6b0c030836d6"
],
"defaultEmail": {
"to": [],
"cc": [],
"bcc": []
}
}
--------------------------------------------------
117 changes: 117 additions & 0 deletions docs/api/uptime/update-settings.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
[[update-settings-api]]
== Update settings API
++++
<titleabbrev>Update settings</titleabbrev>
++++

Updates uptime settings attributes like heartbeatIndices, certExpirationThreshold, certAgeThreshold, defaultConnectors or defaultEmail

=== {api-request-title}

`PUT <kibana host>:<port>/api/uptime/settings`

`PUT <kibana host>:<port>/s/<space_id>/api/uptime/settings`

=== {api-prereq-title}

You must have `all` privileges for the *uptime* feature in *{observability}* section of the
<<kibana-feature-privileges,{kib} feature privileges>>.

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

`space_id`::
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.

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

A partial update is supported, provided settings keys will be merged with existing settings.

`heartbeatIndices`::
(Optional, string) index pattern string to be used within uptime app/alerts to query heartbeat data. Defaults to `heartbeat-*`.


`certExpirationThreshold`::
(Optional, number) Number of days before a certificate expires to trigger an alert. Defaults to `30`.

`certAgeThreshold`::
(Optional, number) Number of days after a certificate is created to trigger an alert. Defaults to `730`.

`defaultConnectors`::
(Optional, array) List of connector IDs to be used as default connectors for new alerts. Defaults to `[]`.

`defaultEmail`::
(Optional, object) Default email configuration for new alerts. Defaults to `{"to": [], "cc": [], "bcc": []}`.

[[settings-api-update-example]]
==== Example

[source,sh]
--------------------------------------------------
PUT api/uptime/settings
{
"heartbeatIndices": "heartbeat-8*",
"certExpirationThreshold": 30,
"certAgeThreshold": 730,
"defaultConnectors": [
"08990f40-09c5-11ee-97ae-912b222b13d4",
"db25f830-2318-11ee-9391-6b0c030836d6"
],
"defaultEmail": {
"to": [],
"cc": [],
"bcc": []
}
}
--------------------------------------------------

The API returns the following:

[source,json]
--------------------------------------------------
{
"heartbeatIndices": "heartbeat-8*",
"certExpirationThreshold": 30,
"certAgeThreshold": 730,
"defaultConnectors": [
"08990f40-09c5-11ee-97ae-912b222b13d4",
"db25f830-2318-11ee-9391-6b0c030836d6"
],
"defaultEmail": {
"to": [],
"cc": [],
"bcc": []
}
}
--------------------------------------------------
[[settings-api-partial-update-example]]
==== Partial update example

[source,sh]
--------------------------------------------------
PUT api/uptime/settings
{
"heartbeatIndices": "heartbeat-8*",
}
--------------------------------------------------

The API returns the following:

[source,json]
--------------------------------------------------
{
"heartbeatIndices": "heartbeat-8*",
"certExpirationThreshold": 30,
"certAgeThreshold": 730,
"defaultConnectors": [
"08990f40-09c5-11ee-97ae-912b222b13d4",
"db25f830-2318-11ee-9391-6b0c030836d6"
],
"defaultEmail": {
"to": [],
"cc": [],
"bcc": []
}
}
--------------------------------------------------
1 change: 1 addition & 0 deletions docs/user/api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ include::{kib-repo-dir}/api/osquery-manager.asciidoc[]
include::{kib-repo-dir}/api/short-urls.asciidoc[]
include::{kib-repo-dir}/api/task-manager/health.asciidoc[]
include::{kib-repo-dir}/api/upgrade-assistant.asciidoc[]
include::{kib-repo-dir}/api/uptime-api.asciidoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { createTestServers } from '@kbn/core-test-helpers-kbn-server';
import { MIGRATION_CLIENT_OPTIONS } from '@kbn/core-saved-objects-migration-server-internal';
import { runActionTestSuite } from './actions_test_suite';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export const runActionTestSuite = ({
{ _source: { title: 'doc 3' } },
{ _source: { title: 'saved object 4', type: 'another_unused_type' } },
{ _source: { title: 'f-agent-event 5', type: 'f_agent_event' } },
{ _source: { title: new Array(1000).fill('a').join(), type: 'large' } }, // "large" saved object
{
_source: { title: new Array(1000).fill('a').join(), type: 'large' },
}, // "large" saved objects
] as unknown as SavedObjectsRawDoc[];
await bulkOverwriteTransformedDocuments({
client,
Expand All @@ -113,6 +115,27 @@ export const runActionTestSuite = ({
refresh: 'wait_for',
})();

await createIndex({
client,
indexName: 'existing_index_with_100k_docs',
aliases: ['existing_index_with_100k_docs_alias'],
esCapabilities,
mappings: {
dynamic: true,
properties: {},
},
})();
const docs100k = new Array(100000).fill({
_source: { title: new Array(1000).fill('a').join(), type: 'large' },
}) as unknown as SavedObjectsRawDoc[]; // 100k "large" saved objects

await bulkOverwriteTransformedDocuments({
client,
index: 'existing_index_with_100k_docs',
operations: docs100k.map((doc) => createBulkIndexOperationTuple(doc)),
refresh: 'wait_for',
})();

await createIndex({
client,
indexName: 'existing_index_2',
Expand Down Expand Up @@ -756,8 +779,7 @@ export const runActionTestSuite = ({

// Reindex doesn't return any errors on it's own, so we have to test
// together with waitForReindexTask
// Failing: See https://github.com/elastic/kibana/issues/166190
describe.skip('reindex & waitForReindexTask', () => {
describe('reindex & waitForReindexTask', () => {
it('resolves right when reindex succeeds without reindex script', async () => {
const res = (await reindex({
client,
Expand Down Expand Up @@ -1122,15 +1144,16 @@ export const runActionTestSuite = ({
it('resolves left wait_for_task_completion_timeout when the task does not finish within the timeout', async () => {
const readyTaskRes = await waitForIndexStatus({
client,
index: 'existing_index_with_docs',
index: 'existing_index_with_100k_docs',
status: 'yellow',
timeout: '300s',
})();

expect(Either.isRight(readyTaskRes)).toBe(true);

const res = (await reindex({
client,
sourceIndex: 'existing_index_with_docs',
sourceIndex: 'existing_index_with_100k_docs',
targetIndex: 'reindex_target',
reindexScript: Option.none,
requireAlias: false,
Expand Down Expand Up @@ -1428,8 +1451,7 @@ export const runActionTestSuite = ({
});
});

// Failing: See https://github.com/elastic/kibana/issues/166199
describe.skip('waitForPickupUpdatedMappingsTask', () => {
describe('waitForPickupUpdatedMappingsTask', () => {
it('rejects if there are failures', async () => {
const res = (await pickupUpdatedMappings(
client,
Expand Down Expand Up @@ -1469,7 +1491,7 @@ export const runActionTestSuite = ({
it('resolves left wait_for_task_completion_timeout when the task does not complete within the timeout', async () => {
const res = (await pickupUpdatedMappings(
client,
'existing_index_with_docs',
'existing_index_with_100k_docs',
1000
)()) as Either.Right<UpdateByQueryResponse>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { v4 as uuidv4 } from 'uuid';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { waitForIndexStatus } from '@kbn/core-saved-objects-migration-server-internal';
import type { APMIndices } from '@kbn/apm-data-access-plugin/server';
import { ElasticsearchCapabilities } from '@kbn/core-elasticsearch-server';
import { ML_ERRORS } from '../../../common/anomaly_detection';
import { METRICSET_NAME, PROCESSOR_EVENT } from '../../../common/es_fields/apm';
import { Environment } from '../../../common/environment_rt';
Expand All @@ -30,12 +31,14 @@ export async function createAnomalyDetectionJobs({
indices,
environments,
logger,
esCapabilities,
}: {
mlClient?: MlClient;
esClient: ElasticsearchClient;
indices: APMIndices;
environments: Environment[];
logger: Logger;
esCapabilities: ElasticsearchCapabilities;
}) {
if (!mlClient) {
throw Boom.notImplemented(ML_ERRORS.ML_NOT_AVAILABLE);
Expand Down Expand Up @@ -68,6 +71,7 @@ export async function createAnomalyDetectionJobs({
esClient,
environment,
apmMetricIndex,
esCapabilities,
})
);
} catch (e) {
Expand Down Expand Up @@ -97,12 +101,16 @@ async function createAnomalyDetectionJob({
esClient,
environment,
apmMetricIndex,
esCapabilities,
}: {
mlClient: Required<MlClient>;
esClient: ElasticsearchClient;
environment: string;
apmMetricIndex: string;
esCapabilities: ElasticsearchCapabilities;
}) {
const { serverless } = esCapabilities;

return withApmSpan('create_anomaly_detection_job', async () => {
const randomToken = uuidv4().substr(-4);

Expand Down Expand Up @@ -136,12 +144,16 @@ async function createAnomalyDetectionJob({
],
});

await waitForIndexStatus({
client: esClient,
index: '.ml-*',
timeout: DEFAULT_TIMEOUT,
status: 'yellow',
})();
// Waiting for the index is not enabled in serverless, this could potentially cause
// problems when creating jobs in parallels
if (!serverless) {
await waitForIndexStatus({
client: esClient,
index: '.ml-*',
timeout: DEFAULT_TIMEOUT,
status: 'yellow',
})();
}

return anomalyDetectionJob;
});
Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugins/apm/server/lib/helpers/get_es_capabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { APMRouteHandlerResources } from '../../routes/apm_routes/register_apm_server_routes';

export async function getESCapabilities({ core }: APMRouteHandlerResources) {
const es = (await core.start()).elasticsearch;

return es.getCapabilities();
}
Loading

0 comments on commit bc5d5d6

Please sign in to comment.