Skip to content

Commit 3a869ca

Browse files
upcoming: [DI-25353] - Fetching the alerting time intervals from /services api (linode#12466)
* upcoming: [DI-25353] - Fetching the alerting time intervals from /services api * upcoming: [Di-25353] - Add unit test for the convert util * add changeset * upcoming: [DI-25353] - Add timeout to failing unit test --------- Co-authored-by: Nikhil Agrawal <[email protected]>
1 parent 9f34a32 commit 3a869ca

File tree

13 files changed

+267
-153
lines changed

13 files changed

+267
-153
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/api-v4": Changed
3+
---
4+
5+
ACLP:Alerting - fixed the typo from evaluation_periods_seconds to evaluation_period_seconds ([#12466](https://github.com/linode/manager/pull/12466))

packages/api-v4/src/cloudpulse/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export interface CloudPulseMetricsList {
168168
}
169169

170170
export interface ServiceAlert {
171-
evaluation_periods_seconds: number[];
171+
evaluation_period_seconds: number[];
172172
polling_interval_seconds: number[];
173173
scope: AlertDefinitionScope[];
174174
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
ACLP-Alerting: using latest /services api data to fetch the evaluation period and polling interval time options ([#12466](https://github.com/linode/manager/pull/12466))

packages/manager/src/factories/cloudpulse/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Factory } from '@linode/utilities';
44
import type { ServiceAlert } from '@linode/api-v4';
55

66
export const serviceAlertFactory = Factory.Sync.makeFactory<ServiceAlert>({
7-
polling_interval_seconds: [1, 5, 10, 15],
8-
evaluation_periods_seconds: [5, 10, 15, 20],
7+
evaluation_period_seconds: [300, 900, 1800, 3600],
8+
polling_interval_seconds: [300, 900, 1800, 3600],
99
scope: ['entity', 'region', 'account'],
1010
});
1111

packages/manager/src/features/CloudPulse/Alerts/CreateAlert/CreateAlertDefinition.test.tsx

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,38 +114,47 @@ describe('AlertDefinition Create', () => {
114114
},
115115
});
116116

117-
it('should render client side validation errors for threshold and trigger occurences text field', async () => {
118-
const user = userEvent.setup();
119-
const container = await renderWithThemeAndRouter(<CreateAlertDefinition />);
117+
it(
118+
'should render client side validation errors for threshold and trigger occurences text field',
119+
async () => {
120+
const user = userEvent.setup();
121+
const container = await renderWithThemeAndRouter(
122+
<CreateAlertDefinition />
123+
);
120124

121-
const serviceTypeInput = container.getByPlaceholderText('Select a Service');
122-
await user.click(serviceTypeInput);
125+
const serviceTypeInput =
126+
container.getByPlaceholderText('Select a Service');
127+
await user.click(serviceTypeInput);
123128

124-
await user.click(container.getByText('Linode'));
129+
await user.click(container.getByText('Linode'));
125130

126-
const dataFieldContainer = container.getByPlaceholderText(
127-
'Select a Data Field'
128-
);
131+
const dataFieldContainer = container.getByPlaceholderText(
132+
'Select a Data Field'
133+
);
129134

130-
await user.click(dataFieldContainer);
131-
await user.click(container.getByText('CPU utilization'));
135+
await user.click(dataFieldContainer);
136+
await user.click(container.getByText('CPU utilization'));
132137

133-
const submitButton = container.getByText('Submit');
138+
const submitButton = container.getByText('Submit');
134139

135-
await user.click(submitButton);
140+
await user.click(submitButton);
136141

137-
expect(container.getAllByText('Enter a positive value.').length).toBe(2);
142+
expect(container.getAllByText('Enter a positive value.').length).toBe(2);
138143

139-
const thresholdInput = container.getByLabelText('Threshold');
140-
const triggerOccurrences = container.getByTestId('trigger-occurences');
141-
await user.clear(thresholdInput);
142-
await user.clear(within(triggerOccurrences).getByTestId('textfield-input'));
143-
await user.click(submitButton!);
144+
const thresholdInput = container.getByLabelText('Threshold');
145+
const triggerOccurrences = container.getByTestId('trigger-occurences');
146+
await user.clear(thresholdInput);
147+
await user.clear(
148+
within(triggerOccurrences).getByTestId('textfield-input')
149+
);
150+
await user.click(submitButton!);
144151

145-
expect(container.getAllByText('The value should be a number.').length).toBe(
146-
2
147-
);
148-
});
152+
expect(
153+
container.getAllByText('The value should be a number.').length
154+
).toBe(2);
155+
},
156+
{ timeout: 10000 }
157+
);
149158

150159
it('should render the client side validation error messages for the form', async () => {
151160
const errorMessage = 'This field is required.';

packages/manager/src/features/CloudPulse/Alerts/CreateAlert/CreateAlertDefinition.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Breadcrumb } from 'src/components/Breadcrumb/Breadcrumb';
1111
import { DocumentTitleSegment } from 'src/components/DocumentTitle';
1212
import { useFlags } from 'src/hooks/useFlags';
1313
import { useCreateAlertDefinition } from 'src/queries/cloudpulse/alerts';
14+
import { useCloudPulseServiceByServiceType } from 'src/queries/cloudpulse/services';
1415

1516
import {
1617
CREATE_ALERT_ERROR_FIELD_MAP,
@@ -111,6 +112,14 @@ export const CreateAlertDefinition = () => {
111112
);
112113

113114
const serviceTypeWatcher = useWatch({ control, name: 'serviceType' });
115+
const {
116+
data: serviceMetadata,
117+
isLoading: serviceMetadataLoading,
118+
error: serviceMetadataError,
119+
} = useCloudPulseServiceByServiceType(
120+
serviceTypeWatcher ?? '',
121+
!!serviceTypeWatcher
122+
);
114123

115124
const [maxScrapeInterval, setMaxScrapeInterval] = React.useState<number>(0);
116125

@@ -221,6 +230,9 @@ export const CreateAlertDefinition = () => {
221230
<TriggerConditions
222231
maxScrapingInterval={maxScrapeInterval}
223232
name="trigger_conditions"
233+
serviceMetadata={serviceMetadata?.alert ?? undefined}
234+
serviceMetadataError={serviceMetadataError}
235+
serviceMetadataLoading={serviceMetadataLoading}
224236
/>
225237
<AddChannelListing name="channel_ids" />
226238
<ActionsPanel

0 commit comments

Comments
 (0)