Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ingest/epm-experi…
Browse files Browse the repository at this point in the history
…mental
  • Loading branch information
jen-huang committed Jul 7, 2020
2 parents e91e997 + 6e35798 commit 696e76f
Show file tree
Hide file tree
Showing 459 changed files with 17,240 additions and 3,626 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
/x-pack/plugins/licensing/ @elastic/kibana-platform
/x-pack/plugins/global_search/ @elastic/kibana-platform
/x-pack/plugins/cloud/ @elastic/kibana-platform
/x-pack/test/saved_objects_field_count/ @elastic/kibana-platform
/packages/kbn-config-schema/ @elastic/kibana-platform
/src/legacy/server/config/ @elastic/kibana-platform
/src/legacy/server/http/ @elastic/kibana-platform
Expand Down
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ kibanaPipeline(timeoutMinutes: 155, checkPrChanges: true, setCommitStatus: true)
'xpack-ciGroup9': kibanaPipeline.xpackCiGroupProcess(9),
'xpack-ciGroup10': kibanaPipeline.xpackCiGroupProcess(10),
'xpack-accessibility': kibanaPipeline.functionalTestProcess('xpack-accessibility', './test/scripts/jenkins_xpack_accessibility.sh'),
'xpack-savedObjectsFieldMetrics': kibanaPipeline.functionalTestProcess('xpack-savedObjectsFieldMetrics', './test/scripts/jenkins_xpack_saved_objects_field_metrics.sh'),
// 'xpack-pageLoadMetrics': kibanaPipeline.functionalTestProcess('xpack-pageLoadMetrics', './test/scripts/jenkins_xpack_page_load_metrics.sh'),
'xpack-securitySolutionCypress': { processNumber ->
whenChanged(['x-pack/plugins/security_solution/', 'x-pack/test/security_solution_cypress/']) {
Expand Down
85 changes: 85 additions & 0 deletions docs/apm/api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Some APM app features are provided via a REST API:

* <<agent-config-api>>
* <<apm-annotation-api>>
* <<kibana-api,Kibana API>>

[float]
[[apm-api-example]]
Expand Down Expand Up @@ -468,3 +469,87 @@ curl -X POST \
}
}
--------------------------------------------------

////
*******************************************************
////

[[kibana-api]]
=== Kibana API

In addition to the APM specific API endpoints, Kibana provides its own <<api,REST API>>
which you can use to automate certain aspects of configuring and deploying Kibana.
An example is below.

[[api-create-apm-index-pattern]]
==== Customize the APM index pattern

As an alternative to updating <<apm-settings-in-kibana,`apm_oss.indexPattern`>> in your `kibana.yml` configuration file,
you can use Kibana's <<saved-objects-api-update,update object API>> to update the default APM index pattern on the fly.

The following example sets the default APM app index pattern to `some-other-pattern-*`:

[source,sh]
----
curl -X PUT "localhost:5601/api/saved_objects/index-pattern/apm_static_index_pattern_id" \ <1>
-H 'Content-Type: application/json' \
-H 'kbn-xsrf: true' \
-H 'Authorization: Basic ${YOUR_AUTH_TOKEN}' \
-d' {
"attributes": {
"title": "some-other-pattern-*", <2>
}
}'
----
<1> `apm_static_index_pattern_id` is the internal, hard-coded ID of the APM index pattern.
This value should not be changed
<2> Your custom index pattern matcher.

The API returns the following:

[source,json]
----
{
"id":"apm_static_index_pattern_id",
"type":"index-pattern",
"updated_at":"2020-07-06T22:55:59.555Z",
"version":"WzYsMV0=",
"attributes":{
"title":"some-other-pattern-*"
}
}
----

To view the new APM app index pattern, use the <<saved-objects-api-get,GET object API>>:

[source,sh]
----
curl -X GET "localhost:5601/api/saved_objects/index-pattern/apm_static_index_pattern_id" \ <1>
-H 'kbn-xsrf: true' \
-H 'Authorization: Basic ${YOUR_AUTH_TOKEN}'
----
<1> `apm_static_index_pattern_id` is the internal, hard-coded ID of the APM index pattern.

The API returns the following:

[source,json]
----
{
"id":"apm_static_index_pattern_id",
"type":"index-pattern",
"updated_at":"2020-07-06T22:55:59.555Z",
"version":"WzYsMV0=",
"attributes":{...}
"fieldFormatMap":"{...}
"fields":"[{...},{...},...]
"sourceFilters":"[{\"value\":\"sourcemap.sourcemap\"}]",
"timeFieldName":"@timestamp",
"title":"some-other-pattern-*"
},
...
}
----

// More examples will go here

More information on Kibana's API is available in <<api,REST API>>.
3 changes: 2 additions & 1 deletion docs/apm/set-up.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ simply click *Load Kibana objects* at the bottom of the Setup Instructions.
[role="screenshot"]
image::apm/images/apm-index-pattern.png[Setup index pattern for APM in Kibana]

