Skip to content

Commit

Permalink
[Uptime] remove latency limit warnings when using monitor management (#…
Browse files Browse the repository at this point in the history
…129597) (#130082)

(cherry picked from commit 1a6b234)

Co-authored-by: Lucas F. da Costa <lucas.costa@elastic.co>
  • Loading branch information
kibanamachine and lucasfcosta authored Apr 13, 2022
1 parent 2ea6dc8 commit 114ac53
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ import { tEnum } from '../../utils/t_enum';
export enum BandwidthLimitKey {
DOWNLOAD = 'download',
UPLOAD = 'upload',
LATENCY = 'latency',
}

export const DEFAULT_BANDWIDTH_LIMIT = {
[BandwidthLimitKey.DOWNLOAD]: 100,
[BandwidthLimitKey.UPLOAD]: 30,
[BandwidthLimitKey.LATENCY]: 1000,
};

export const DEFAULT_THROTTLING = {
[BandwidthLimitKey.DOWNLOAD]: DEFAULT_BANDWIDTH_LIMIT[BandwidthLimitKey.DOWNLOAD],
[BandwidthLimitKey.UPLOAD]: DEFAULT_BANDWIDTH_LIMIT[BandwidthLimitKey.UPLOAD],
[BandwidthLimitKey.LATENCY]: DEFAULT_BANDWIDTH_LIMIT[BandwidthLimitKey.LATENCY],
};

export const BandwidthLimitKeyCodec = tEnum<BandwidthLimitKey>(
Expand Down Expand Up @@ -93,7 +90,6 @@ export const isServiceLocationInvalid = (location: ServiceLocation) =>
export const ThrottlingOptionsCodec = t.interface({
[BandwidthLimitKey.DOWNLOAD]: t.number,
[BandwidthLimitKey.UPLOAD]: t.number,
[BandwidthLimitKey.LATENCY]: t.number,
});

export const ServiceLocationsApiResponseCodec = t.interface({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ describe('<ThrottlingFields />', () => {
const throttling = {
[BandwidthLimitKey.DOWNLOAD]: 100,
[BandwidthLimitKey.UPLOAD]: 50,
[BandwidthLimitKey.LATENCY]: 25,
};

const defaultLocations = [defaultLocation];
Expand Down Expand Up @@ -338,54 +337,6 @@ describe('<ThrottlingFields />', () => {
)
).not.toBeInTheDocument();
});

it("shows latency warnings when exceeding the node's latency limits", () => {
const { getByLabelText, queryByText } = render(
<WrappedComponent
policyConfigOverrides={{ throttling, defaultLocations, runsOnService: true }}
/>
);

const latencyLimit = throttling[BandwidthLimitKey.LATENCY];

const latency = getByLabelText('Latency') as HTMLInputElement;
userEvent.clear(latency);
userEvent.type(latency, String(latencyLimit + 1));

expect(
queryByText(
`You have exceeded the latency limit for Synthetic Nodes. The latency value can't be larger than ${latencyLimit}ms.`
)
).toBeInTheDocument();

expect(
queryByText("You've exceeded the Synthetics Node bandwidth limits")
).toBeInTheDocument();

expect(
queryByText(
'When using throttling values larger than a Synthetics Node bandwidth limit, your monitor will still have its bandwidth capped.'
)
).toBeInTheDocument();

userEvent.clear(latency);
userEvent.type(latency, String(latencyLimit - 1));
expect(
queryByText(
`You have exceeded the latency limit for Synthetic Nodes. The latency value can't be larger than ${latencyLimit}ms.`
)
).not.toBeInTheDocument();

expect(
queryByText("You've exceeded the Synthetics Node bandwidth limits")
).not.toBeInTheDocument();

expect(
queryByText(
'When using throttling values larger than a Synthetics Node bandwidth limit, your monitor will still have its bandwidth capped.'
)
).not.toBeInTheDocument();
});
});

it('only displays download, upload, and latency fields with throttling is on', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,15 @@ export const ThrottlingExceededCallout = () => {
export const ThrottlingExceededMessage = ({
throttlingField,
limit,
unit,
}: {
throttlingField: string;
limit: number;
unit: string;
}) => {
return (
<FormattedMessage
id="xpack.uptime.createPackagePolicy.stepConfigure.browserAdvancedSettings.throttling.throttling_exceeded.message"
defaultMessage="You have exceeded the { throttlingField } limit for Synthetic Nodes. The { throttlingField } value can't be larger than { limit }{unit}."
values={{ throttlingField, limit, unit }}
defaultMessage="You have exceeded the { throttlingField } limit for Synthetic Nodes. The { throttlingField } value can't be larger than { limit }Mbps."
values={{ throttlingField, limit }}
/>
);
};
Expand All @@ -97,7 +95,6 @@ export const ThrottlingFields = memo<Props>(({ validate, minColumnWidth, onField

const maxDownload = throttling[BandwidthLimitKey.DOWNLOAD];
const maxUpload = throttling[BandwidthLimitKey.UPLOAD];
const maxLatency = throttling[BandwidthLimitKey.LATENCY];

const handleInputChange = useCallback(
({ value, configKey }: { value: unknown; configKey: ThrottlingConfigs }) => {
Expand All @@ -110,7 +107,6 @@ export const ThrottlingFields = memo<Props>(({ validate, minColumnWidth, onField
runsOnService && parseFloat(fields[ConfigKey.DOWNLOAD_SPEED]) > maxDownload;
const exceedsUploadLimits =
runsOnService && parseFloat(fields[ConfigKey.UPLOAD_SPEED]) > maxUpload;
const exceedsLatencyLimits = runsOnService && parseFloat(fields[ConfigKey.LATENCY]) > maxLatency;
const isThrottlingEnabled = fields[ConfigKey.IS_THROTTLING_ENABLED];

const throttlingInputs = isThrottlingEnabled ? (
Expand All @@ -127,7 +123,7 @@ export const ThrottlingFields = memo<Props>(({ validate, minColumnWidth, onField
isInvalid={!!validate[ConfigKey.DOWNLOAD_SPEED]?.(fields) || exceedsDownloadLimits}
error={
exceedsDownloadLimits ? (
<ThrottlingExceededMessage throttlingField="download" limit={maxDownload} unit="Mbps" />
<ThrottlingExceededMessage throttlingField="download" limit={maxDownload} />
) : (
<FormattedMessage
id="xpack.uptime.createPackagePolicy.stepConfigure.browserAdvancedSettings.throttling.download.error"
Expand Down Expand Up @@ -166,7 +162,7 @@ export const ThrottlingFields = memo<Props>(({ validate, minColumnWidth, onField
isInvalid={!!validate[ConfigKey.UPLOAD_SPEED]?.(fields) || exceedsUploadLimits}
error={
exceedsUploadLimits ? (
<ThrottlingExceededMessage throttlingField="upload" limit={maxUpload} unit="Mbps" />
<ThrottlingExceededMessage throttlingField="upload" limit={maxUpload} />
) : (
<FormattedMessage
id="xpack.uptime.createPackagePolicy.stepConfigure.browserAdvancedSettings.throttling.upload.error"
Expand Down Expand Up @@ -202,16 +198,12 @@ export const ThrottlingFields = memo<Props>(({ validate, minColumnWidth, onField
/>
}
labelAppend={<OptionalLabel />}
isInvalid={!!validate[ConfigKey.LATENCY]?.(fields) || exceedsLatencyLimits}
isInvalid={!!validate[ConfigKey.LATENCY]?.(fields)}
error={
exceedsLatencyLimits ? (
<ThrottlingExceededMessage throttlingField="latency" limit={maxLatency} unit="ms" />
) : (
<FormattedMessage
id="xpack.uptime.createPackagePolicy.stepConfigure.browserAdvancedSettings.throttling.latency.error"
defaultMessage="Latency must not be negative."
/>
)
<FormattedMessage
id="xpack.uptime.createPackagePolicy.stepConfigure.browserAdvancedSettings.throttling.latency.error"
defaultMessage="Latency must not be negative."
/>
}
>
<EuiFieldNumber
Expand Down Expand Up @@ -277,8 +269,7 @@ export const ThrottlingFields = memo<Props>(({ validate, minColumnWidth, onField
}
onBlur={() => onFieldBlur?.(ConfigKey.IS_THROTTLING_ENABLED)}
/>
{isThrottlingEnabled &&
(exceedsDownloadLimits || exceedsUploadLimits || exceedsLatencyLimits) ? (
{isThrottlingEnabled && (exceedsDownloadLimits || exceedsUploadLimits) ? (
<>
<EuiSpacer />
<ThrottlingExceededCallout />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('getServiceLocations', function () {
throttling: {
[BandwidthLimitKey.DOWNLOAD]: 100,
[BandwidthLimitKey.UPLOAD]: 50,
[BandwidthLimitKey.LATENCY]: 20,
},
locations: {
us_central: {
Expand Down Expand Up @@ -50,7 +49,6 @@ describe('getServiceLocations', function () {
throttling: {
[BandwidthLimitKey.DOWNLOAD]: 100,
[BandwidthLimitKey.UPLOAD]: 50,
[BandwidthLimitKey.LATENCY]: 20,
},
locations: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export async function getServiceLocations(server: UptimeServerSetup) {
const throttling = pick(
data.throttling,
BandwidthLimitKey.DOWNLOAD,
BandwidthLimitKey.UPLOAD,
BandwidthLimitKey.LATENCY
BandwidthLimitKey.UPLOAD
) as ThrottlingOptions;

return { throttling, locations };
Expand Down

0 comments on commit 114ac53

Please sign in to comment.