Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Upcoming Features
---

Add logs to `CloudPulseServiceType` and `capabilityServiceTypeMapping` ([#13445](https://github.com/linode/manager/pull/13445))
2 changes: 2 additions & 0 deletions packages/api-v4/src/cloudpulse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type CloudPulseServiceType =
| 'firewall'
| 'linode'
| 'lke'
| 'logs'
| 'netloadbalancer'
| 'nodebalancer'
| 'objectstorage';
Expand Down Expand Up @@ -429,6 +430,7 @@ export const capabilityServiceTypeMapping: Record<
blockstorage: 'Block Storage',
lke: 'Kubernetes',
netloadbalancer: 'Network LoadBalancer',
logs: 'Akamai Cloud Pulse Logs',
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Integrate aclp-logs service to alerts with custom validation schemas, error texts ([#13445](https://github.com/linode/manager/pull/13445))
65 changes: 65 additions & 0 deletions packages/manager/src/factories/cloudpulse/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,68 @@
],
},
];

const logsDimensions: Dimension[] = [
{
label: 'Status Code',

Check warning on line 737 in packages/manager/src/factories/cloudpulse/alerts.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Define a constant instead of duplicating this literal 3 times. Raw Output: {"ruleId":"sonarjs/no-duplicate-string","severity":1,"message":"Define a constant instead of duplicating this literal 3 times.","line":737,"column":12,"nodeType":"Literal","endLine":737,"endColumn":25}
dimension_label: 'status_code',
values: [],
},
];

export const logsMetricCriteria: MetricDefinition[] = [
{
label: 'Successful Upload Count',
metric: 'success_upload_count',
unit: 'Count',
scrape_interval: '300s',
metric_type: 'gauge',
is_alertable: true,
available_aggregate_functions: ['sum'],
dimensions: logsDimensions,
},
{
label: 'Error Upload Count',
metric: 'error_upload_count',
unit: 'Count',
scrape_interval: '300s',
metric_type: 'gauge',
is_alertable: true,
available_aggregate_functions: ['sum'],
dimensions: logsDimensions,
},
{
label: 'Error Upload Rate',
metric: 'error_upload_rate',
unit: 'Percent',
scrape_interval: '300s',
metric_type: 'gauge',
is_alertable: true,
available_aggregate_functions: ['avg'],
dimensions: logsDimensions,
},
];

export const logsAlertMetricCriteria =
Factory.Sync.makeFactory<AlertDefinitionMetricCriteria>({
label: 'Successful Upload Count',
metric: 'success_upload_count',
unit: 'Count',
aggregate_function: 'sum',
operator: 'eq',
threshold: 1500,
dimension_filters: [
{
label: 'Status Code',
dimension_label: 'status_code',
operator: 'in',
value: '203,402',
},
{
label: 'Status Code',
dimension_label: 'status_code',
operator: 'eq',
value: '503',
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@
isLoading: isResourcesLoading,
} = useResourcesQuery(
Boolean(
serviceType && (serviceType === 'firewall' || supportedRegionIds?.length)
serviceType &&
(serviceType === 'firewall' ||

Check warning on line 209 in packages/manager/src/features/CloudPulse/Alerts/AlertsResources/AlertsResources.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Insert `··` Raw Output: {"ruleId":"prettier/prettier","severity":1,"message":"Insert `··`","line":209,"column":7,"nodeType":null,"messageId":"insert","endLine":209,"endColumn":7,"fix":{"range":[6020,6020],"text":" "}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@santoshp210-akamai . some linting issue that may be fixed??

serviceType === 'logs' ||

Check warning on line 210 in packages/manager/src/features/CloudPulse/Alerts/AlertsResources/AlertsResources.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Insert `··` Raw Output: {"ruleId":"prettier/prettier","severity":1,"message":"Insert `··`","line":210,"column":9,"nodeType":null,"messageId":"insert","endLine":210,"endColumn":9,"fix":{"range":[6059,6059],"text":" "}}
supportedRegionIds?.length)

Check warning on line 211 in packages/manager/src/features/CloudPulse/Alerts/AlertsResources/AlertsResources.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐢 Insert `··` Raw Output: {"ruleId":"prettier/prettier","severity":1,"message":"Insert `··`","line":211,"column":1,"nodeType":null,"messageId":"insert","endLine":211,"endColumn":1,"fix":{"range":[6085,6085],"text":" "}}
), // Enable query only if serviceType and supportedRegionIds are available, in case of firewall only serviceType is needed
serviceType,
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export const serviceTypeBasedColumns: ServiceColumns<AlertInstance> = {
sortingKey: 'region',
},
],
logs: [
{
accessor: ({ label }) => label,
label: 'Entity',
sortingKey: 'label',
},
],
};

export const serviceToFiltersMap: Partial<
Expand All @@ -138,6 +145,7 @@ export const serviceToFiltersMap: Partial<
{ component: AlertsEndpointFilter, filterKey: 'endpoint' },
],
blockstorage: [{ component: AlertsRegionFilter, filterKey: 'region' }],
logs: [],
};
export const applicableAdditionalFilterKeys: AlertAdditionalFilterKey[] = [
'engineType', // Extendable in future for filter keys like 'tags', 'plan', etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
INTERFACE_ID_ERROR_MESSAGE,
PORT_HELPER_TEXT,
PORTS_TRAILING_COMMA_ERROR_MESSAGE,
STATUS_CODE_ERROR_MESSAGE,
STATUS_CODES_ERROR_MESSAGE,
STATUS_CODES_HELPER_TEXT,
} from '../../../constants';

const LENGTH_ERROR_MESSAGE = 'Value must be 100 characters or less.';
Expand Down Expand Up @@ -240,6 +243,73 @@ const multipleInterfacesSchema = string()
}
);

