Skip to content

Commit

Permalink
[Uptime] Use service.name to link from Uptime -> APM where available (
Browse files Browse the repository at this point in the history
#73618) (#73666)

With elastic/beats#19932 coming in 7.10 adding
the `service.name` ECS field is very easy. We should prefer this field
when cross linking to APM, hence this PR.

Resolves elastic/uptime#220
# Conflicts:
#	x-pack/plugins/uptime/public/lib/helper/observability_integration/get_apm_href.ts
  • Loading branch information
andrewvc authored Aug 5, 2020
1 parent 98cd061 commit 4a4b1e0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/uptime/common/runtime_types/monitor/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const StateType = t.intersection([
name: t.array(t.string),
}),
}),
service: t.partial({
name: t.string,
}),
}),
]);

Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/uptime/common/runtime_types/ping/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ export const PingType = t.intersection([
port: t.number,
scheme: t.string,
}),
service: t.partial({
name: t.string,
}),
}),
]);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ export const IntegrationGroup = ({ summary }: IntegrationGroupProps) => {
href={getApmHref(summary, basePath, dateRangeStart, dateRangeEnd)}
iconType="apmApp"
message={i18n.translate('xpack.uptime.apmIntegrationAction.text', {
defaultMessage: 'Check APM for domain',
defaultMessage: 'Show APM Data',
description:
'A message explaining that when the user clicks the associated link, it will navigate to the APM app and search for the selected domain',
'A message explaining that when the user clicks the associated link, it will navigate to the APM app',
})}
tooltipContent={i18n.translate(
'xpack.uptime.monitorList.observabilityIntegrationsColumn.apmIntegrationLink.tooltip',
{
defaultMessage: 'Click here to check APM for the domain "{domain}".',
defaultMessage:
'Click here to check APM for the domain "{domain}" or explicitly defined "service name".',
description:
'A messsage shown in a tooltip explaining that the nested anchor tag will navigate to the APM app and search for the given URL domain.',
'A messsage shown in a tooltip explaining that the nested anchor tag will navigate to the APM app and search for the given URL domain or explicitly defined service name.',
values: {
domain,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { MonitorSummary, makePing } from '../../../../../common/runtime_types';

describe('getApmHref', () => {
let summary: MonitorSummary;

beforeEach(() => {
summary = {
monitor_id: 'foo',
Expand Down Expand Up @@ -49,4 +48,18 @@ describe('getApmHref', () => {
`"/app/apm#/services?kuery=url.domain:%20%22www.elastic.co%22&rangeFrom=now-15m&rangeTo=now"`
);
});

describe('with service.name', () => {
const serviceName = 'MyServiceName';
beforeEach(() => {
summary.state.service = { name: serviceName };
});

it('links to the named service', () => {
const result = getApmHref(summary, 'foo', 'now-15m', 'now');
expect(result).toMatchInlineSnapshot(
`"foo/app/apm#/services?kuery=service.name:%20%22${serviceName}%22&rangeFrom=now-15m&rangeTo=now"`
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ export const getApmHref = (
basePath: string,
dateRangeStart: string,
dateRangeEnd: string
) =>
addBasePath(
) => {
const clause = summary?.state?.service?.name
? `service.name: "${summary.state.service.name}"`
: `url.domain: "${summary.state.url?.domain}"`;

return addBasePath(
basePath,
`/app/apm#/services?kuery=${encodeURI(
`url.domain: "${summary?.state?.url?.domain}"`
clause
)}&rangeFrom=${dateRangeStart}&rangeTo=${dateRangeEnd}`
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const summaryPingsToSummary = (summaryPings: Ping[]): MonitorSummary => {
observer: {
geo: { name: summaryPings.map((p) => p.observer?.geo?.name ?? '').filter((n) => n !== '') },
},
service: summaryPings.find((p) => p.service?.name)?.service,
},
};
};
Expand Down

0 comments on commit 4a4b1e0

Please sign in to comment.