[APM] Fix linking between errors and transactions, and link from errors to Discover (#28477) (#28585)

* [APM] Fix linking between errors and transactions, and link from errors to Discover

* Add tests
This commit is contained in:
Søren Louv-Jansen 2019-01-11 22:00:20 +01:00 committed by GitHub
parent 9d830f6a1e
commit 1c3444354f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 3 deletions

View file

@ -79,7 +79,7 @@ exports[`DetailView should render StickyProperties 1`] = `
pathname="/app/apm"
query={
Object {
"traceid": "traceId",
"traceId": "traceId",
"transactionId": "myTransactionName",
}
}

View file

@ -197,7 +197,7 @@ function getTransactionLink(error: APMError, transaction?: Transaction) {
hash={path}
query={{
transactionId: transaction.transaction.id,
traceid: get(transaction, TRACE_ID)
traceId: get(transaction, TRACE_ID)
}}
>
{transaction.transaction.id}

View file

@ -17,7 +17,7 @@ function getDiscoverQuery(error: APMError, kuery?: string) {
const groupId = error.error.grouping_key;
let query = `${SERVICE_NAME}:"${serviceName}" AND ${ERROR_GROUP_ID}:"${groupId}"`;
if (kuery) {
query = ` AND ${kuery}`;
query += ` AND ${kuery}`;
}
return {

View file

@ -0,0 +1,59 @@
/*
* 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 { shallow, ShallowWrapper } from 'enzyme';
import 'jest-styled-components';
import React from 'react';
import { APMError } from 'x-pack/plugins/apm/typings/es_schemas/Error';
import { DiscoverErrorButton } from '../DiscoverErrorButton';
describe('DiscoverErrorButton without kuery', () => {
let wrapper: ShallowWrapper;
beforeEach(() => {
const error = {
context: { service: { name: 'myServiceName' } },
error: { grouping_key: 'myGroupingKey' }
} as APMError;
wrapper = shallow(<DiscoverErrorButton error={error} />);
});
it('should have correct query', () => {
const queryProp = wrapper.prop('query') as any;
expect(queryProp._a.query.query).toEqual(
'context.service.name:"myServiceName" AND error.grouping_key:"myGroupingKey"'
);
});
it('should match snapshot', () => {
expect(wrapper).toMatchSnapshot();
});
});
describe('DiscoverErrorButton with kuery', () => {
let wrapper: ShallowWrapper;
beforeEach(() => {
const error = {
context: { service: { name: 'myServiceName' } },
error: { grouping_key: 'myGroupingKey' }
} as APMError;
const kuery = 'transaction.sampled: true';
wrapper = shallow(<DiscoverErrorButton error={error} kuery={kuery} />);
});
it('should have correct query', () => {
const queryProp = wrapper.prop('query') as any;
expect(queryProp._a.query.query).toEqual(
'context.service.name:"myServiceName" AND error.grouping_key:"myGroupingKey" AND transaction.sampled: true'
);
});
it('should match snapshot', () => {
expect(wrapper).toMatchSnapshot();
});
});

View file

@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`DiscoverErrorButton with kuery should match snapshot 1`] = `
<DiscoverButton
query={
Object {
"_a": Object {
"interval": "auto",
"query": Object {
"language": "lucene",
"query": "context.service.name:\\"myServiceName\\" AND error.grouping_key:\\"myGroupingKey\\" AND transaction.sampled: true",
},
"sort": Object {
"@timestamp": "desc",
},
},
}
}
/>
`;
exports[`DiscoverErrorButton without kuery should match snapshot 1`] = `
<DiscoverButton
query={
Object {
"_a": Object {
"interval": "auto",
"query": Object {
"language": "lucene",
"query": "context.service.name:\\"myServiceName\\" AND error.grouping_key:\\"myGroupingKey\\"",
},
"sort": Object {
"@timestamp": "desc",
},
},
}
}
/>
`;