Skip to content

Commit

Permalink
upcoming: [DI-23237] - Alerting bug fixes (#11610)
Browse files Browse the repository at this point in the history
* upcoming: [DI-23237] - Alerting UI bug fixes

* upcoming: [DI-23237] - Add changesets

* upcoming: [DI-23316] - Review changes

* upcoming: [DI-23316] - Avoiding nested await
  • Loading branch information
santoshp210-akamai authored Feb 6, 2025
1 parent 03462e7 commit bbf396d
Show file tree
Hide file tree
Showing 28 changed files with 143 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Upcoming Features
---

changed attribute names in NotificationChannel,MetricCriteria types to reflect the latest API specification ([#11610](https://github.com/linode/manager/pull/11610))
20 changes: 16 additions & 4 deletions packages/api-v4/src/cloudpulse/services.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import { BETA_API_ROOT as API_ROOT } from 'src/constants';
import Request, { setData, setMethod, setURL } from '../request';
import Request, {
setData,
setMethod,
setParams,
setURL,
setXFilter,
} from '../request';
import {
JWEToken,
JWETokenPayLoad,
MetricDefinition,
ServiceTypesList,
} from './types';
import { ResourcePage } from 'src/types';
import { Filter, Params, ResourcePage } from 'src/types';

export const getMetricDefinitionsByServiceType = (serviceType: string) => {
export const getMetricDefinitionsByServiceType = (
serviceType: string,
params?: Params,
filters?: Filter
) => {
return Request<ResourcePage<MetricDefinition>>(
setURL(
`${API_ROOT}/monitor/services/${encodeURIComponent(
serviceType
)}/metric-definitions`
),
setMethod('GET')
setMethod('GET'),
setParams(params),
setXFilter(filters)
);
};

Expand Down
9 changes: 5 additions & 4 deletions packages/api-v4/src/cloudpulse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface MetricDefinition {
scrape_interval: string;
available_aggregate_functions: string[];
dimensions: Dimension[];
is_alertable: boolean;
}

export interface Dimension {
Expand Down Expand Up @@ -180,7 +181,7 @@ export interface CreateAlertDefinitionPayload {
}
export interface MetricCriteria {
metric: string;
aggregation_type: MetricAggregationType;
aggregate_function: MetricAggregationType;
operator: MetricOperatorType;
threshold: number;
dimension_filters?: DimensionFilter[];
Expand Down Expand Up @@ -222,11 +223,11 @@ export interface Alert {
rules: AlertDefinitionMetricCriteria[];
};
trigger_conditions: TriggerCondition;
channels: {
id: string;
alert_channels: {
id: number;
label: string;
url: string;
type: 'channel';
type: 'alert-channel';
}[];
created_by: string;
updated_by: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Modified setValue method for the `DimensionFilterField`, `Metric` components. Capitalized the Dimension Filter values in ShowDetails and Create features ([#11610](https://github.com/linode/manager/pull/11610))
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ describe('Integration Tests for Alert Show Detail Page', () => {
.eq(index)
.within(() => {
cy.get(
`[data-qa-chip="${aggregationTypeMap[rule.aggregation_type]}"]`
`[data-qa-chip="${aggregationTypeMap[rule.aggregate_function]}"]`
)
.should('be.visible')
.should('have.text', aggregationTypeMap[rule.aggregation_type]);
.should('have.text', aggregationTypeMap[rule.aggregate_function]);

cy.get(`[data-qa-chip="${rule.label}"]`)
.should('be.visible')
Expand Down
12 changes: 6 additions & 6 deletions packages/manager/src/factories/cloudpulse/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const alertDimensionsFactory = Factory.Sync.makeFactory<AlertDefinitionDi

export const alertRulesFactory = Factory.Sync.makeFactory<AlertDefinitionMetricCriteria>(
{
aggregation_type: 'avg',
aggregate_function: 'avg',
dimension_filters: alertDimensionsFactory.buildList(1),
label: 'CPU Usage',
metric: 'cpu_usage',
Expand All @@ -28,17 +28,17 @@ export const alertRulesFactory = Factory.Sync.makeFactory<AlertDefinitionMetricC
);

export const alertFactory = Factory.Sync.makeFactory<Alert>({
channels: [
alert_channels: [
{
id: '1',
id: 1,
label: 'sample1',
type: 'channel',
type: 'alert-channel',
url: '',
},
{
id: '2',
id: 2,
label: 'sample2',
type: 'channel',
type: 'alert-channel',
url: '',
},
],
Expand Down
3 changes: 2 additions & 1 deletion packages/manager/src/factories/dashboards.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Factory from 'src/factories/factoryProxy';

import type {
MetricDefinition,
CloudPulseMetricsResponse,
CloudPulseMetricsResponseData,
Dashboard,
MetricDefinition,
Widgets,
} from '@linode/api-v4';
import type { ChartVariant } from 'src/components/AreaChart/AreaChart';
Expand Down Expand Up @@ -56,6 +56,7 @@ export const dashboardMetricFactory = Factory.Sync.makeFactory<MetricDefinition>
{
available_aggregate_functions: ['min', 'max', 'avg', 'sum'],
dimensions: [],
is_alertable: true,
label: Factory.each((i) => `widget_label_${i}`),
metric: Factory.each((i) => `widget_metric_${i}`),
metric_type: 'gauge',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const AlertDetail = () => {
data-qa-section="Notification Channels"
>
<AlertDetailNotification
channelIds={alertDetails.channels.map(({ id }) => id)}
channelIds={alertDetails.alert_channels.map(({ id }) => id)}
/>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('AlertDetailCriteria component tests', () => {
const alertDetails = alertFactory.build({
rule_criteria: {
rules: alertRulesFactory.buildList(2, {
aggregation_type: 'avg',
aggregate_function: 'avg',
dimension_filters: alertDimensionsFactory.buildList(2),
label: 'CPU Usage',
metric: 'cpu_usage',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ beforeEach(() => {
describe('AlertDetailNotification component tests', () => {
it('should render the alert detail notification channels successfully', () => {
const { getAllByText, getByText } = renderWithTheme(
<AlertDetailNotification channelIds={['1', '2', '3']} />
<AlertDetailNotification channelIds={[1, 2, 3]} />
);

expect(getByText(notificationChannel)).toBeInTheDocument();
Expand All @@ -59,7 +59,7 @@ describe('AlertDetailNotification component tests', () => {
isFetching: false,
});
const { getByText } = renderWithTheme(
<AlertDetailNotification channelIds={['1', '2', '3']} />
<AlertDetailNotification channelIds={[1, 2, 3]} />
);

expect(getByText(notificationChannel)).toBeInTheDocument();
Expand All @@ -73,7 +73,7 @@ describe('AlertDetailNotification component tests', () => {
isFetching: false,
});
const { getByText } = renderWithTheme(
<AlertDetailNotification channelIds={['1', '2', '3']} />
<AlertDetailNotification channelIds={[1, 2, 3]} />
);

expect(getByText(notificationChannel)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface NotificationChannelProps {
* List of channel IDs associated with the alert.
* These IDs are used to fetch and display notification channels.
*/
channelIds: string[];
channelIds: number[];
}
export const AlertDetailNotification = React.memo(
(props: NotificationChannelProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Grid } from '@mui/material';
import React from 'react';

import NullComponent from 'src/components/NullComponent';
import { capitalize } from 'src/utilities/capitalize';

import {
aggregationTypeMap,
Expand Down Expand Up @@ -33,7 +34,7 @@ export const RenderAlertMetricsAndDimensions = React.memo(
return ruleCriteria.rules.map(
(
{
aggregation_type: aggregationType,
aggregate_function: aggregationType,
dimension_filters: dimensionFilters,
label,
operator,
Expand Down Expand Up @@ -68,7 +69,7 @@ export const RenderAlertMetricsAndDimensions = React.memo(
}) => [
dimensionLabel,
dimensionOperatorTypeMap[dimensionOperator],
value,
capitalize(value),
]
)}
label="Dimension Filter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export const AlertsListTable = React.memo((props: AlertsListTableProps) => {
};

return (
<OrderBy data={alerts} order="asc" orderBy="service">
<OrderBy
data={alerts}
order="asc"
orderBy="service"
preferenceKey="alerts-landing"
>
{({ data: orderedData, handleOrderChange, order, orderBy }) => (
<Paginate data={orderedData}>
{({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const triggerConditionInitialValues: TriggerConditionForm = {
trigger_occurrences: 0,
};
const criteriaInitialValues: MetricCriteriaForm = {
aggregation_type: null,
aggregate_function: null,
dimension_filters: [],
metric: null,
operator: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const mockData: MetricDefinition[] = [
values: [],
},
],
is_alertable: true,
label: 'CPU utilization',
metric: 'system_cpu_utilization_percent',
metric_type: 'gauge',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';

import { capitalize } from 'src/utilities/capitalize';
import { renderWithThemeAndHookFormContext } from 'src/utilities/testHelpers';

import { dimensionOperatorOptions } from '../../constants';
Expand Down Expand Up @@ -39,6 +40,7 @@ const mockData: MetricDefinition[] = [
values: [],
},
],
is_alertable: true,
label: 'CPU utilization',
metric: 'system_cpu_utilization_percent',
metric_type: 'gauge',
Expand All @@ -47,6 +49,7 @@ const mockData: MetricDefinition[] = [
},
];

const dataFieldId = 'data-field';
const dimensionFieldMockData = mockData[0].dimensions;
describe('Dimension filter field component', () => {
const user = userEvent.setup();
Expand Down Expand Up @@ -95,7 +98,7 @@ describe('Dimension filter field component', () => {
},
}
);
const dataFieldContainer = container.getByTestId('data-field');
const dataFieldContainer = container.getByTestId(dataFieldId);
const dataFieldInput = within(dataFieldContainer).getByRole('button', {
name: 'Open',
});
Expand Down Expand Up @@ -140,6 +143,15 @@ describe('Dimension filter field component', () => {
},
}
);
const dataFieldContainer = container.getByTestId('data-field');
const dataFieldInput = within(dataFieldContainer).getByRole('button', {
name: 'Open',
});
await user.click(dataFieldInput);
const option = await container.findByRole('option', {
name: dimensionFieldMockData[1].label,
});
await user.click(option);
const operatorContainer = container.getByTestId('operator');
const operatorInput = within(operatorContainer).getByRole('button', {
name: 'Open',
Expand Down Expand Up @@ -186,10 +198,11 @@ describe('Dimension filter field component', () => {
},
}
);
const dataFieldContainer = container.getByTestId('data-field');
const dataFieldContainer = container.getByTestId(dataFieldId);
const dataFieldInput = within(dataFieldContainer).getByRole('button', {
name: 'Open',
});
const valueLabel = capitalize(dimensionFieldMockData[1].values[0]);
await user.click(dataFieldInput);
await user.click(
await container.findByRole('option', {
Expand All @@ -204,25 +217,25 @@ describe('Dimension filter field component', () => {
user.click(valueInput);
expect(
await container.findByRole('option', {
name: dimensionFieldMockData[1].values[0],
name: valueLabel,
})
);

expect(
await container.findByRole('option', {
name: dimensionFieldMockData[1].values[1],
name: valueLabel,
})
);

await user.click(
container.getByRole('option', {
name: dimensionFieldMockData[1].values[0],
name: valueLabel,
})
);

expect(within(valueContainer).getByRole('combobox')).toHaveAttribute(
'value',
dimensionFieldMockData[1].values[0]
valueLabel
);
});
});
Loading

0 comments on commit bbf396d

Please sign in to comment.