Skip to content

Commit

Permalink
Merge branch 'master' into model-text
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Aug 31, 2020
2 parents ce07a2f + 9b59122 commit 0c7c543
Show file tree
Hide file tree
Showing 252 changed files with 5,331 additions and 1,971 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,7 @@ module.exports = {
errorMessage: `Plugins may only import from src/core/server and src/core/public.`,
},
{
target: [
'(src|x-pack)/plugins/*/server/**/*',
'!x-pack/plugins/apm/**/*', // https://github.com/elastic/kibana/issues/67210
],
target: ['(src|x-pack)/plugins/*/server/**/*'],
from: ['(src|x-pack)/plugins/*/public/**/*'],
errorMessage: `Server code can not import from public, use a common directory.`,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [ACTION\_GLOBAL\_APPLY\_FILTER](./kibana-plugin-plugins-data-public.action_global_apply_filter.md)

## ACTION\_GLOBAL\_APPLY\_FILTER variable

<b>Signature:</b>

```typescript
ACTION_GLOBAL_APPLY_FILTER = "ACTION_GLOBAL_APPLY_FILTER"
```
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

| Variable | Description |
| --- | --- |
| [ACTION\_GLOBAL\_APPLY\_FILTER](./kibana-plugin-plugins-data-public.action_global_apply_filter.md) | |
| [AggGroupLabels](./kibana-plugin-plugins-data-public.agggrouplabels.md) | |
| [AggGroupNames](./kibana-plugin-plugins-data-public.agggroupnames.md) | |
| [baseFormattersPublic](./kibana-plugin-plugins-data-public.baseformatterspublic.md) | |
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/data/common/search/aggs/agg_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ describe('AggType Class', () => {
expect(aggType.params[1].name).toBe('customLabel');
});

test('disables json param', () => {
const aggType = new AggType({
name: 'name',
title: 'title',
json: false,
});

expect(aggType.params.length).toBe(1);
expect(aggType.params[0].name).toBe('customLabel');
});

test('can disable customLabel', () => {
const aggType = new AggType({
name: 'smart agg',
Expand Down
17 changes: 11 additions & 6 deletions src/plugins/data/common/search/aggs/agg_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface AggTypeConfig<
getRequestAggs?: ((aggConfig: TAggConfig) => TAggConfig[]) | (() => TAggConfig[] | void);
getResponseAggs?: ((aggConfig: TAggConfig) => TAggConfig[]) | (() => TAggConfig[] | void);
customLabels?: boolean;
json?: boolean;
decorateAggConfig?: () => any;
postFlightRequest?: (
resp: any,
Expand Down Expand Up @@ -235,13 +236,17 @@ export class AggType<
if (config.params && config.params.length && config.params[0] instanceof BaseParamType) {
this.params = config.params as TParam[];
} else {
// always append the raw JSON param
// always append the raw JSON param unless it is configured to false
const params: any[] = config.params ? [...config.params] : [];
params.push({
name: 'json',
type: 'json',
advanced: true,
});

if (config.json !== false) {
params.push({
name: 'json',
type: 'json',
advanced: true,
});
}

// always append custom label

if (config.customLabels !== false) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/search/aggs/metrics/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const getCountMetricAgg = () =>
defaultMessage: 'Count',
}),
hasNoDsl: true,
json: false,
makeLabel() {
return i18n.translate('data.search.aggs.metrics.countLabel', {
defaultMessage: 'Count',
Expand Down
14 changes: 0 additions & 14 deletions src/plugins/data/common/search/aggs/metrics/count_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,12 @@ describe('agg_expression_functions', () => {
"id": undefined,
"params": Object {
"customLabel": undefined,
"json": undefined,
},
"schema": undefined,
"type": "count",
},
}
`);
});

test('correctly parses json string argument', () => {
const actual = fn({
json: '{ "foo": true }',
});

expect(actual.value.params.json).toEqual({ foo: true });
expect(() => {
fn({
json: '/// intentionally malformed json ///',
});
}).toThrowErrorMatchingInlineSnapshot(`"Unable to parse json argument string"`);
});
});
});
12 changes: 1 addition & 11 deletions src/plugins/data/common/search/aggs/metrics/count_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { AggExpressionType, AggExpressionFunctionArgs, METRIC_TYPES } from '../';
import { getParsedValue } from '../utils/get_parsed_value';

const fnName = 'aggCount';

Expand Down Expand Up @@ -55,12 +54,6 @@ export const aggCount = (): FunctionDefinition => ({
defaultMessage: 'Schema to use for this aggregation',
}),
},
json: {
types: ['string'],
help: i18n.translate('data.search.aggs.metrics.count.json.help', {
defaultMessage: 'Advanced json to include when the agg is sent to Elasticsearch',
}),
},
customLabel: {
types: ['string'],
help: i18n.translate('data.search.aggs.metrics.count.customLabel.help', {
Expand All @@ -78,10 +71,7 @@ export const aggCount = (): FunctionDefinition => ({
enabled,
schema,
type: METRIC_TYPES.COUNT,
params: {
...rest,
json: getParsedValue(args, 'json'),
},
params: rest,
},
};
},
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 @@ -440,7 +440,7 @@ export {

export { isTimeRange, isQuery, isFilter, isFilters } from '../common';

export { ApplyGlobalFilterActionContext } from './actions';
export { ACTION_GLOBAL_APPLY_FILTER, ApplyGlobalFilterActionContext } from './actions';

export * from '../common/field_mapping';

Expand Down
5 changes: 5 additions & 0 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ import { UnregisterCallback } from 'history';
import { UnwrapPromiseOrReturn } from '@kbn/utility-types';
import { UserProvidedValues } from 'src/core/server/types';

// Warning: (ae-missing-release-tag) "ACTION_GLOBAL_APPLY_FILTER" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const ACTION_GLOBAL_APPLY_FILTER = "ACTION_GLOBAL_APPLY_FILTER";

// Warning: (ae-forgotten-export) The symbol "AggConfigSerialized" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "AggConfigOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
IAggType,
IndexPattern,
IndexPatternField,
} from 'src/plugins/data/public';
} from '../../../data/public';
import { filterAggTypes, filterAggTypeFields } from '../agg_filters';
import { groupAndSortBy, ComboBoxGroupedOptions } from '../utils';
import { AggTypeState, AggParamsState } from './agg_params_state';
Expand Down
5 changes: 5 additions & 0 deletions test/functional/apps/visualize/_point_series_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function ({ getService, getPageObjects }) {
const retry = getService('retry');
const kibanaServer = getService('kibanaServer');
const browser = getService('browser');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects([
'visualize',
'header',
Expand Down Expand Up @@ -148,6 +149,10 @@ export default function ({ getService, getPageObjects }) {
});
});

it('should not show advanced json for count agg', async function () {
await testSubjects.missingOrFail('advancedParams-1');
});

it('should put secondary axis on the right', async function () {
const length = await PageObjects.visChart.getRightValueAxes();
expect(length).to.be(1);
Expand Down
19 changes: 19 additions & 0 deletions x-pack/plugins/apm/common/alert_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { i18n } from '@kbn/i18n';
export enum AlertType {
ErrorRate = 'apm.error_rate',
TransactionDuration = 'apm.transaction_duration',
TransactionDurationAnomaly = 'apm.transaction_duration_anomaly',
}

export const ALERT_TYPES_CONFIG = {
Expand Down Expand Up @@ -45,6 +46,24 @@ export const ALERT_TYPES_CONFIG = {
defaultActionGroupId: 'threshold_met',
producer: 'apm',
},
[AlertType.TransactionDurationAnomaly]: {
name: i18n.translate('xpack.apm.transactionDurationAnomalyAlert.name', {
defaultMessage: 'Transaction duration anomaly',
}),
actionGroups: [
{
id: 'threshold_met',
name: i18n.translate(
'xpack.apm.transactionDurationAlert.thresholdMet',
{
defaultMessage: 'Threshold met',
}
),
},
],
defaultActionGroupId: 'threshold_met',
producer: 'apm',
},
};

export const TRANSACTION_ALERT_AGGREGATION_TYPES = {
Expand Down
32 changes: 24 additions & 8 deletions x-pack/plugins/apm/common/environment_filter_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@

import { i18n } from '@kbn/i18n';

export const ENVIRONMENT_ALL = 'ENVIRONMENT_ALL';
export const ENVIRONMENT_NOT_DEFINED = 'ENVIRONMENT_NOT_DEFINED';
const ENVIRONMENT_ALL_VALUE = 'ENVIRONMENT_ALL';
const ENVIRONMENT_NOT_DEFINED_VALUE = 'ENVIRONMENT_NOT_DEFINED';

const environmentLabels: Record<string, string> = {
[ENVIRONMENT_ALL_VALUE]: i18n.translate(
'xpack.apm.filter.environment.allLabel',
{ defaultMessage: 'All' }
),
[ENVIRONMENT_NOT_DEFINED_VALUE]: i18n.translate(
'xpack.apm.filter.environment.notDefinedLabel',
{ defaultMessage: 'Not defined' }
),
};

export const ENVIRONMENT_ALL = {
value: ENVIRONMENT_ALL_VALUE,
text: environmentLabels[ENVIRONMENT_ALL_VALUE],
};

export const ENVIRONMENT_NOT_DEFINED = {
value: ENVIRONMENT_NOT_DEFINED_VALUE,
text: environmentLabels[ENVIRONMENT_NOT_DEFINED_VALUE],
};

export function getEnvironmentLabel(environment: string) {
if (environment === ENVIRONMENT_NOT_DEFINED) {
return i18n.translate('xpack.apm.filter.environment.notDefinedLabel', {
defaultMessage: 'Not defined',
});
}
return environment;
return environmentLabels[environment] || environment;
}
14 changes: 14 additions & 0 deletions x-pack/plugins/apm/common/fetch_options.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;
* you may not use this file except in compliance with the Elastic License.
*/

import { HttpFetchOptions } from 'kibana/public';

export type FetchOptions = Omit<HttpFetchOptions, 'body'> & {
pathname: string;
isCachable?: boolean;
method?: string;
body?: any;
};
74 changes: 74 additions & 0 deletions x-pack/plugins/apm/public/application/application.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { act } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import { Observable } from 'rxjs';
import { AppMountParameters, CoreStart, HttpSetup } from 'src/core/public';
import { mockApmPluginContextValue } from '../context/ApmPluginContext/MockApmPluginContext';
import { ApmPluginSetupDeps } from '../plugin';
import { createCallApmApi } from '../services/rest/createCallApmApi';
import { renderApp } from './';
import { disableConsoleWarning } from '../utils/testHelpers';

describe('renderApp', () => {
let mockConsole: jest.SpyInstance;

beforeAll(() => {
// The RUM agent logs an unnecessary message here. There's a couple open
// issues need to be fixed to get the ability to turn off all of the logging:
//
// * https://github.com/elastic/apm-agent-rum-js/issues/799
// * https://github.com/elastic/apm-agent-rum-js/issues/861
//
// for now, override `console.warn` to filter those messages out.
mockConsole = disableConsoleWarning('[Elastic APM]');
});

afterAll(() => {
mockConsole.mockRestore();
});

it('renders the app', () => {
const { core, config } = mockApmPluginContextValue;
const plugins = {
licensing: { license$: new Observable() },
triggers_actions_ui: { actionTypeRegistry: {}, alertTypeRegistry: {} },
usageCollection: { reportUiStats: () => {} },
};
const params = {
element: document.createElement('div'),
history: createMemoryHistory(),
};
jest.spyOn(window, 'scrollTo').mockReturnValueOnce(undefined);
createCallApmApi((core.http as unknown) as HttpSetup);

jest
.spyOn(window.console, 'warn')
.mockImplementationOnce((message: string) => {
if (message.startsWith('[Elastic APM')) {
return;
} else {
console.warn(message); // eslint-disable-line no-console
}
});

let unmount: () => void;

act(() => {
unmount = renderApp(
(core as unknown) as CoreStart,
(plugins as unknown) as ApmPluginSetupDeps,
(params as unknown) as AppMountParameters,
config
);
});

expect(() => {
unmount();
}).not.toThrowError();
});
});
Loading

0 comments on commit 0c7c543

Please sign in to comment.