const singleStatusCodeSchema = string()
.max(100, LENGTH_ERROR_MESSAGE)
.test(
'validate-single-status-code-schema',
STATUS_CODE_ERROR_MESSAGE,
function (value) {
if (!value || typeof value !== 'string') {
return this.createError({ message: fieldErrorMessage });
}

if (!CONFIG_NUMBER_REGEX.test(value)) {
return this.createError({ message: STATUS_CODE_ERROR_MESSAGE });
}

return true;
}
);

const multipleStatusCodeSchema = string()
.max(100, LENGTH_ERROR_MESSAGE)
.test(
'validate-multi-status-code-schema',
STATUS_CODES_ERROR_MESSAGE,
function (value) {
if (!value || typeof value !== 'string') {
return this.createError({ message: fieldErrorMessage });
}
if (value.includes(' ')) {
return this.createError({ message: STATUS_CODES_ERROR_MESSAGE });
}

if (value.trim().endsWith(',')) {
return this.createError({
message: PORTS_TRAILING_COMMA_ERROR_MESSAGE,
});
}

if (value.trim().startsWith(',')) {
return this.createError({ message: PORTS_LEADING_COMMA_ERROR_MESSAGE });
}

if (value.trim().includes(',,')) {
return this.createError({
message: CONFIG_IDS_CONSECUTIVE_COMMAS_ERROR_MESSAGE,
});
}
if (value.includes('.')) {
return this.createError({ message: STATUS_CODES_HELPER_TEXT });
}

const rawSegments = value.split(',');
// Check for empty segments
if (rawSegments.some((segment) => segment.trim() === '')) {
return this.createError({
message: CONFIG_IDS_CONSECUTIVE_COMMAS_ERROR_MESSAGE,
});
}
for (const configId of rawSegments) {
const trimmedConfigId = configId.trim();

if (!CONFIG_NUMBER_REGEX.test(trimmedConfigId)) {
return this.createError({ message: STATUS_CODE_ERROR_MESSAGE });
}
}
return true;
}
);
const baseValueSchema = string()
.nullable()
.required(fieldErrorMessage)
Expand Down Expand Up @@ -269,6 +339,11 @@ export const getDimensionFilterValueSchema = ({
operator === 'in' ? multipleInterfacesSchema : singleInterfaceSchema;
return interfaceSchema.concat(baseValueSchema);
}
if (dimensionLabel === 'status_code') {
const statusCodeSchema =
operator === 'in' ? multipleStatusCodeSchema : singleStatusCodeSchema;
return statusCodeSchema.concat(baseValueSchema);
}
if (['endswith', 'startswith'].includes(operator)) {
return string().max(100, LENGTH_ERROR_MESSAGE).concat(baseValueSchema);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import {
PORT_HELPER_TEXT,
PORT_PLACEHOLDER_TEXT,
PORTS_PLACEHOLDER_TEXT,
STATUS_CODE_HELPER_TEXT,
STATUS_CODE_PLACEHOLDER_TEXT,
STATUS_CODES_HELPER_TEXT,
STATUS_CODES_PLACEHOLDER_TEXT,
VIP_HELPER_TEXT,
VIP_PLACEHOLDER_TEXT,
} from '../../../constants';
Expand Down Expand Up @@ -366,6 +370,34 @@ export const valueFieldConfig: ValueFieldConfigMap = {
inputType: 'text',
},
},
status_code: {
eq_neq: {
type: 'textfield',
inputType: 'number',
min: 0,
max: Number.MAX_SAFE_INTEGER,
placeholder: STATUS_CODE_PLACEHOLDER_TEXT,
helperText: STATUS_CODE_HELPER_TEXT,
},
startswith_endswith: {
type: 'textfield',
inputType: 'number',
min: 0,
max: Number.MAX_SAFE_INTEGER,
placeholder: STATUS_CODE_PLACEHOLDER_TEXT,
helperText: STATUS_CODE_HELPER_TEXT,
},
in: {
type: 'textfield',
inputType: 'text',
placeholder: STATUS_CODES_PLACEHOLDER_TEXT,
helperText: STATUS_CODES_HELPER_TEXT,
},
'*': {
type: 'textfield',
inputType: 'number',
},
},
emptyValue: {
eq_neq: {
type: 'textfield',
Expand Down
32 changes: 10 additions & 22 deletions packages/manager/src/features/CloudPulse/Alerts/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { FieldPath } from 'react-hook-form';

import { PORTS_HELPER_TEXT } from '../Utils/constants';

import type { CreateAlertDefinitionForm } from './CreateAlert/types';
import type {
AlertDefinitionScope,
Expand Down Expand Up @@ -277,27 +275,17 @@ export const CONFIGS_ID_PLACEHOLDER_TEXT = 'e.g., 1234,5678';

export const INTERFACE_ID_ERROR_MESSAGE = 'Enter a valid interface ID number.';
export const INTERFACE_ID_HELPER_TEXT = 'Enter an interface ID number.';
export const PLACEHOLDER_TEXT_MAP: Record<string, Record<string, string>> = {
port: {
in: PORTS_PLACEHOLDER_TEXT,
default: PORT_PLACEHOLDER_TEXT,
},
config_id: {
in: CONFIGS_ID_PLACEHOLDER_TEXT,
default: CONFIG_ID_PLACEHOLDER_TEXT,
},
};

export const HELPER_TEXT_MAP: Record<string, Record<string, string>> = {
port: {
in: PORTS_HELPER_TEXT,
default: PORT_HELPER_TEXT,
},
config_id: {
in: CONFIGS_HELPER_TEXT,
default: CONFIG_ERROR_MESSAGE,
},
};
export const STATUS_CODE_PLACEHOLDER_TEXT = 'e.g., 200';
export const STATUS_CODES_PLACEHOLDER_TEXT = 'e.g., 200,403,500';

export const STATUS_CODE_HELPER_TEXT = 'Enter a status code number.';
export const STATUS_CODES_HELPER_TEXT =
'Enter one or more status codes separated by commas.';

export const STATUS_CODE_ERROR_MESSAGE = 'Enter a valid status code number.';
export const STATUS_CODES_ERROR_MESSAGE =
'Enter valid status codes as integers separated by commas.';

export const entityLabelMap = {
linode: 'Linode',
Expand Down
2 changes: 2 additions & 0 deletions packages/manager/src/features/CloudPulse/Utils/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
NetworkLoadBalancer,
NodeBalancer,
ObjectStorageBucket,
Stream,
Volume,
} from '@linode/api-v4';
import type { QueryFunction, QueryKey } from '@tanstack/react-query';
Expand Down Expand Up @@ -68,6 +69,7 @@ export type QueryFunctionType =
| NetworkLoadBalancer[]
| NodeBalancer[]
| ObjectStorageBucket[]
| Stream[]
| Volume[];
/**
* The non array types of QueryFunctionType like DatabaseEngine|DatabaseType
Expand Down
Loading