Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Stabilize agent configuration API #57767

Merged
merged 11 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 260 additions & 0 deletions docs/apm/api.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
[role="xpack"]
[[apm-api]]
== API

Some APM app features are provided via a REST API:

* <<agent-config-api>>

TIP: Kibana provides additional <<api,REST APIs>>,
and general information on <<using-api,how to use APIs>>.

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

[[agent-config-api]]
=== Agent Configuration API

The Agent configuration API allows you to fine-tune your APM agent configuration,
without needing to redeploy your application.

The following Agent configuration APIs are available:

* <<apm-update-config>> to create or update an Agent configuration
* <<apm-delete-config>> to delete an Agent configuration.
* <<apm-list-config>> to list all Agent configurations.
* <<apm-search-config>> to search for an Agent configuration.

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

[[apm-update-config]]
==== Create or update configuration

[[apm-update-config-req]]
===== Request

`PUT /api/apm/settings/agent-configuration`

[[apm-update-config-req-body]]
===== Request body

`service`::
(required, object) Service identifying the configuration to create or update.

`name` :::
(required, string) Name of service

`environment` :::
(optional, string) Environment of service

`settings`::
(required) Key/value object with settings and their corresponding value.

`agent_name`::
(optional) The agent name is used by the UI to determine which settings to display.


[[apm-update-config-example]]
===== Example

[source,console]
--------------------------------------------------
PUT /api/apm/settings/agent-configuration
{
"service" : {
"name" : "frontend",
"environment" : "production"
},
"settings" : {
"transaction_sample_rate" : 0.4,
"capture_body" : "off",
"transaction_max_spans" : 500
},
"agent_name": "nodejs"
}
--------------------------------------------------

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


[[apm-delete-config]]
==== Delete configuration

[[apm-delete-config-req]]
===== Request

`DELETE /api/apm/settings/agent-configuration`

[[apm-delete-config-req-body]]
===== Request body
`service`::
(required, object) Service identifying the configuration to delete

`name` :::
(required, string) Name of service

`environment` :::
(optional, string) Environment of service


[[apm-delete-config-example]]
===== Example

[source,console]
--------------------------------------------------
DELETE /api/apm/settings/agent-configuration
{
"service" : {
"name" : "frontend",
"environment": "production"
}
}
--------------------------------------------------

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


[[apm-list-config]]
==== List configuration


[[apm-list-config-req]]
===== Request

`GET /api/apm/settings/agent-configuration`

[[apm-list-config-body]]
===== Response body

[source,js]
--------------------------------------------------
[
{
"agent_name": "go",
"service": {
"name": "opbeans-go",
"environment": "production"
},
"settings": {
"transaction_sample_rate": 1,
"capture_body": "off",
"transaction_max_spans": 200
},
"@timestamp": 1581934104843,
"applied_by_agent": false,
"etag": "1e58c178efeebae15c25c539da740d21dee422fc"
},
{
"agent_name": "go",
"service": {
"name": "opbeans-go"
},
"settings": {
"transaction_sample_rate": 1,
"capture_body": "off",
"transaction_max_spans": 300
},
"@timestamp": 1581934111727,
"applied_by_agent": false,
"etag": "3eed916d3db434d9fb7f039daa681c7a04539a64"
},
{
"agent_name": "nodejs",
"service": {
"name": "frontend"
},
"settings": {
"transaction_sample_rate": 1,
},
"@timestamp": 1582031336265,
"applied_by_agent": false,
"etag": "5080ed25785b7b19f32713681e79f46996801a5b"
}
]
--------------------------------------------------

[[apm-list-config-example]]
===== Example

[source,console]
--------------------------------------------------
GET /api/apm/settings/agent-configuration
--------------------------------------------------

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


[[apm-search-config]]
==== Search configuration

[[apm-search-config-req]]
===== Request

`POST /api/apm/settings/agent-configuration/search`

[[apm-search-config-req-body]]
===== Request body

`service`::
(required, object) Service identifying the configuration.

`name` :::
(required, string) Name of service

`environment` :::
(optional, string) Environment of service

`etag`::
(required) etag is sent by the agent to indicate the etag of the last successfully applied configuration. If the etag matches an existing configuration its `applied_by_agent` property will be set to `true`. Every time a configuration is edited `applied_by_agent` is reset to `false`.

