Skip to content

Commit

Permalink
[APM] Fix ML links (elastic#22820)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Sep 8, 2018
1 parent 9452877 commit e7f8ad6
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ exports[`WatcherButton should render initial state 1`] = `
</EuiButton>
}
closePopover={[Function]}
hasArrow={true}
isOpen={false}
ownFocus={false}
panelPaddingSize="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
EuiSpacer,
EuiBetaBadge
} from '@elastic/eui';
import { getMlJobUrl, KibanaLink } from '../../../../utils/url';
import { KibanaLink, ViewMLJob } from '../../../../utils/url';

export default class DynamicBaselineFlyout extends Component {
state = {
Expand Down Expand Up @@ -68,10 +68,15 @@ export default class DynamicBaselineFlyout extends Component {
text: (
<p>
There&apos;s already a job running for anomaly detection on{' '}
{serviceName} ({transactionType}).{' '}
<a href={getMlJobUrl(serviceName, transactionType, location)}>
{serviceName} ({transactionType}
).{' '}
<ViewMLJob
serviceName={serviceName}
transactionType={transactionType}
location={location}
>
View existing job
</a>
</ViewMLJob>
</p>
)
}
Expand All @@ -89,12 +94,16 @@ export default class DynamicBaselineFlyout extends Component {
color: 'success',
text: (
<p>
The analysis is now running for {serviceName} ({transactionType}).
It might take a while before results are added to the response
The analysis is now running for {serviceName} ({transactionType}
). It might take a while before results are added to the response
times graph.{' '}
<a href={getMlJobUrl(serviceName, transactionType, location)}>
<ViewMLJob
serviceName={serviceName}
transactionType={transactionType}
location={location}
>
View job
</a>
</ViewMLJob>
</p>
)
}
Expand Down Expand Up @@ -140,12 +149,16 @@ export default class DynamicBaselineFlyout extends Component {
iconType="check"
>
<p>
There is currently a job running for {serviceName} ({
transactionType
}).{' '}
<a href={getMlJobUrl(serviceName, transactionType, location)}>
There is currently a job running for {serviceName} (
{transactionType}
).{' '}
<ViewMLJob
serviceName={serviceName}
transactionType={transactionType}
location={location}
>
View existing job
</a>
</ViewMLJob>
</p>
</EuiCallOut>
<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ exports[`MLButton should render initial state 1`] = `
</EuiButton>
}
closePopover={[Function]}
hasArrow={true}
isOpen={false}
ownFocus={false}
panelPaddingSize="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { get } from 'lodash';
import { HeaderContainer, HeaderMedium } from '../../shared/UIComponents';
import TabNavigation from '../../shared/TabNavigation';
import Charts from '../../shared/charts/TransactionCharts';
import { getMlJobUrl, KibanaLink } from '../../../utils/url';
import { ViewMLJob } from '../../../utils/url';
import List from './List';
import { units, px, fontSizes } from '../../../style/variables';
import { OverviewChartsRequest } from '../../../store/reactReduxRequest/overviewCharts';
Expand Down Expand Up @@ -75,15 +75,13 @@ class TransactionOverview extends Component {
<EuiIconTip content="The stream around the average response time shows the expected bounds. An annotation is shown for anomaly scores &gt;= 75." />
<MLText>
Machine Learning:{' '}
<KibanaLink
pathname={getMlJobUrl(
serviceName,
transactionType,
this.props.location
)}
<ViewMLJob
serviceName={serviceName}
transactionType={transactionType}
location={this.props.location}
>
View Job
</KibanaLink>
View job
</ViewMLJob>
</MLText>
</MLTipContainer>
) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ exports[`RelativeLinkComponent should render correct markup 1`] = `
Go to Discover
</a>
`;

exports[`ViewMLJob should render component 1`] = `
<Connect(KibanaLinkComponent)
hash="/timeseriesexplorer"
pathname="/app/ml"
query={
Object {
"_a": null,
"_g": Object {
"ml": Object {
"jobIds": Array [
"myServiceName-myTransactionType-high_mean_response_time",
],
},
},
}
}
>
View Job
</Connect(KibanaLinkComponent)>
`;
44 changes: 30 additions & 14 deletions x-pack/plugins/apm/public/utils/__test__/url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

import React from 'react';
import { Router } from 'react-router-dom';
import { mount } from 'enzyme';
import { mount, shallow } from 'enzyme';
import createHistory from 'history/createMemoryHistory';

import {
toQuery,
fromQuery,
KibanaLinkComponent,
RelativeLinkComponent,
encodeKibanaSearchParams,
decodeKibanaSearchParams,
getMlJobUrl
ViewMLJob
} from '../url';
import { toJson } from '../testHelpers';

Expand Down Expand Up @@ -221,22 +220,39 @@ describe('KibanaLinkComponent', () => {
});
});

describe('getMlJobUrl', () => {
it('should have correct url', () => {
const serviceName = 'myServiceName';
const transactionType = 'myTransactionType';
describe('ViewMLJob', () => {
it('should render component', () => {
const location = { search: '' };
expect(getMlJobUrl(serviceName, transactionType, location)).toBe(
'/app/ml#/timeseriesexplorer/?_g=(ml:(jobIds:!(myServiceName-myTransactionType-high_mean_response_time)))&_a=!n'
const wrapper = shallow(
<ViewMLJob
serviceName="myServiceName"
transactionType="myTransactionType"
location={location}
/>
);

expect(toJson(wrapper)).toMatchSnapshot();
});

it('should not contain basePath', () => {
const serviceName = 'myServiceName';
const transactionType = 'myTransactionType';
it('should have correct path props', () => {
const location = { search: '' };
expect(getMlJobUrl(serviceName, transactionType, location)).toBe(
'/app/ml#/timeseriesexplorer/?_g=(ml:(jobIds:!(myServiceName-myTransactionType-high_mean_response_time)))&_a=!n'
const wrapper = shallow(
<ViewMLJob
serviceName="myServiceName"
transactionType="myTransactionType"
location={location}
/>
);

expect(wrapper.prop('pathname')).toBe('/app/ml');
expect(wrapper.prop('hash')).toBe('/timeseriesexplorer');
expect(wrapper.prop('query')).toEqual({
_a: null,
_g: {
ml: {
jobIds: ['myServiceName-myTransactionType-high_mean_response_time']
}
}
});
});
});
23 changes: 19 additions & 4 deletions x-pack/plugins/apm/public/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,34 @@ import { EuiLink } from '@elastic/eui';
import createHistory from 'history/createHashHistory';
import chrome from 'ui/chrome';

export function getMlJobUrl(serviceName, transactionType, location) {
export function ViewMLJob({
serviceName,
transactionType,
location,
children = 'View Job'
}) {
const { _g, _a } = decodeKibanaSearchParams(location.search);
const nextSearch = encodeKibanaSearchParams({

const pathname = '/app/ml';
const hash = '/timeseriesexplorer';
const query = {
_g: {
..._g,
ml: {
jobIds: [`${serviceName}-${transactionType}-high_mean_response_time`]
}
},
_a
});
};

return `/app/ml#/timeseriesexplorer/?${nextSearch}`;
return (
<KibanaLink
pathname={pathname}
hash={hash}
query={query}
children={children}
/>
);
}

export function toQuery(search) {
Expand Down

0 comments on commit e7f8ad6

Please sign in to comment.