-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Dependencies table for backend inventory/detail views (#106995)
- Loading branch information
1 parent
2a9d17c
commit efd2540
Showing
35 changed files
with
1,630 additions
and
993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { AgentName } from '../typings/es_schemas/ui/fields/agent'; | ||
import { Coordinate } from '../typings/timeseries'; | ||
|
||
export enum NodeType { | ||
service = 'service', | ||
backend = 'backend', | ||
} | ||
|
||
interface NodeBase { | ||
id: string; | ||
} | ||
|
||
export interface ServiceNode extends NodeBase { | ||
type: NodeType.service; | ||
serviceName: string; | ||
agentName: AgentName; | ||
environment: string; | ||
} | ||
|
||
export interface BackendNode extends NodeBase { | ||
type: NodeType.backend; | ||
backendName: string; | ||
spanType: string; | ||
spanSubtype: string; | ||
} | ||
|
||
export type Node = ServiceNode | BackendNode; | ||
|
||
export interface ConnectionStatsItem { | ||
location: Node; | ||
stats: { | ||
latency: { | ||
value: number | null; | ||
timeseries: Coordinate[]; | ||
}; | ||
throughput: { | ||
value: number | null; | ||
timeseries: Coordinate[]; | ||
}; | ||
errorRate: { | ||
value: number | null; | ||
timeseries: Coordinate[]; | ||
}; | ||
}; | ||
} | ||
|
||
export interface ConnectionStatsItemWithImpact extends ConnectionStatsItem { | ||
stats: ConnectionStatsItem['stats'] & { | ||
impact: number; | ||
}; | ||
} | ||
|
||
export interface ConnectionStatsItemWithComparisonData { | ||
location: Node; | ||
currentStats: ConnectionStatsItemWithImpact['stats']; | ||
previousStats: ConnectionStatsItemWithImpact['stats'] | null; | ||
} | ||
|
||
export function getNodeName(node: Node) { | ||
return node.type === NodeType.service ? node.serviceName : node.backendName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...s/apm/public/components/app/backend_detail_overview/backend_detail_dependencies_table.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { getNodeName, NodeType } from '../../../../common/connections'; | ||
import { useApmParams } from '../../../hooks/use_apm_params'; | ||
import { useUrlParams } from '../../../context/url_params_context/use_url_params'; | ||
import { useFetcher } from '../../../hooks/use_fetcher'; | ||
import { getTimeRangeComparison } from '../../shared/time_comparison/get_time_range_comparison'; | ||
import { DependenciesTable } from '../../shared/dependencies_table'; | ||
import { useApmBackendContext } from '../../../context/apm_backend/use_apm_backend_context'; | ||
import { ServiceLink } from '../../shared/service_link'; | ||
|
||
export function BackendDetailDependenciesTable() { | ||
const { | ||
urlParams: { start, end, environment, comparisonEnabled, comparisonType }, | ||
} = useUrlParams(); | ||
|
||
const { | ||
query: { rangeFrom, rangeTo, kuery }, | ||
} = useApmParams('/backends/:backendName/overview'); | ||
|
||
const { offset } = getTimeRangeComparison({ | ||
start, | ||
end, | ||
comparisonEnabled, | ||
comparisonType, | ||
}); | ||
|
||
const { backendName } = useApmBackendContext(); | ||
|
||
const { data, status } = useFetcher( | ||
(callApmApi) => { | ||
if (!start || !end) { | ||
return; | ||
} | ||
|
||
return callApmApi({ | ||
endpoint: 'GET /api/apm/backends/{backendName}/upstream_services', | ||
params: { | ||
path: { | ||
backendName, | ||
}, | ||
query: { start, end, environment, numBuckets: 20, offset }, | ||
}, | ||
}); | ||
}, | ||
[start, end, environment, offset, backendName] | ||
); | ||
|
||
const dependencies = | ||
data?.services.map((dependency) => { | ||
const { location } = dependency; | ||
const name = getNodeName(location); | ||
|
||
if (location.type !== NodeType.service) { | ||
throw new Error('Expected a service node'); | ||
} | ||
|
||
return { | ||
name, | ||
currentStats: dependency.currentStats, | ||
previousStats: dependency.previousStats, | ||
link: ( | ||
<ServiceLink | ||
serviceName={location.serviceName} | ||
agentName={location.agentName} | ||
query={{ | ||
comparisonEnabled: comparisonEnabled ? 'true' : 'false', | ||
comparisonType, | ||
environment, | ||
kuery, | ||
rangeFrom, | ||
rangeTo, | ||
latencyAggregationType: undefined, | ||
transactionType: undefined, | ||
}} | ||
/> | ||
), | ||
}; | ||
}) ?? []; | ||
|
||
return ( | ||
<DependenciesTable | ||
dependencies={dependencies} | ||
title={i18n.translate('xpack.apm.backendDetail.dependenciesTableTitle', { | ||
defaultMessage: 'Upstream services', | ||
})} | ||
nameColumnTitle={i18n.translate( | ||
'xpack.apm.backendDetail.dependenciesTableColumnBackend', | ||
{ | ||
defaultMessage: 'Service', | ||
} | ||
)} | ||
status={status} | ||
compact={false} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...pm/public/components/app/backend_inventory/backend_inventory_dependencies_table/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { getNodeName, NodeType } from '../../../../../common/connections'; | ||
import { useApmParams } from '../../../../hooks/use_apm_params'; | ||
import { useUrlParams } from '../../../../context/url_params_context/use_url_params'; | ||
import { useFetcher } from '../../../../hooks/use_fetcher'; | ||
import { getTimeRangeComparison } from '../../../shared/time_comparison/get_time_range_comparison'; | ||
import { DependenciesTable } from '../../../shared/dependencies_table'; | ||
import { BackendLink } from '../../../shared/backend_link'; | ||
|
||
export function BackendInventoryDependenciesTable() { | ||
const { | ||
urlParams: { start, end, environment, comparisonEnabled, comparisonType }, | ||
} = useUrlParams(); | ||
|
||
const { | ||
query: { rangeFrom, rangeTo, kuery }, | ||
} = useApmParams('/backends'); | ||
|
||
const { offset } = getTimeRangeComparison({ | ||
start, | ||
end, | ||
comparisonEnabled, | ||
comparisonType, | ||
}); | ||
|
||
const { data, status } = useFetcher( | ||
(callApmApi) => { | ||
if (!start || !end) { | ||
return; | ||
} | ||
|
||
return callApmApi({ | ||
endpoint: 'GET /api/apm/backends/top_backends', | ||
params: { | ||
query: { start, end, environment, numBuckets: 20, offset }, | ||
}, | ||
}); | ||
}, | ||
[start, end, environment, offset] | ||
); | ||
|
||
const dependencies = | ||
data?.backends.map((dependency) => { | ||
const { location } = dependency; | ||
const name = getNodeName(location); | ||
|
||
if (location.type !== NodeType.backend) { | ||
throw new Error('Expected a backend node'); | ||
} | ||
const link = ( | ||
<BackendLink | ||
backendName={location.backendName} | ||
type={location.spanType} | ||
subtype={location.spanSubtype} | ||
query={{ | ||
comparisonEnabled: comparisonEnabled ? 'true' : 'false', | ||
comparisonType, | ||
environment, | ||
kuery, | ||
rangeFrom, | ||
rangeTo, | ||
}} | ||
/> | ||
); | ||
|
||
return { | ||
name, | ||
currentStats: dependency.currentStats, | ||
previousStats: dependency.previousStats, | ||
link, | ||
}; | ||
}) ?? []; | ||
|
||
return ( | ||
<DependenciesTable | ||
dependencies={dependencies} | ||
title={i18n.translate( | ||
'xpack.apm.backendInventory.dependenciesTableTitle', | ||
{ | ||
defaultMessage: 'Backends', | ||
} | ||
)} | ||
nameColumnTitle={i18n.translate( | ||
'xpack.apm.backendInventory.dependenciesTableColumnBackend', | ||
{ | ||
defaultMessage: 'Backend', | ||
} | ||
)} | ||
status={status} | ||
compact={false} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.