Skip to content

Commit

Permalink
Merge branch 'master' into elastic#63480
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored May 21, 2020
2 parents 836af59 + 203605e commit a34a62e
Show file tree
Hide file tree
Showing 52 changed files with 885 additions and 446 deletions.
149 changes: 146 additions & 3 deletions docs/apm/api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,45 @@
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>>.
* <<apm-annotation-api>>

Here's an example CURL request that adds an annotation to the APM app:

[source,curl]
----
curl -X POST \
http://localhost:5601/api/apm/services/opbeans-java/annotation \
-H 'Content-Type: application/json' \
-H 'kbn-xsrf: true' \
-H 'Authorization: Basic YhUlubWZhM0FDbnlQeE6WRtaW49FQmSGZ4RUWXdX' \
-d '{
"@timestamp": "2020-05-11T10:31:30.452Z",
"service": {
"version": "1.2"
},
"message": "Revert upgrade",
"tags": [
"elastic.co", "customer"
]
}'
----

For more information, the Kibana <<api,REST API reference>> provides information on how to use Kibana APIs,
like required request headers and authentication options.

// AGENT CONFIG API
// GET --> Feature (APM) Read
// CREATE/EDIT/DELETE --> Feature (APM) All

// ANNOTATION API
// Feature (APM) All
// Index: `observability-annotations`. Privileges: `create_index`, `create_doc`, `manage`, and `read`.

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

[role="xpack"]
[[agent-config-api]]
=== Agent Configuration API

Expand Down Expand Up @@ -274,6 +305,118 @@ POST /api/apm/settings/agent-configuration/search
}
--------------------------------------------------

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

[role="xpack"]
[[apm-annotation-api]]
=== Annotation API

The Annotation API allows you to annotate visualizations in the APM app with significant events, like deployments,
allowing you to easily see how these events are impacting the performance of your existing applications.

The following APIs are available:

* <<apm-annotation-create>> to create an annotation for APM.
// * <<obs-annotation-create>> POST /api/observability/annotation
// * <<obs-annotation-get>> GET /api/observability/annotation/:id
// * <<obs-annotation-delete>> DELETE /api/observability/annotation/:id

By default, annotations are stored in a newly created `observability-annotations` index.
The name of this index can be changed in your `config.yml` by editing `xpack.observability.annotations.index`.

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

[[apm-annotation-create]]
==== Create or update annotation

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

`POST /api/apm/services/:serviceName/annotation`

[role="child_attributes"]
[[apm-annotation-config-req-body]]
===== Request body

`service`::
(required, object) Service identifying the configuration to create or update.
+
.Properties of `service`
[%collapsible%open]
======
`version` :::
(required, string) Name of service.
`environment` :::
(optional, string) Environment of service.
======

`@timestamp`::
(required, string) The date and time of the annotation. Must be in https://www.w3.org/TR/NOTE-datetime[ISO 8601] format.

`message`::
(optional, string) The message displayed in the annotation. Defaults to `service.version`.

`tags`::
(optional, array) Tags are used by the APM app to distinguish APM annotations from other annotations.
Tags may have additional functionality in future releases. Defaults to `[apm]`.
While you can add additional tags, you cannot remove the `apm` tag.

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

The following example creates an annotation for a service named `opbeans-java`.

[source,console]
--------------------------------------------------
POST /api/apm/services/opbeans-java/annotation
{
"@timestamp": "2020-05-08T10:31:30.452Z",
"service": {
"version": "1.2"
},
"message": "Deployment 1.2",
"tags": [
"elastic.co", "customer"
]
}
--------------------------------------------------

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

[source,js]
--------------------------------------------------
{
"_index": "observability-annotations",
"_id": "Lc9I93EBh6DbmkeV7nFX",
"_version": 1,
"_seq_no": 12,
"_primary_term": 1,
"found": true,
"_source": {
"message": "Deployment 1.2",
"@timestamp": "2020-05-08T10:31:30.452Z",
"service": {
"version": "1.2",
"name": "opbeans-java"
},
"tags": [
"apm",
"elastic.co",
"customer"
],
"annotation": {
"type": "deployment"
},
"event": {
"created": "2020-05-09T02:34:43.937Z"
}
}
}
--------------------------------------------------
8 changes: 6 additions & 2 deletions docs/apm/deployment-annotations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
=== Track deployments with annotations

++++
<titleabbrev>Track deployments</titleabbrev>
<titleabbrev>Track deployments with annotations</titleabbrev>
++++

For enhanced visibility into your deployments, we offer deployment annotations on all transaction charts.
This feature automatically tags new deployments, so you can easily see if your deploy has increased response times
for an end-user, or if the memory/CPU footprint of your application has changed.
Being able to identify bad deployments quickly enables you to rollback and fix issues without causing costly outages.

Deployment annotations are automatically enabled, and appear when the `service.version` of your app changes.
Deployment annotations are enabled by default, and can be created with the <<apm-annotation-api,annotation API>>.
If there are no created annotations for the selected time period,
the APM app will automatically annotate your data if the `service.version` of your application changes.

NOTE: If custom annotations have been created for the selected time period, any derived annotations, i.e., those created automatically when `service.version` changes, will not be shown.

[role="screenshot"]
image::apm/images/apm-transaction-annotation.png[Example view of transactions annotation in the APM app in Kibana]
Binary file modified docs/apm/images/apm-transaction-annotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/settings/apm-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Changing these settings may disable features of the APM App.
| `xpack.apm.ui.maxTraceItems` {ess-icon}
| Maximum number of child items displayed when viewing trace details. Defaults to `1000`.

