Skip to content

Commit

Permalink
upcoming: [DI-20595] - ACLP Supported regions per service type (#11382)
Browse files Browse the repository at this point in the history
* upcoming: [DI-20595] - ACLP Supported regions per service type

* upcoming: [DI-20595] - small fix

* upcoming: [DI-20595] - improved test quality

* upcoming: [DI-20595] - PR Comments

* upcoming: [DI-20595] - small fix

* upcoming: [DI-20595] - updated UT

* upcoming: [DI-20595] - updated UT

* upcoming: [DI-20595] - updated types

* upcoming: [DI-20595] - small linting fix

* upcoming: [DI-20595] - handle empty regions

* upcoming: [DI-20595] - Added changeset

* upcoming: [DI-20595] - Added changeset

* upcoming: [DI-20595] - edge case fix

* upcoming: [DI-20595] - linting fix

* Test[DI-20595] -add region select testcases

* upcoming: [DI-20595] - PR Comments

* upcoming: [DI-20595] - PR Comments

* upcoming: [DI-20595] - linting fix

Co-authored-by: Purvesh Makode <[email protected]>

* upcoming: [DI-20595] - linting fix

Co-authored-by: Purvesh Makode <[email protected]>

* upcoming: [DI-20595] - linting fix

Co-authored-by: Mariah Jacobs <[email protected]>

---------

Co-authored-by: agorthi <[email protected]>
Co-authored-by: Purvesh Makode <[email protected]>
Co-authored-by: Mariah Jacobs <[email protected]>
  • Loading branch information
4 people authored Dec 11, 2024
1 parent 681acc6 commit 0bd360b
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Show ACLP supported regions per service type in region select ([#11382](https://github.com/linode/manager/pull/11382))
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from 'support/intercepts/databases';
import { Database } from '@linode/api-v4';
import { mockGetAccount } from 'support/intercepts/account';
import { Flags } from 'src/featureFlags';

/**
* Verifies the presence and values of specific properties within the aclpPreference object
Expand All @@ -44,6 +45,24 @@ import { mockGetAccount } from 'support/intercepts/account';
* @param requestPayload - The payload received from the request, containing the aclpPreference object.
* @param expectedValues - An object containing the expected values for properties to validate against the requestPayload.
*/

const flags: Partial<Flags> = {
aclp: { enabled: true, beta: true },
aclpResourceTypeMap: [
{
dimensionKey: 'LINODE_ID',
maxResourceSelections: 10,
serviceType: 'linode',
supportedRegionIds: 'us-ord',
},
{
dimensionKey: 'cluster_id',
maxResourceSelections: 10,
serviceType: 'dbaas',
supportedRegionIds: 'us-ord',
},
],
};
const {
metrics,
id,
Expand Down Expand Up @@ -78,10 +97,9 @@ const metricDefinitions = {
};

const mockRegion = regionFactory.build({
capabilities: ['Linodes'],
capabilities: ['Managed Databases'],
id: 'us-ord',
label: 'Chicago, IL',
country: 'us',
});

const databaseMock: Database = databaseFactory.build({
Expand All @@ -97,9 +115,7 @@ const mockAccount = accountFactory.build();

describe('Tests for API error handling', () => {
beforeEach(() => {
mockAppendFeatureFlags({
aclp: { beta: true, enabled: true },
});
mockAppendFeatureFlags(flags);
mockGetAccount(mockAccount);
mockGetCloudPulseMetricDefinitions(serviceType, metricDefinitions);
mockGetCloudPulseDashboards(serviceType, [dashboard]).as('fetchDashboard');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { mockGetAccount } from 'support/intercepts/account';
import { mockGetLinodes } from 'support/intercepts/linodes';
import { mockGetUserPreferences } from 'support/intercepts/profile';
import { mockGetRegions } from 'support/intercepts/regions';
import { extendRegion } from 'support/util/regions';
import { CloudPulseMetricsResponse, Database } from '@linode/api-v4';
import { Interception } from 'cypress/types/net-stubbing';
import { generateRandomMetricsData } from 'support/util/cloudpulse';
Expand All @@ -49,14 +48,29 @@ import { formatToolTip } from 'src/features/CloudPulse/Utils/unitConversion';
const expectedGranularityArray = ['Auto', '1 day', '1 hr', '5 min'];
const timeDurationToSelect = 'Last 24 Hours';

const flags: Partial<Flags> = { aclp: { enabled: true, beta: true } };
const flags: Partial<Flags> = {
aclp: { enabled: true, beta: true },
aclpResourceTypeMap: [
{
dimensionKey: 'LINODE_ID',
maxResourceSelections: 10,
serviceType: 'linode',
supportedRegionIds: '',
},
{
dimensionKey: 'cluster_id',
maxResourceSelections: 10,
serviceType: 'dbaas',
supportedRegionIds: 'us-ord',
},
],
};

const {
metrics,
id,
serviceType,
dashboardName,
region,
engine,
clusterName,
nodeType,
Expand Down Expand Up @@ -91,14 +105,18 @@ const mockLinode = linodeFactory.build({
});

const mockAccount = accountFactory.build();
const mockRegion = extendRegion(
regionFactory.build({
capabilities: ['Linodes'],
id: 'us-ord',
label: 'Chicago, IL',
country: 'us',
})
);

const mockRegion = regionFactory.build({
capabilities: ['Managed Databases'],
id: 'us-ord',
label: 'Chicago, IL',
});

const extendedMockRegion = regionFactory.build({
capabilities: ['Managed Databases'],
id: 'us-east',
label: 'Newark,NL',
});
const metricsAPIResponsePayload = cloudPulseMetricsResponseFactory.build({
data: generateRandomMetricsData(timeDurationToSelect, '5 min'),
});
Expand Down Expand Up @@ -151,9 +169,9 @@ const getWidgetLegendRowValuesFromResponse = (
};

const databaseMock: Database = databaseFactory.build({
label: widgetDetails.dbaas.clusterName,
type: widgetDetails.dbaas.engine,
region: widgetDetails.dbaas.region,
label: clusterName,
type: engine,
region: mockRegion.label,
version: '1',
status: 'provisioning',
cluster_size: 1,
Expand All @@ -177,7 +195,7 @@ describe('Integration Tests for DBaaS Dashboard ', () => {
mockCreateCloudPulseMetrics(serviceType, metricsAPIResponsePayload).as(
'getMetrics'
);
mockGetRegions([mockRegion]);
mockGetRegions([mockRegion, extendedMockRegion]);
mockGetUserPreferences({});
mockGetDatabases([databaseMock]).as('getDatabases');

Expand All @@ -191,35 +209,60 @@ describe('Integration Tests for DBaaS Dashboard ', () => {
ui.autocomplete
.findByLabel('Dashboard')
.should('be.visible')
.type(`${dashboardName}{enter}`)
.should('be.visible');
.type(dashboardName);

ui.autocompletePopper
.findByTitle(dashboardName)
.should('be.visible')
.click();

// Select a time duration from the autocomplete input.
ui.autocomplete
.findByLabel('Time Range')
.should('be.visible')
.type(`${timeDurationToSelect}{enter}`)
.should('be.visible');
.type(timeDurationToSelect);

ui.autocompletePopper
.findByTitle(timeDurationToSelect)
.should('be.visible')
.click();

//Select a Engine from the autocomplete input.
//Select a Database Engine from the autocomplete input.
ui.autocomplete
.findByLabel('Database Engine')
.should('be.visible')
.type(`${engine}{enter}`)
.should('be.visible');
.type(engine);

ui.autocompletePopper.findByTitle(engine).should('be.visible').click();

// Select a region from the dropdown.
ui.regionSelect.find().click();

// Select a region from the dropdown.
ui.regionSelect.find().click().type(`${region}{enter}`);
ui.regionSelect.find().type(extendedMockRegion.label);

// Since DBaaS does not support this region, we expect it to not be in the dropdown.

ui.autocompletePopper.find().within(() => {
cy.findByText(
`${extendedMockRegion.label} (${extendedMockRegion.id})`
).should('not.exist');
});

// Select a resource from the autocomplete input.
ui.regionSelect.find().click().clear();
ui.regionSelect
.findItemByRegionId(mockRegion.id, [mockRegion])
.should('be.visible')
.click();

// Select a resource (Database Clusters) from the autocomplete input.
ui.autocomplete
.findByLabel('Database Clusters')
.should('be.visible')
.type(`${clusterName}{enter}`)
.click();
cy.findByText(clusterName).should('be.visible');
.type(clusterName);

ui.autocompletePopper.findByTitle(clusterName).should('be.visible').click();

//Select a Node from the autocomplete input.
// Select a Node from the autocomplete input.
ui.autocomplete
.findByLabel('Node Type')
.should('be.visible')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { mockGetAccount } from 'support/intercepts/account';
import { mockGetLinodes } from 'support/intercepts/linodes';
import { mockGetUserPreferences } from 'support/intercepts/profile';
import { mockGetRegions } from 'support/intercepts/regions';
import { extendRegion } from 'support/util/regions';
import { CloudPulseMetricsResponse } from '@linode/api-v4';
import { generateRandomMetricsData } from 'support/util/cloudpulse';
import { Interception } from 'cypress/types/net-stubbing';
Expand All @@ -46,15 +45,25 @@ import { formatToolTip } from 'src/features/CloudPulse/Utils/unitConversion';
*/
const expectedGranularityArray = ['Auto', '1 day', '1 hr', '5 min'];
const timeDurationToSelect = 'Last 24 Hours';
const flags: Partial<Flags> = { aclp: { enabled: true, beta: true } };
const {
metrics,
id,
serviceType,
dashboardName,
region,
resource,
} = widgetDetails.linode;
const flags: Partial<Flags> = {
aclp: { enabled: true, beta: true },
aclpResourceTypeMap: [
{
dimensionKey: 'LINODE_ID',
maxResourceSelections: 10,
serviceType: 'linode',
supportedRegionIds: 'us-ord',
},
{
dimensionKey: 'cluster_id',
maxResourceSelections: 10,
serviceType: 'dbaas',
supportedRegionIds: '',
},
],
};
const { metrics, id, serviceType, dashboardName, region, resource } =
widgetDetails.linode;

const dashboard = dashboardFactory.build({
label: dashboardName,
Expand Down Expand Up @@ -85,14 +94,18 @@ const mockLinode = linodeFactory.build({
});

const mockAccount = accountFactory.build();
const mockRegion = extendRegion(
regionFactory.build({
capabilities: ['Linodes'],
id: 'us-ord',
label: 'Chicago, IL',
country: 'us',
})
);

const mockRegion = regionFactory.build({
capabilities: ['Linodes'],
id: 'us-ord',
label: 'Chicago, IL',
});

const extendedMockRegion = regionFactory.build({
capabilities: ['Managed Databases'],
id: 'us-east',
label: 'Newark,NL',
});
const metricsAPIResponsePayload = cloudPulseMetricsResponseFactory.build({
data: generateRandomMetricsData(timeDurationToSelect, '5 min'),
});
Expand Down Expand Up @@ -170,18 +183,41 @@ describe('Integration Tests for Linode Dashboard ', () => {
ui.autocomplete
.findByLabel('Dashboard')
.should('be.visible')
.type(`${dashboardName}{enter}`)
.should('be.visible');
.type(dashboardName);

ui.autocompletePopper
.findByTitle(dashboardName)
.should('be.visible')
.click();

// Select a time duration from the autocomplete input.
ui.autocomplete
.findByLabel('Time Range')
.should('be.visible')
.type(`${timeDurationToSelect}{enter}`)
.should('be.visible');
.type(timeDurationToSelect);

ui.autocompletePopper
.findByTitle(timeDurationToSelect)
.should('be.visible')
.click();

ui.regionSelect.find().click();

// Select a region from the dropdown.
ui.regionSelect.find().click();

ui.regionSelect.find().type(extendedMockRegion.label);

// Since Linode does not support this region, we expect it to not be in the dropdown.

ui.autocompletePopper.find().within(() => {
cy.findByText(
`${extendedMockRegion.label} (${extendedMockRegion.id})`
).should('not.exist');
});

// Select a region from the dropdown.
ui.regionSelect.find().click().type(`${region}{enter}`);
ui.regionSelect.find().click().clear().type(`${region}{enter}`);

// Select a resource from the autocomplete input.
ui.autocomplete
Expand All @@ -191,6 +227,7 @@ describe('Integration Tests for Linode Dashboard ', () => {
.click();

cy.findByText(resource).should('be.visible');

// Wait for all metrics query requests to resolve.
cy.wait(['@getMetrics', '@getMetrics', '@getMetrics', '@getMetrics']);
});
Expand Down
1 change: 1 addition & 0 deletions packages/manager/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface CloudPulseResourceTypeMapFlag {
dimensionKey: string;
maxResourceSelections?: number;
serviceType: string;
supportedRegionIds?: string;
}

interface gpuV2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { CloudPulseSelectTypes } from './models';
import type { CloudPulseServiceTypeFilterMap } from './models';

const TIME_DURATION = 'Time Range';
export const DBAAS_CAPABILITY = 'Managed Databases';
export const LINODE_CAPABILITY = 'Linodes';

export const LINODE_CONFIG: Readonly<CloudPulseServiceTypeFilterMap> = {
capability: LINODE_CAPABILITY,
filters: [
{
configuration: {
Expand Down Expand Up @@ -52,6 +55,7 @@ export const LINODE_CONFIG: Readonly<CloudPulseServiceTypeFilterMap> = {
};

export const DBAAS_CONFIG: Readonly<CloudPulseServiceTypeFilterMap> = {
capability: DBAAS_CAPABILITY,
filters: [
{
configuration: {
Expand Down
10 changes: 9 additions & 1 deletion packages/manager/src/features/CloudPulse/Utils/models.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import type { DatabaseEngine, DatabaseType } from '@linode/api-v4';
import type {
Capabilities,
DatabaseEngine,
DatabaseType,
} from '@linode/api-v4';
import type { QueryFunction, QueryKey } from '@tanstack/react-query';

/**
* The CloudPulseServiceTypeMap has list of filters to be built for different service types like dbaas, linode etc.,The properties here are readonly as it is only for reading and can't be modified in code
*/
export interface CloudPulseServiceTypeFilterMap {
/**
* Current capability corresponding to a service type
*/
readonly capability: Capabilities;
/**
* The list of filters for a service type
*/
Expand Down
Loading

0 comments on commit 0bd360b

Please sign in to comment.