To use a custom index pattern, see <<apm-settings-in-kibana>>.
TIP: To use a custom index pattern,
adjust Kibana's <<apm-settings-in-kibana,settings>> or use the <<api-create-apm-index-pattern,Kibana API>>.

[float]
[[apm-getting-started-next]]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface HttpServerInfo

| Property | Type | Description |
| --- | --- | --- |
| [host](./kibana-plugin-core-server.httpserverinfo.host.md) | <code>string</code> | The hostname of the server |
| [hostname](./kibana-plugin-core-server.httpserverinfo.hostname.md) | <code>string</code> | The hostname of the server |
| [name](./kibana-plugin-core-server.httpserverinfo.name.md) | <code>string</code> | The name of the Kibana server |
| [port](./kibana-plugin-core-server.httpserverinfo.port.md) | <code>number</code> | The port the server is listening on |
| [protocol](./kibana-plugin-core-server.httpserverinfo.protocol.md) | <code>'http' &#124; 'https' &#124; 'socket'</code> | The protocol used by the server |
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export declare class IndexPattern implements IIndexPattern
| [\_fetchFields()](./kibana-plugin-plugins-data-public.indexpattern._fetchfields.md) | | |
| [addScriptedField(name, script, fieldType, lang)](./kibana-plugin-plugins-data-public.indexpattern.addscriptedfield.md) | | |
| [create(allowOverride)](./kibana-plugin-plugins-data-public.indexpattern.create.md) | | |
| [destroy()](./kibana-plugin-plugins-data-public.indexpattern.destroy.md) | | |
| [getAggregationRestrictions()](./kibana-plugin-plugins-data-public.indexpattern.getaggregationrestrictions.md) | | |
| [getComputedFields()](./kibana-plugin-plugins-data-public.indexpattern.getcomputedfields.md) | | |
| [getFieldByName(name)](./kibana-plugin-plugins-data-public.indexpattern.getfieldbyname.md) | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ two out-of-the box connectors: <<slack-action-type, Slack>> and <<webhook-action
my-slack1: <1>
actionTypeId: .slack <2>
name: 'Slack #xyz' <3>
secrets: <4>
secrets:
webhookUrl: 'https://hooks.slack.com/services/abcd/efgh/ijklmnopqrstuvwxyz'
webhook-service:
actionTypeId: .webhook
name: 'Email service'
config:
config: <4>
url: 'https://email-alert-service.elastic.co'
method: post
headers:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"@babel/plugin-transform-modules-commonjs": "^7.10.1",
"@babel/register": "^7.10.1",
"@elastic/apm-rum": "^5.2.0",
"@elastic/charts": "19.7.0",
"@elastic/charts": "19.8.0",
"@elastic/datemath": "5.0.3",
"@elastic/ems-client": "7.9.3",
"@elastic/eui": "24.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-ui-shared-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"kbn:watch": "node scripts/build --dev --watch"
},
"dependencies": {
"@elastic/charts": "19.7.0",
"@elastic/charts": "19.8.0",
"@elastic/eui": "24.1.0",
"@elastic/numeral": "^2.5.0",
"@kbn/i18n": "1.0.0",
Expand Down
105 changes: 20 additions & 85 deletions src/core/server/elasticsearch/elasticsearch_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,14 @@
*/

import { BehaviorSubject } from 'rxjs';
import { Client } from 'elasticsearch';
import {
ILegacyClusterClient,
ILegacyCustomClusterClient,
ILegacyScopedClusterClient,
} from './legacy';
import { ILegacyClusterClient, ILegacyCustomClusterClient } from './legacy';
import { legacyClientMock } from './legacy/mocks';
import { ElasticsearchConfig } from './elasticsearch_config';
import { ElasticsearchService } from './elasticsearch_service';
import { InternalElasticsearchServiceSetup, ElasticsearchStatusMeta } from './types';
import { NodesVersionCompatibility } from './version_check/ensure_es_version';
import { ServiceStatus, ServiceStatusLevels } from '../status';

const createScopedClusterClientMock = (): jest.Mocked<ILegacyScopedClusterClient> => ({
callAsInternalUser: jest.fn(),
callAsCurrentUser: jest.fn(),
});

const createCustomClusterClientMock = (): jest.Mocked<ILegacyCustomClusterClient> => ({
...createClusterClientMock(),
close: jest.fn(),
});

function createClusterClientMock() {
const client: jest.Mocked<ILegacyClusterClient> = {
callAsInternalUser: jest.fn(),
asScoped: jest.fn(),
};
client.asScoped.mockReturnValue(createScopedClusterClientMock());
return client;
}

interface MockedElasticSearchServiceSetup {
legacy: {
createClient: jest.Mock<ILegacyCustomClusterClient, any>;
Expand All @@ -60,11 +37,13 @@ const createSetupContractMock = () => {
const setupContract: MockedElasticSearchServiceSetup = {
legacy: {
createClient: jest.fn(),
client: createClusterClientMock(),
client: legacyClientMock.createClusterClient(),
},
};
setupContract.legacy.createClient.mockReturnValue(createCustomClusterClientMock());
setupContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock());
setupContract.legacy.createClient.mockReturnValue(legacyClientMock.createCustomClusterClient());
setupContract.legacy.client.asScoped.mockReturnValue(
legacyClientMock.createScopedClusterClient()
);
return setupContract;
};

Expand All @@ -74,11 +53,14 @@ const createStartContractMock = () => {
const startContract: MockedElasticSearchServiceStart = {
legacy: {
createClient: jest.fn(),
client: createClusterClientMock(),
client: legacyClientMock.createClusterClient(),
},
};
startContract.legacy.createClient.mockReturnValue(createCustomClusterClientMock());
startContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock());
startContract.legacy.createClient.mockReturnValue(legacyClientMock.createCustomClusterClient());
startContract.legacy.client.asScoped.mockReturnValue(
legacyClientMock.createScopedClusterClient()
);

return startContract;
};

Expand All @@ -104,7 +86,9 @@ const createInternalSetupContractMock = () => {
...createSetupContractMock().legacy,
},
};
setupContract.legacy.client.asScoped.mockReturnValue(createScopedClusterClientMock());
setupContract.legacy.client.asScoped.mockReturnValue(
legacyClientMock.createScopedClusterClient()
);
return setupContract;
};

