forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
219 lines (202 loc) · 6.37 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
* 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 {
EuiFlexGrid,
EuiFlexGroup,
EuiFlexItem,
EuiIconTip,
EuiPanel,
EuiText,
EuiTitle
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { Location } from 'history';
import React, { Component } from 'react';
import { isEmpty } from 'lodash';
import styled from 'styled-components';
import { idx } from '@kbn/elastic-idx';
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n';
import { Coordinate } from '../../../../../typings/timeseries';
import { ITransactionChartData } from '../../../../selectors/chartSelectors';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { asInteger, asMillis, tpmUnit } from '../../../../utils/formatters';
import { MLJobLink } from '../../Links/MachineLearningLinks/MLJobLink';
import { LicenseContext } from '../../../../context/LicenseContext';
import { TransactionLineChart } from './TransactionLineChart';
import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue';
interface TransactionChartProps {
hasMLJob: boolean;
charts: ITransactionChartData;
location: Location;
urlParams: IUrlParams;
}
const ShiftedIconWrapper = styled.span`
padding-right: 5px;
position: relative;
top: -1px;
display: inline-block;
`;
const ShiftedEuiText = styled(EuiText)`
position: relative;
top: 5px;
`;
export class TransactionCharts extends Component<TransactionChartProps> {
public getResponseTimeTickFormatter = (t: number) => {
return asMillis(t);
};
public getResponseTimeTooltipFormatter = (p: Coordinate) => {
return isValidCoordinateValue(p.y) ? asMillis(p.y) : NOT_AVAILABLE_LABEL;
};
public getTPMFormatter = (t: number) => {
const { urlParams } = this.props;
const unit = tpmUnit(urlParams.transactionType);
return `${asInteger(t)} ${unit}`;
};
public getTPMTooltipFormatter = (p: Coordinate) => {
return isValidCoordinateValue(p.y)
? this.getTPMFormatter(p.y)
: NOT_AVAILABLE_LABEL;
};
public renderMLHeader(hasValidMlLicense: boolean | undefined) {
const { hasMLJob } = this.props;
if (!hasValidMlLicense || !hasMLJob) {
return null;
}
const { serviceName, transactionType, kuery } = this.props.urlParams;
if (!serviceName) {
return null;
}
const hasKuery = !isEmpty(kuery);
const icon = hasKuery ? (
<EuiIconTip
aria-label="Warning"
type="alert"
color="warning"
content="The Machine learning results are hidden when the search bar is used for filtering"
/>
) : (
<EuiIconTip
content={i18n.translate(
'xpack.apm.metrics.transactionChart.machineLearningTooltip',
{
defaultMessage:
'The stream around the average duration shows the expected bounds. An annotation is shown for anomaly scores >= 75.'
}
)}
/>
);
return (
<EuiFlexItem grow={false}>
<ShiftedEuiText size="xs">
<ShiftedIconWrapper>{icon}</ShiftedIconWrapper>
<span>
{i18n.translate(
'xpack.apm.metrics.transactionChart.machineLearningLabel',
{
defaultMessage: 'Machine learning:'
}
)}{' '}
</span>
<MLJobLink
serviceName={serviceName}
transactionType={transactionType}
>
View Job
</MLJobLink>
</ShiftedEuiText>
</EuiFlexItem>
);
}
public render() {
const { charts, urlParams } = this.props;
const { responseTimeSeries, tpmSeries } = charts;
const { transactionType } = urlParams;
return (
<EuiFlexGrid columns={2} gutterSize="s">
<EuiFlexItem>
<EuiPanel>
<React.Fragment>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem>
<EuiTitle size="xs">
<span>{responseTimeLabel(transactionType)}</span>
</EuiTitle>
</EuiFlexItem>
<LicenseContext.Consumer>
{license =>
this.renderMLHeader(
idx(license, _ => _.features.ml.is_available)
)
}
</LicenseContext.Consumer>
</EuiFlexGroup>
<TransactionLineChart
series={responseTimeSeries}
tickFormatY={this.getResponseTimeTickFormatter}
formatTooltipValue={this.getResponseTimeTooltipFormatter}
/>
</React.Fragment>
</EuiPanel>
</EuiFlexItem>
<EuiFlexItem style={{ flexShrink: 1 }}>
<EuiPanel>
<React.Fragment>
<EuiTitle size="xs">
<span>{tpmLabel(transactionType)}</span>
</EuiTitle>
<TransactionLineChart
series={tpmSeries}
tickFormatY={this.getTPMFormatter}
formatTooltipValue={this.getTPMTooltipFormatter}
truncateLegends
/>
</React.Fragment>
</EuiPanel>
</EuiFlexItem>
</EuiFlexGrid>
);
}
}
function tpmLabel(type?: string) {
return type === 'request'
? i18n.translate(
'xpack.apm.metrics.transactionChart.requestsPerMinuteLabel',
{
defaultMessage: 'Requests per minute'
}
)
: i18n.translate(
'xpack.apm.metrics.transactionChart.transactionsPerMinuteLabel',
{
defaultMessage: 'Transactions per minute'
}
);
}
function responseTimeLabel(type?: string) {
switch (type) {
case 'page-load':
return i18n.translate(
'xpack.apm.metrics.transactionChart.pageLoadTimesLabel',
{
defaultMessage: 'Page load times'
}
);
case 'route-change':
return i18n.translate(
'xpack.apm.metrics.transactionChart.routeChangeTimesLabel',
{
defaultMessage: 'Route change times'
}
);
default:
return i18n.translate(
'xpack.apm.metrics.transactionChart.transactionDurationLabel',
{
defaultMessage: 'Transaction duration'
}
);
}
}