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] Agent configuration GA #46995

Merged
merged 23 commits into from
Oct 10, 2019
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
25 changes: 25 additions & 0 deletions x-pack/legacy/plugins/apm/common/agent_configuration_constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { i18n } from '@kbn/i18n';

export const ALL_OPTION_VALUE = 'ALL_OPTION_VALUE';

// human-readable label for the option. The "All" option should be translated.
// Everything else should be returned verbatim
export function getOptionLabel(value: string | undefined) {
if (value === undefined || value === ALL_OPTION_VALUE) {
return i18n.translate('xpack.apm.settings.agentConf.allOptionLabel', {
defaultMessage: 'All'
});
}

return value;
}

export function omitAllOption(value: string) {
return value === ALL_OPTION_VALUE ? undefined : value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { transactionMaxSpansRt } from './index';
import { isRight } from 'fp-ts/lib/Either';

describe('transactionMaxSpans', () => {
it('does not accept empty values', () => {
expect(isRight(transactionMaxSpansRt.decode(undefined))).toBe(false);
expect(isRight(transactionMaxSpansRt.decode(null))).toBe(false);
expect(isRight(transactionMaxSpansRt.decode(''))).toBe(false);
});

it('accepts both strings and numbers as values', () => {
expect(isRight(transactionMaxSpansRt.decode('55'))).toBe(true);
expect(isRight(transactionMaxSpansRt.decode(55))).toBe(true);
});

it('checks if the number falls within 0, 32000', () => {
expect(isRight(transactionMaxSpansRt.decode(0))).toBe(true);
expect(isRight(transactionMaxSpansRt.decode(32000))).toBe(true);
expect(isRight(transactionMaxSpansRt.decode(-55))).toBe(false);
expect(isRight(transactionMaxSpansRt.decode(NaN))).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 * as t from 'io-ts';

export const transactionMaxSpansRt = new t.Type<number, number, unknown>(
'transactionMaxSpans',
t.number.is,
(input, context) => {
const value = parseInt(input as string, 10);
return value >= 0 && value <= 32000
? t.success(value)
: t.failure(input, context);
},
t.identity
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { transactionSampleRateRt } from './index';
import { isRight } from 'fp-ts/lib/Either';

describe('transactionSampleRateRt', () => {
it('does not accept empty values', () => {
expect(isRight(transactionSampleRateRt.decode(undefined))).toBe(false);
expect(isRight(transactionSampleRateRt.decode(null))).toBe(false);
expect(isRight(transactionSampleRateRt.decode(''))).toBe(false);
});

it('accepts both strings and numbers as values', () => {
expect(isRight(transactionSampleRateRt.decode('0.5'))).toBe(true);
expect(isRight(transactionSampleRateRt.decode(0.5))).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const transactionSampleRateRt = new t.Type<number, number, unknown>(
'TransactionSampleRate',
t.number.is,
(input, context) => {
const value = Number(input);
return value >= 0 && value <= 1 && Number(value.toFixed(3)) === value
const value = parseFloat(input as string);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why parseFloat? because it's more permissive than Number?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The opposite actually. Due to coercion Number('') => 0 whereas parseFloat('') => NaN.
I wanted to disallow empty values.

return value >= 0 && value <= 1 && parseFloat(value.toFixed(3)) === value
? t.success(value)
: t.failure(input, context);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
logStacktraceTab
} from './ErrorTabs';
import { Summary } from '../../../shared/Summary';
import { TimestampSummaryItem } from '../../../shared/Summary/TimestampSummaryItem';
import { TimestampTooltip } from '../../../shared/TimestampTooltip';
import { HttpInfoSummaryItem } from '../../../shared/Summary/HttpInfoSummaryItem';
import { TransactionDetailLink } from '../../../shared/Links/apm/TransactionDetailLink';
import { UserAgentSummaryItem } from '../../../shared/Summary/UserAgentSummaryItem';
Expand Down Expand Up @@ -114,7 +114,7 @@ export function DetailView({ errorGroup, urlParams, location }: Props) {

<Summary
items={[
<TimestampSummaryItem time={error.timestamp.us / 1000} />,
<TimestampTooltip time={error.timestamp.us / 1000} />,
errorUrl && method ? (
<HttpInfoSummaryItem
url={errorUrl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TransactionDetails } from '../../TransactionDetails';
import { Home } from '../../Home';
import { BreadcrumbRoute } from '../ProvideBreadcrumbs';
import { RouteName } from './route_names';
import { Settings } from '../../Settings';
import { AgentConfigurations } from '../../Settings/AgentConfigurations';
import { toQuery } from '../../../shared/Links/url_helpers';
import { ServiceNodeMetrics } from '../../ServiceNodeMetrics';
import { resolveUrlParams } from '../../../../context/UrlParamsContext/resolveUrlParams';
Expand Down Expand Up @@ -67,7 +67,7 @@ export const routes: BreadcrumbRoute[] = [
{
exact: true,
path: '/settings',
component: Settings,
component: AgentConfigurations,
breadcrumb: i18n.translate('xpack.apm.breadcrumb.listSettingsTitle', {
defaultMessage: 'Settings'
}),
Expand Down
Loading