Expand All @@ -121,62 +105,13 @@ const createMock = () => {
return mocked;
};

const createElasticsearchClientMock = () => {
const mocked: jest.Mocked<Client> = {
cat: {} as any,
cluster: {} as any,
indices: {} as any,
ingest: {} as any,
nodes: {} as any,
snapshot: {} as any,
tasks: {} as any,
bulk: jest.fn(),
clearScroll: jest.fn(),
count: jest.fn(),
create: jest.fn(),
delete: jest.fn(),
deleteByQuery: jest.fn(),
deleteScript: jest.fn(),
deleteTemplate: jest.fn(),
exists: jest.fn(),
explain: jest.fn(),
fieldStats: jest.fn(),
get: jest.fn(),
getScript: jest.fn(),
getSource: jest.fn(),
getTemplate: jest.fn(),
index: jest.fn(),
info: jest.fn(),
mget: jest.fn(),
msearch: jest.fn(),
msearchTemplate: jest.fn(),
mtermvectors: jest.fn(),
ping: jest.fn(),
putScript: jest.fn(),
putTemplate: jest.fn(),
reindex: jest.fn(),
reindexRethrottle: jest.fn(),
renderSearchTemplate: jest.fn(),
scroll: jest.fn(),
search: jest.fn(),
searchShards: jest.fn(),
searchTemplate: jest.fn(),
suggest: jest.fn(),
termvectors: jest.fn(),
update: jest.fn(),
updateByQuery: jest.fn(),
close: jest.fn(),
};
return mocked;
};

export const elasticsearchServiceMock = {
create: createMock,
createInternalSetup: createInternalSetupContractMock,
createSetup: createSetupContractMock,
createStart: createStartContractMock,
createClusterClient: createClusterClientMock,
createCustomClusterClient: createCustomClusterClientMock,
createScopedClusterClient: createScopedClusterClientMock,
createElasticsearchClient: createElasticsearchClientMock,
createLegacyClusterClient: legacyClientMock.createClusterClient,
createLegacyCustomClusterClient: legacyClientMock.createCustomClusterClient,
createLegacyScopedClusterClient: legacyClientMock.createScopedClusterClient,
createLegacyElasticsearchClient: legacyClientMock.createElasticsearchClient,
};
8 changes: 4 additions & 4 deletions src/core/server/elasticsearch/elasticsearch_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('#setup', () => {
});

it('returns elasticsearch client as a part of the contract', async () => {
const mockClusterClientInstance = elasticsearchServiceMock.createClusterClient();
const mockClusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient();
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);

const setupContract = await elasticsearchService.setup(deps);
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('#setup', () => {
});

it('esNodeVersionCompatibility$ only starts polling when subscribed to', async (done) => {
const clusterClientInstance = elasticsearchServiceMock.createClusterClient();
const clusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient();
MockClusterClient.mockImplementationOnce(() => clusterClientInstance);

clusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());
Expand All @@ -225,7 +225,7 @@ describe('#setup', () => {
});

it('esNodeVersionCompatibility$ stops polling when unsubscribed from', async (done) => {
const mockClusterClientInstance = elasticsearchServiceMock.createClusterClient();
const mockClusterClientInstance = elasticsearchServiceMock.createLegacyClusterClient();
MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);

mockClusterClientInstance.callAsInternalUser.mockRejectedValue(new Error());
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('#stop', () => {

it('stops pollEsNodeVersions even if there are active subscriptions', async (done) => {
expect.assertions(2);
const mockClusterClientInstance = elasticsearchServiceMock.createCustomClusterClient();
const mockClusterClientInstance = elasticsearchServiceMock.createLegacyCustomClusterClient();

MockClusterClient.mockImplementationOnce(() => mockClusterClientInstance);

Expand Down
Loading

0 comments on commit 696e76f

Please sign in to comment.