Skip to content

Commit

Permalink
Merge branch 'master' into core-ts-expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jun 29, 2020
2 parents 589847c + 752fa6e commit 14620e4
Show file tree
Hide file tree
Showing 129 changed files with 6,334 additions and 1,830 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ module.exports = {
{
// typescript only for front and back end
files: [
'x-pack/{,legacy/}plugins/{alerting,alerting_builtins,actions,task_manager,event_log}/**/*.{ts,tsx}',
'x-pack/{,legacy/}plugins/{alerts,alerting_builtins,actions,task_manager,event_log}/**/*.{ts,tsx}',
],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
Expand Down
23 changes: 21 additions & 2 deletions docs/apm/apm-alerts.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ and enables central management of all alerts from <<management,Kibana Management
[role="screenshot"]
image::apm/images/apm-alert.png[Create an alert in the APM app]

There are two different types of threshold alerts: transaction duration, and error rate.
For a walkthrough of the alert flyout panel, including detailed information on each configurable property,
see Kibana's <<defining-alerts,defining alerts>>.

The APM app supports two different types of threshold alerts: transaction duration, and error rate.
Below, we'll create one of each.

[float]
[[apm-create-transaction-alert]]
=== Create a transaction duration alert

This guide creates an alert for the `opbeans-java` service based on the following criteria:
Transaction duration alerts trigger when the duration of a specific transaction type in a service exceeds a defined threshold.
This guide will create an alert for the `opbeans-java` service based on the following criteria:

* Environment: Production
* Transaction type: `transaction.type:request`
* Average request is above `1500ms` for the last 5 minutes
* Check every 10 minutes, and repeat the alert every 30 minutes
Expand Down Expand Up @@ -52,14 +57,22 @@ Enter a name for the connector,
and paste the webhook URL.
See Slack's webhook documentation if you need to create one.

Add a message body in markdown format.
You can use the https://mustache.github.io/[Mustache] template syntax, i.e., `{{variable}}`
to pass alert values at the time a condition is detected to an action.
A list of available variables can be accessed by selecting the
**add variable** button image:apm/images/add-variable.png[add variable button].

Select **Save**. The alert has been created and is now active!

[float]
[[apm-create-error-alert]]
=== Create an error rate alert

Error rate alerts trigger when the number of errors in a service exceeds a defined threshold.
This guide creates an alert for the `opbeans-python` service based on the following criteria:

* Environment: Production
* Error rate is above 25 for the last minute
* Check every 1 minute, and repeat the alert every 10 minutes
* Send the alert via email to the `opbeans-python` team
Expand All @@ -81,6 +94,12 @@ Based on the alert criteria, define the following alert details:
Select the **Email** action type and click **Create a connector**.
Fill out the required details: sender, host, port, etc., and click **save**.

Add a message body in markdown format.
You can use the https://mustache.github.io/[Mustache] template syntax, i.e., `{{variable}}`
to pass alert values at the time a condition is detected to an action.
A list of available variables can be accessed by selecting the
**add variable** button image:apm/images/add-variable.png[add variable button].

Select **Save**. The alert has been created and is now active!

[float]
Expand Down
Binary file added docs/apm/images/add-variable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [getTime](./kibana-plugin-plugins-data-server.gettime.md)

## getTime() function

<b>Signature:</b>

```typescript
export declare function getTime(indexPattern: IIndexPattern | undefined, timeRange: TimeRange, options?: {
forceNow?: Date;
fieldName?: string;
}): import("../..").RangeFilter | undefined;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| indexPattern | <code>IIndexPattern &#124; undefined</code> | |
| timeRange | <code>TimeRange</code> | |
| options | <code>{</code><br/><code> forceNow?: Date;</code><br/><code> fieldName?: string;</code><br/><code>}</code> | |

<b>Returns:</b>

`import("../..").RangeFilter | undefined`

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
| Function | Description |
| --- | --- |
| [getDefaultSearchParams(config)](./kibana-plugin-plugins-data-server.getdefaultsearchparams.md) | |
| [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-server.gettime.md) | |
| [parseInterval(interval)](./kibana-plugin-plugins-data-server.parseinterval.md) | |
| [plugin(initializerContext)](./kibana-plugin-plugins-data-server.plugin.md) | Static code to be shared externally |
| [shouldReadFieldFromDocValues(aggregatable, esType)](./kibana-plugin-plugins-data-server.shouldreadfieldfromdocvalues.md) | |
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const ReactDomServer = require('react-dom/server');
export const ReactIntl = require('react-intl');
export const ReactRouter = require('react-router'); // eslint-disable-line
export const ReactRouterDom = require('react-router-dom');
export const StyledComponents = require('styled-components');

Moment.tz.load(require('moment-timezone/data/packed/latest.json'));

Expand Down
1 change: 1 addition & 0 deletions packages/kbn-ui-shared-deps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ exports.externals = {
'react-intl': '__kbnSharedDeps__.ReactIntl',
'react-router': '__kbnSharedDeps__.ReactRouter',
'react-router-dom': '__kbnSharedDeps__.ReactRouterDom',
'styled-components': '__kbnSharedDeps__.StyledComponents',
'@kbn/monaco': '__kbnSharedDeps__.KbnMonaco',
// this is how plugins/consumers from npm load monaco
'monaco-editor/esm/vs/editor/editor.api': '__kbnSharedDeps__.MonacoBarePluginApi',
Expand Down
6 changes: 4 additions & 2 deletions packages/kbn-ui-shared-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-intl": "^2.8.0",
"react-is": "^16.8.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"regenerator-runtime": "^0.13.3",
"rxjs": "^6.5.5",
"styled-components": "^5.1.0",
"symbol-observable": "^1.2.0",
"whatwg-fetch": "^3.0.0"
},
"devDependencies": {
"@kbn/babel-preset": "1.0.0",
"@kbn/dev-utils": "1.0.0",
"loader-utils": "^1.2.3",
"val-loader": "^1.1.1",
"css-loader": "^3.4.2",
"del": "^5.1.0",
"loader-utils": "^1.2.3",
"val-loader": "^1.1.1",
"webpack": "^4.41.5"
}
}
1 change: 0 additions & 1 deletion src/plugins/data/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ export * from './kbn_field_types';
export * from './query';
export * from './search';
export * from './search/aggs';
export * from './timefilter';
export * from './types';
export * from './utils';
1 change: 1 addition & 0 deletions src/plugins/data/common/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
*/

export * from './filter_manager';
export * from './timefilter';
export * from './types';
export * from './is_query';
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
*/

import dateMath from '@elastic/datemath';
import { IIndexPattern } from '../..';
import { TimeRange, buildRangeFilter } from '../../../common';
import { buildRangeFilter, IIndexPattern, TimeRange, TimeRangeBounds } from '../..';

interface CalculateBoundsOptions {
forceNow?: Date;
}

export function calculateBounds(timeRange: TimeRange, options: CalculateBoundsOptions = {}) {
export function calculateBounds(
timeRange: TimeRange,
options: CalculateBoundsOptions = {}
): TimeRangeBounds {
return {
min: dateMath.parse(timeRange.from, { forceNow: options.forceNow }),
max: dateMath.parse(timeRange.to, { roundUp: true, forceNow: options.forceNow }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
* under the License.
*/

export { isTimeRange } from './is_time_range';
export * from './get_time';
export * from './is_time_range';
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { Moment } from 'moment';

export interface RefreshInterval {
pause: boolean;
value: number;
Expand All @@ -27,3 +29,8 @@ export interface TimeRange {
to: string;
mode?: 'absolute' | 'relative';
}

export interface TimeRangeBounds {
min: Moment | undefined;
max: Moment | undefined;
}
2 changes: 2 additions & 0 deletions src/plugins/data/common/query/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

export * from './timefilter/types';

export interface Query {
query: string | { [key: string]: any };
language: string;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

export * from './timefilter/types';
export * from './query/types';
export * from './kbn_field_types/types';
export * from './index_patterns/types';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ export {
connectToQueryState,
syncQueryStateWithUrl,
QueryState,
getTime,
getQueryLog,
getDefaultQuery,
FilterManager,
Expand All @@ -435,6 +434,7 @@ export {
} from './query';

export {
getTime,
// kbn field types
castEsToKbnFieldTypeName,
getKbnTypeNames,
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
expressions,
getInternalStartServices,
packageInfo: this.packageInfo,
query: queryService,
}),
fieldFormats: this.fieldFormatsService.setup(core),
query: queryService,
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/query/timefilter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ export { TimefilterService, TimefilterSetup } from './timefilter_service';
export * from './types';
export { Timefilter, TimefilterContract } from './timefilter';
export { TimeHistory, TimeHistoryContract } from './time_history';
export { getTime, calculateBounds } from './get_time';
export { changeTimeFilter, convertRangeFilterToTimeRangeString } from './lib/change_time_filter';
export { extractTimeFilter } from './lib/extract_time_filter';
34 changes: 34 additions & 0 deletions src/plugins/data/public/query/timefilter/lib/get_force_now.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.
*/

import { parseQueryString } from './parse_querystring';

/** @internal */
export function getForceNow() {
const forceNow = parseQueryString().forceNow as string;
if (!forceNow) {
return;
}

const ticks = Date.parse(forceNow);
if (isNaN(ticks)) {
throw new Error(`forceNow query parameter, ${forceNow}, can't be parsed by Date.parse`);
}
return new Date(ticks);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import { parse } from 'query-string';

/** @internal */
export function parseQueryString() {
// window.location.search is an empty string
// get search from href
Expand Down
16 changes: 3 additions & 13 deletions src/plugins/data/public/query/timefilter/timefilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import _ from 'lodash';
import { Subject, BehaviorSubject } from 'rxjs';
import moment from 'moment';
import { areRefreshIntervalsDifferent, areTimeRangesDifferent } from './lib/diff_time_picker_vals';
import { parseQueryString } from './lib/parse_querystring';
import { calculateBounds, getTime } from './get_time';
import { getForceNow } from './lib/get_force_now';
import { TimefilterConfig, InputTimeRange, TimeRangeBounds } from './types';
import { RefreshInterval, TimeRange } from '../../../common';
import { calculateBounds, getTime, RefreshInterval, TimeRange } from '../../../common';
import { TimeHistoryContract } from './time_history';
import { IndexPattern } from '../../index_patterns';

Expand Down Expand Up @@ -224,16 +223,7 @@ export class Timefilter {
}

private getForceNow = () => {
const forceNow = parseQueryString().forceNow as string;
if (!forceNow) {
return;
}

const ticks = Date.parse(forceNow);
if (isNaN(ticks)) {
throw new Error(`forceNow query parameter, ${forceNow}, can't be parsed by Date.parse`);
}
return new Date(ticks);
return getForceNow();
};
}

Expand Down
7 changes: 3 additions & 4 deletions src/plugins/data/public/query/timefilter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/

import { Moment } from 'moment';

import { TimeRange, RefreshInterval } from '../../../common';

export interface TimefilterConfig {
Expand All @@ -32,7 +34,4 @@ export type InputTimeRange =
to: Moment;
};

export interface TimeRangeBounds {
min: Moment | undefined;
max: Moment | undefined;
}
export { TimeRangeBounds } from '../../../common';
15 changes: 7 additions & 8 deletions src/plugins/data/public/search/aggs/agg_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import { IUiSettingsClient } from 'src/core/public';
import { QuerySetup } from '../../query/query_service';
import { TimeRange, TimeRangeBounds } from '../../../common';
import { GetInternalStartServicesFn } from '../../types';

import { getCountMetricAgg } from './metrics/count';
import { getAvgMetricAgg } from './metrics/avg';
Expand Down Expand Up @@ -54,18 +55,16 @@ import { getBucketAvgMetricAgg } from './metrics/bucket_avg';
import { getBucketMinMetricAgg } from './metrics/bucket_min';
import { getBucketMaxMetricAgg } from './metrics/bucket_max';

import { GetInternalStartServicesFn } from '../../types';

export interface AggTypesDependencies {
uiSettings: IUiSettingsClient;
query: QuerySetup;
calculateBounds: (timeRange: TimeRange) => TimeRangeBounds;
getInternalStartServices: GetInternalStartServicesFn;
uiSettings: IUiSettingsClient;
}

export const getAggTypes = ({
uiSettings,
query,
calculateBounds,
getInternalStartServices,
uiSettings,
}: AggTypesDependencies) => ({
metrics: [
getCountMetricAgg({ getInternalStartServices }),
Expand All @@ -91,7 +90,7 @@ export const getAggTypes = ({
getGeoCentroidMetricAgg({ getInternalStartServices }),
],
buckets: [
getDateHistogramBucketAgg({ uiSettings, query, getInternalStartServices }),
getDateHistogramBucketAgg({ calculateBounds, uiSettings, getInternalStartServices }),
getHistogramBucketAgg({ uiSettings, getInternalStartServices }),
getRangeBucketAgg({ getInternalStartServices }),
getDateRangeBucketAgg({ uiSettings, getInternalStartServices }),
Expand Down
Loading

0 comments on commit 14620e4

Please sign in to comment.