Skip to content

Commit

Permalink
Merge branch 'v3' into PMM-12910-popup-new-version-available
Browse files Browse the repository at this point in the history
  • Loading branch information
doracretu3pillar authored Sep 30, 2024
2 parents 185b4be + 89a0db3 commit 9f92a49
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ export interface TemplatesList extends Omit<TemplatesListAPI, 'templates'> {
}

export enum SourceDescription {
BUILT_IN = 'BUILT_IN',
SAAS = 'SAAS',
USER_FILE = 'USER_FILE',
USER_API = 'USER_API',
BUILT_IN = 'TEMPLATE_SOURCE_BUILT_IN',
SAAS = 'TEMPLATE_SOURCE_SAAS',
USER_FILE = 'TEMPLATE_SOURCE_USER_FILE',
USER_API = 'TEMPLATE_SOURCE_USER_API',
}

// https://github.com/percona-platform/saas/blob/main/pkg/alert/type.go
// https://github.com/percona/saas/blob/main/pkg/alert/type.go
export enum TemplateParamType {
FLOAT = 'FLOAT',
BOOL = 'BOOL',
STRING = 'STRING',
FLOAT = 'PARAM_TYPE_FLOAT',
BOOL = 'PARAM_TYPE_BOOL',
STRING = 'PARAM_TYPE_STRING',
}

// https://github.com/percona-platform/saas/blob/main/pkg/alert/unit.go
// https://github.com/percona/saas/blob/main/pkg/alert/unit.go
export enum TemplateParamUnit {
PERCENTAGE = 'PERCENTAGE',
SECONDS = 'SECONDS',
PERCENTAGE = 'PARAM_UNIT_PERCENTAGE',
SECONDS = 'PARAM_UNIT_SECONDS',
}

export interface TemplateFloatParamAPI {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('AlertRuleTemplatesTable utils', () => {
});

test('formatSource', () => {
expect(formatSource(SourceDescription.BUILT_IN)).toBe(SOURCE_MAP.BUILT_IN);
expect(formatSource(SourceDescription.SAAS)).toBe(SOURCE_MAP.SAAS);
expect(formatSource(SourceDescription.BUILT_IN)).toBe(SOURCE_MAP.TEMPLATE_SOURCE_BUILT_IN);
expect(formatSource(SourceDescription.SAAS)).toBe(SOURCE_MAP.TEMPLATE_SOURCE_SAAS);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { SelectableValue } from '@grafana/data';
import { Severity } from 'app/percona/shared/core';

import { TemplateParamType } from '../AlertRuleTemplate/AlertRuleTemplate.types';

// TODO: generate SEVERITY_OPTIONS from its type definitions
export const SEVERITY_OPTIONS: Array<SelectableValue<keyof typeof Severity>> = [
{
Expand Down Expand Up @@ -40,3 +42,9 @@ export const SEVERITY_OPTIONS: Array<SelectableValue<keyof typeof Severity>> = [
// We define our default evaluation interval as 60s
// 'for' can't be less than that, hence this minimum
export const MINIMUM_DURATION_VALUE = 60;

export const TYPE_TO_KEY_MAP: Record<TemplateParamType, 'bool' | 'float' | 'string'> = {
PARAM_TYPE_BOOL: 'bool',
PARAM_TYPE_FLOAT: 'float',
PARAM_TYPE_STRING: 'string',
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { AlertRuleCreatePayload, AlertRulesListResponseChannel, Severity } from

import { TemplatedAlertFormValues } from '../../types';

import { TYPE_TO_KEY_MAP } from './TemplateForm.constants';

export const formatChannelsOptions = (channels: string[]): Array<SelectableValue<string>> =>
channels
? channels.map((channel) => ({
Expand Down Expand Up @@ -48,7 +50,7 @@ export const formatCreateAPIPayload = (data: TemplatedAlertFormValues): AlertRul
payload.params?.push({
name,
type,
[type.toLowerCase()]: value,
[TYPE_TO_KEY_MAP[type]]: value,
});
}
});
Expand Down
3 changes: 2 additions & 1 deletion public/app/percona/shared/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export enum Severity {
import {
TemplateAnnotation,
TemplateParam,
TemplateParamType,
} from 'app/percona/integrated-alerting/components/AlertRuleTemplate/AlertRuleTemplate.types';

export enum AlertRuleParamType {
Expand Down Expand Up @@ -159,7 +160,7 @@ export interface AlertRulesListPayloadFilter {

export interface AlertRulesListResponseParam {
name: string;
type: keyof typeof AlertRuleParamType;
type: TemplateParamType;
[AlertRuleParamType.BOOL]?: boolean;
[AlertRuleParamType.FLOAT]?: number;
[AlertRuleParamType.STRING]?: string;
Expand Down

0 comments on commit 9f92a49

Please sign in to comment.