| `xpack.observability.annotations.index`
| Index name where Observability annotations are stored. Defaults to `observability-annotations`.

| `apm_oss.indexPattern` {ess-icon}
| The index pattern used for integrations with Machine Learning and Query Bar.
It must match all apm indices. Defaults to `apm-*`.
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
"react-dom": "^16.12.0",
"react-grid-layout": "^0.16.2",
"react-input-range": "^1.3.0",
"react-markdown": "^3.4.1",
"react-markdown": "^4.3.1",
"react-monaco-editor": "~0.27.0",
"react-redux": "^7.1.3",
"react-resize-detector": "^4.2.0",
Expand Down Expand Up @@ -298,7 +298,6 @@
"@elastic/eslint-plugin-eui": "0.0.2",
"@elastic/github-checks-reporter": "0.0.20b3",
"@elastic/makelogs": "^5.0.1",
"@elastic/static-fs": "1.0.2",
"@kbn/dev-utils": "1.0.0",
"@kbn/es": "1.0.0",
"@kbn/eslint-import-resolver-kibana": "2.0.0",
Expand Down Expand Up @@ -387,7 +386,7 @@
"@types/semver": "^5.5.0",
"@types/sinon": "^7.0.13",
"@types/strip-ansi": "^3.0.0",
"@types/styled-components": "^4.4.2",
"@types/styled-components": "^5.1.0",
"@types/supertest": "^2.0.5",
"@types/supertest-as-promised": "^2.0.38",
"@types/testing-library__react": "^9.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@babel/preset-typescript": "^7.9.0",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-filter-imports": "^3.0.0",
"babel-plugin-styled-components": "^1.10.6",
"babel-plugin-styled-components": "^1.10.7",
"babel-plugin-transform-define": "^1.3.1",
"babel-plugin-transform-imports": "^2.0.0"
}
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export * from './bundle';
export * from './bundle_cache';
export * from './worker_config';
export * from './worker_messages';
export * from './parent_messages';
export * from './compiler_messages';
export * from './ts_helpers';
export * from './rxjs_helpers';
Expand Down
33 changes: 33 additions & 0 deletions packages/kbn-optimizer/src/common/parent_messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export interface ParentPongMsg {
type: 'pong';
}

export const isParentPong = (value: any): value is ParentPongMsg =>
typeof value === 'object' && value && value.type === 'pong';

export class ParentMsgs {
pong(): ParentPongMsg {
return {
type: 'pong',
};
}
}
19 changes: 18 additions & 1 deletion packages/kbn-optimizer/src/common/worker_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ import {
CompilerErrorMsg,
} from './compiler_messages';

export type WorkerMsg =
export type InternalWorkerMsg =
| WorkerPingMsg
| CompilerRunningMsg
| CompilerIssueMsg
| CompilerSuccessMsg
| CompilerErrorMsg
| WorkerErrorMsg;

// ping messages are internal, they don't apper in public message streams
export type WorkerMsg = Exclude<InternalWorkerMsg, WorkerPingMsg>;

/**
* Message sent when the worker encounters an error that it can't
* recover from, no more messages will be sent and the worker
Expand All @@ -42,6 +46,10 @@ export interface WorkerErrorMsg {
errorStack?: string;
}

export interface WorkerPingMsg {
type: 'ping';
}

const WORKER_STATE_TYPES: ReadonlyArray<WorkerMsg['type']> = [
'running',
'compiler issue',
Expand All @@ -50,10 +58,19 @@ const WORKER_STATE_TYPES: ReadonlyArray<WorkerMsg['type']> = [
'worker error',
];

export const isWorkerPing = (value: any): value is WorkerPingMsg =>
typeof value === 'object' && value && value.type === 'ping';

export const isWorkerMsg = (value: any): value is WorkerMsg =>
typeof value === 'object' && value && WORKER_STATE_TYPES.includes(value.type);

export class WorkerMsgs {
ping(): WorkerPingMsg {
return {
type: 'ping',
};
}

error(error: Error): WorkerErrorMsg {
return {
type: 'worker error',
Expand Down
16 changes: 14 additions & 2 deletions packages/kbn-optimizer/src/optimizer/observe_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import { Readable } from 'stream';
import { inspect } from 'util';

import * as Rx from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { map, filter, takeUntil } from 'rxjs/operators';

import { isWorkerMsg, WorkerConfig, WorkerMsg, Bundle } from '../common';
import { isWorkerMsg, isWorkerPing, WorkerConfig, WorkerMsg, Bundle, ParentMsgs } from '../common';

import { OptimizerConfig } from './optimizer_config';

const parentMsgs = new ParentMsgs();

export interface WorkerStdio {
type: 'worker stdio';
stream: 'stdout' | 'stderr';
Expand Down Expand Up @@ -146,6 +148,16 @@ export function observeWorker(
observeStdio$(proc.stderr, 'stderr'),
Rx.fromEvent<[unknown]>(proc, 'message')
.pipe(
// filter out ping messages so they don't end up in the general message stream
filter(([msg]) => {
if (!isWorkerPing(msg)) {
return true;
}

proc.send(parentMsgs.pong());
return false;
}),

// validate the messages from the process
map(([msg]) => {
if (!isWorkerMsg(msg)) {
Expand Down
Loading

0 comments on commit a34a62e

Please sign in to comment.