[[apm-search-config-body]]
===== Response body

[source,js]
--------------------------------------------------
{
"_index": ".apm-agent-configuration",
"_id": "CIaqXXABmQCdPphWj8EJ",
"_score": 2,
"_source": {
"agent_name": "nodejs",
"service": {
"name": "frontend"
},
"settings": {
"transaction_sample_rate": 1,
},
"@timestamp": 1582031336265,
"applied_by_agent": false,
"etag": "5080ed25785b7b19f32713681e79f46996801a5b"
}
}
--------------------------------------------------

[[apm-search-config-example]]
===== Example

[source,console]
--------------------------------------------------
POST /api/apm/settings/agent-configuration/search
{
"etag" : "1e58c178efeebae15c25c539da740d21dee422fc",
"service" : {
"name" : "frontend",
"environment": "production"
}
}
--------------------------------------------------

////
*******************************************************
////
2 changes: 2 additions & 0 deletions docs/apm/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ include::getting-started.asciidoc[]
include::bottlenecks.asciidoc[]

include::using-the-apm-ui.asciidoc[]

include::api.asciidoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ async function deleteConfig(
) {
try {
await callApmApi({
pathname: '/api/apm/settings/agent-configuration/{configurationId}',
pathname: '/api/apm/settings/agent-configuration',
method: 'DELETE',
params: {
path: { configurationId: selectedConfig.id }
body: {
service: {
name: selectedConfig.service.name,
environment: selectedConfig.service.environment
}
}
}
});

toasts.addSuccess({
title: i18n.translate(
'xpack.apm.settings.agentConf.flyout.deleteSection.deleteConfigSucceededTitle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export function AddEditFlyout({
sampleRate,
captureBody,
transactionMaxSpans,
configurationId: selectedConfig ? selectedConfig.id : undefined,
agentName,
isExistingConfig: Boolean(selectedConfig),
toasts,
trackApmEvent
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export async function saveConfig({
sampleRate,
captureBody,
transactionMaxSpans,
configurationId,
agentName,
isExistingConfig,
toasts,
trackApmEvent
}: {
Expand All @@ -38,8 +38,8 @@ export async function saveConfig({
sampleRate: string;
captureBody: string;
transactionMaxSpans: string;
configurationId?: string;
agentName?: string;
isExistingConfig: boolean;
toasts: NotificationsStart['toasts'];
trackApmEvent: UiTracker;
}) {
Expand All @@ -64,24 +64,14 @@ export async function saveConfig({
settings
};

if (configurationId) {
await callApmApi({
pathname: '/api/apm/settings/agent-configuration/{configurationId}',
method: 'PUT',
params: {
path: { configurationId },
body: configuration
}
});
} else {
await callApmApi({
pathname: '/api/apm/settings/agent-configuration/new',
method: 'POST',
params: {
body: configuration
}
});
}
await callApmApi({
pathname: '/api/apm/settings/agent-configuration',
method: 'PUT',
params: {
query: { overwrite: isExistingConfig },
body: configuration
}
});

toasts.addSuccess({
title: i18n.translate(
Expand Down
22 changes: 22 additions & 0 deletions x-pack/legacy/plugins/apm/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ node scripts/jest.js plugins/apm --watch
node scripts/jest.js plugins/apm --updateSnapshot
```

### Functional tests

**Start server**
`node scripts/functional_tests_server --config x-pack/test/functional/config.js`

**Run tests**
`node scripts/functional_test_runner --config x-pack/test/functional/config.js --grep='APM specs'`

APM tests are located in `x-pack/test/functional/apps/apm`.
For debugging access Elasticsearch on http://localhost:9220` (elastic/changeme)

### API integration tests

**Start server**
`node scripts/functional_tests_server --config x-pack/test/api_integration/config.js`

**Run tests**
`node scripts/functional_test_runner --config x-pack/test/api_integration/config.js --grep='APM specs'`

APM tests are located in `x-pack/test/api_integration/apis/apm`.
For debugging access Elasticsearch on http://localhost:9220` (elastic/changeme)

### Linting

_Note: Run the following commands from `kibana/`._
Expand Down
Loading