Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

refactor(ruler): tighten rule and downtime OpenAPI schema (#10995)

Pandeya5e1f71cf669
diff --git a/docs/api/openapi.yml b/docs/api/openapi.yml
index a1d09a4b77..b0f5fa8a78 100644
--- a/docs/api/openapi.yml
+++ b/docs/api/openapi.yml
@@ -3645,6 +3645,13 @@ components:
- nodata
- disabled
type: string
+ RuletypesAlertType:
+ enum:
+ - METRIC_BASED_ALERT
+ - TRACES_BASED_ALERT
+ - LOGS_BASED_ALERT
+ - EXCEPTIONS_BASED_ALERT
+ type: string
RuletypesBasicRuleThreshold:
properties:
channels:
@@ -3701,6 +3708,8 @@ components:
weekday:
nullable: true
type: integer
+ required:
+ - type
type: object
RuletypesCumulativeWindow:
properties:
@@ -3746,45 +3755,12 @@ components:
spec:
$ref: '#/components/schemas/RuletypesRollingWindow'
type: object
- RuletypesGettablePlannedMaintenance:
- properties:
- alertIds:
- items:
- type: string
- nullable: true
- type: array
- createdAt:
- format: date-time
- type: string
- createdBy:
- type: string
- description:
- type: string
- id:
- type: string
- kind:
- type: string
- name:
- type: string
- schedule:
- $ref: '#/components/schemas/RuletypesSchedule'
- status:
- type: string
- updatedAt:
- format: date-time
- type: string
- updatedBy:
- type: string
- required:
- - name
- - schedule
- type: object
RuletypesGettableRule:
properties:
alert:
type: string
alertType:
- type: string
+ $ref: '#/components/schemas/RuletypesAlertType'
annotations:
additionalProperties:
type: string
@@ -3793,7 +3769,6 @@ components:
$ref: '#/components/schemas/RuletypesRuleCondition'
createAt:
format: date-time
- nullable: true
type: string
createBy:
nullable: true
@@ -3830,7 +3805,6 @@ components:
$ref: '#/components/schemas/RuletypesAlertState'
updateAt:
format: date-time
- nullable: true
type: string
updateBy:
nullable: true
@@ -3838,17 +3812,13 @@ components:
version:
type: string
required:
+ - id
+ - state
- alert
- ruleType
- condition
- type: object
- RuletypesGettableRules:
- properties:
- rules:
- items:
- $ref: '#/components/schemas/RuletypesGettableRule'
- nullable: true
- type: array
+ - createAt
+ - updateAt
type: object
RuletypesGettableTestRule:
properties:
@@ -3857,6 +3827,17 @@ components:
message:
type: string
type: object
+ RuletypesMaintenanceKind:
+ enum:
+ - fixed
+ - recurring
+ type: string
+ RuletypesMaintenanceStatus:
+ enum:
+ - active
+ - upcoming
+ - expired
+ type: string
RuletypesMatchType:
enum:
- at_least_once
@@ -3884,12 +3865,65 @@ components:
- table
- graph
type: string
+ RuletypesPlannedMaintenance:
+ properties:
+ alertIds:
+ items:
+ type: string
+ nullable: true
+ type: array
+ createdAt:
+ format: date-time
+ type: string
+ createdBy:
+ type: string
+ description:
+ type: string
+ id:
+ type: string
+ kind:
+ $ref: '#/components/schemas/RuletypesMaintenanceKind'
+ name:
+ type: string
+ schedule:
+ $ref: '#/components/schemas/RuletypesSchedule'
+ status:
+ $ref: '#/components/schemas/RuletypesMaintenanceStatus'
+ updatedAt:
+ format: date-time
+ type: string
+ updatedBy:
+ type: string
+ required:
+ - id
+ - name
+ - schedule
+ - status
+ - kind
+ type: object
+ RuletypesPostablePlannedMaintenance:
+ properties:
+ alertIds:
+ items:
+ type: string
+ nullable: true
+ type: array
+ description:
+ type: string
+ name:
+ type: string
+ schedule:
+ $ref: '#/components/schemas/RuletypesSchedule'
+ required:
+ - name
+ - schedule
+ type: object
RuletypesPostableRule:
properties:
alert:
type: string
alertType:
- type: string
+ $ref: '#/components/schemas/RuletypesAlertType'
annotations:
additionalProperties:
type: string
@@ -3945,14 +3979,18 @@ components:
type: string
repeatOn:
items:
- type: string
+ $ref: '#/components/schemas/RuletypesRepeatOn'
nullable: true
type: array
repeatType:
- type: string
+ $ref: '#/components/schemas/RuletypesRepeatType'
startTime:
format: date-time
type: string
+ required:
+ - startTime
+ - duration
+ - repeatType
type: object
RuletypesRenotify:
properties:
@@ -3965,6 +4003,22 @@ components:
interval:
type: string
type: object
+ RuletypesRepeatOn:
+ enum:
+ - sunday
+ - monday
+ - tuesday
+ - wednesday
+ - thursday
+ - friday
+ - saturday
+ type: string
+ RuletypesRepeatType:
+ enum:
+ - daily
+ - weekly
+ - monthly
+ type: string
RuletypesRollingWindow:
properties:
evalWindow:
@@ -6222,7 +6276,7 @@ paths:
properties:
data:
items:
- $ref: '#/components/schemas/RuletypesGettablePlannedMaintenance'
+ $ref: '#/components/schemas/RuletypesPlannedMaintenance'
type: array
status:
type: string
@@ -6265,9 +6319,21 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/RuletypesGettablePlannedMaintenance'
+ $ref: '#/components/schemas/RuletypesPostablePlannedMaintenance'
responses:
"201":
+ content:
+ application/json:
+ schema:
+ properties:
+ data:
+ $ref: '#/components/schemas/RuletypesPlannedMaintenance'
+ status:
+ type: string
+ required:
+ - status
+ - data
+ type: object
description: Created
"400":
content:
@@ -6364,7 +6430,7 @@ paths:
schema:
properties:
data:
- $ref: '#/components/schemas/RuletypesGettablePlannedMaintenance'
+ $ref: '#/components/schemas/RuletypesPlannedMaintenance'
status:
type: string
required:
@@ -6418,7 +6484,7 @@ paths:
content:
application/json:
schema:
- $ref: '#/components/schemas/RuletypesGettablePlannedMaintenance'
+ $ref: '#/components/schemas/RuletypesPostablePlannedMaintenance'
responses:
"204":
description: No Content
@@ -10709,7 +10775,9 @@ paths:
schema:
properties:
data:
- $ref: '#/components/schemas/RuletypesGettableRules'
+ items:
+ $ref: '#/components/schemas/RuletypesGettableRule'
+ type: array
status:
type: string
required:
diff --git a/frontend/src/api/generated/services/downtimeschedules/index.ts b/frontend/src/api/generated/services/downtimeschedules/index.ts
index 490d4617d7..a3f7298277 100644
--- a/frontend/src/api/generated/services/downtimeschedules/index.ts
+++ b/frontend/src/api/generated/services/downtimeschedules/index.ts
@@ -20,13 +20,14 @@ import { useMutation, useQuery } from 'react-query';
import type { BodyType, ErrorType } from '../../../generatedAPIInstance';
import { GeneratedAPIInstance } from '../../../generatedAPIInstance';
import type {
+ CreateDowntimeSchedule201,
DeleteDowntimeScheduleByIDPathParameters,
GetDowntimeScheduleByID200,
GetDowntimeScheduleByIDPathParameters,
ListDowntimeSchedules200,
ListDowntimeSchedulesParams,
RenderErrorResponseDTO,
- RuletypesGettablePlannedMaintenanceDTO,
+ RuletypesPostablePlannedMaintenanceDTO,
UpdateDowntimeScheduleByIDPathParameters,
} from '../sigNoz.schemas';
@@ -135,14 +136,14 @@ export const invalidateListDowntimeSchedules = async (
* @summary Create downtime schedule
*/
export const createDowntimeSchedule = (
- ruletypesGettablePlannedMaintenanceDTO: BodyType<RuletypesGettablePlannedMaintenanceDTO>,
+ ruletypesPostablePlannedMaintenanceDTO: BodyType<RuletypesPostablePlannedMaintenanceDTO>,
signal?: AbortSignal,
) => {
- return GeneratedAPIInstance<void>({
+ return GeneratedAPIInstance<CreateDowntimeSchedule201>({
url: `/api/v1/downtime_schedules`,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
- data: ruletypesGettablePlannedMaintenanceDTO,
+ data: ruletypesPostablePlannedMaintenanceDTO,
signal,
});
};
@@ -154,13 +155,13 @@ export const getCreateDowntimeScheduleMutationOptions = <
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof createDowntimeSchedule>>,
TError,
- { data: BodyType<RuletypesGettablePlannedMaintenanceDTO> },
+ { data: BodyType<RuletypesPostablePlannedMaintenanceDTO> },
TContext
>;
}): UseMutationOptions<
Awaited<ReturnType<typeof createDowntimeSchedule>>,
TError,
- { data: BodyType<RuletypesGettablePlannedMaintenanceDTO> },
+ { data: BodyType<RuletypesPostablePlannedMaintenanceDTO> },
TContext
> => {
const mutationKey = ['createDowntimeSchedule'];
@@ -174,7 +175,7 @@ export const getCreateDowntimeScheduleMutationOptions = <
const mutationFn: MutationFunction<
Awaited<ReturnType<typeof createDowntimeSchedule>>,
- { data: BodyType<RuletypesGettablePlannedMaintenanceDTO> }
+ { data: BodyType<RuletypesPostablePlannedMaintenanceDTO> }
> = (props) => {
const { data } = props ?? {};
@@ -187,7 +188,7 @@ export const getCreateDowntimeScheduleMutationOptions = <
export type CreateDowntimeScheduleMutationResult = NonNullable<
Awaited<ReturnType<typeof createDowntimeSchedule>>
>;
-export type CreateDowntimeScheduleMutationBody = BodyType<RuletypesGettablePlannedMaintenanceDTO>;
+export type CreateDowntimeScheduleMutationBody = BodyType<RuletypesPostablePlannedMaintenanceDTO>;
export type CreateDowntimeScheduleMutationError = ErrorType<RenderErrorResponseDTO>;
/**
@@ -200,13 +201,13 @@ export const useCreateDowntimeSchedule = <
mutation?: UseMutationOptions<
Awaited<ReturnType<typeof createDowntimeSchedule>>,
TError,
- { data: BodyType<RuletypesGettablePlannedMaintenanceDTO> },
+ { data: BodyType<RuletypesPostablePlannedMaintenanceDTO> },
TContext
>;
}): UseMutationResult<
Awaited<ReturnType<typeof createDowntimeSchedule>>,
TError,
- { data: BodyType<RuletypesGettablePlannedMaintenanceDTO> },
+ { data: BodyType<RuletypesPostablePlannedMaintenanceDTO> },
TContext
> => {
const mutationOptions = getCreateDowntimeScheduleMutationOptions(options);
@@ -402,13 +403,13 @@ export const invalidateGetDowntimeScheduleByID = async (
*/
export const updateDowntimeScheduleByID = (
{ id }: UpdateDowntimeScheduleByIDPathParameters,
- ruletypesGettablePlannedMaintenanceDTO: BodyType<RuletypesGettablePlannedMaintenanceDTO>,
+ ruletypesPostablePlannedMaintenanceDTO: BodyType<RuletypesPostablePlannedMaintenanceDTO>,
) => {
return GeneratedAPIInstance<void>({
url: `/api/v1/downtime_schedules/${id}`,
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
- data: ruletypesGettablePlannedMaintenanceDTO,
+ data: ruletypesPostablePlannedMaintenanceDTO,
});
};
@@ -421,7 +422,7 @@ export const getUpdateDowntimeScheduleByIDMutationOptions = <
TError,
{
pathParams: UpdateDowntimeScheduleByIDPathParameters;
- data: BodyType<RuletypesGettablePlannedMaintenanceDTO>;
+ data: BodyType<RuletypesPostablePlannedMaintenanceDTO>;
},
TContext
>;
@@ -430,7 +431,7 @@ export const getUpdateDowntimeScheduleByIDMutationOptions = <
TError,
{
pathParams: UpdateDowntimeScheduleByIDPathParameters;
- data: BodyType<RuletypesGettablePlannedMaintenanceDTO>;
+ data: BodyType<RuletypesPostablePlannedMaintenanceDTO>;
},
TContext
> => {
@@ -447,7 +448,7 @@ export const getUpdateDowntimeScheduleByIDMutationOptions = <
Awaited<ReturnType<typeof updateDowntimeScheduleByID>>,
{
pathParams: UpdateDowntimeScheduleByIDPathParameters;
- data: BodyType<RuletypesGettablePlannedMaintenanceDTO>;
+ data: BodyType<RuletypesPostablePlannedMaintenanceDTO>;
}
> = (props) => {
const { pathParams, data } = props ?? {};
@@ -461,7 +462,7 @@ export const getUpdateDowntimeScheduleByIDMutationOptions = <
export type UpdateDowntimeScheduleByIDMutationResult = NonNullable<
Awaited<ReturnType<typeof updateDowntimeScheduleByID>>
>;
-export type UpdateDowntimeScheduleByIDMutationBody = BodyType<RuletypesGettablePlannedMaintenanceDTO>;
+export type UpdateDowntimeScheduleByIDMutationBody = BodyType<RuletypesPostablePlannedMaintenanceDTO>;
export type UpdateDowntimeScheduleByIDMutationError = ErrorType<RenderErrorResponseDTO>;
/**
@@ -476,7 +477,7 @@ export const useUpdateDowntimeScheduleByID = <
TError,
{
pathParams: UpdateDowntimeScheduleByIDPathParameters;
- data: BodyType<RuletypesGettablePlannedMaintenanceDTO>;
+ data: BodyType<RuletypesPostablePlannedMaintenanceDTO>;
},
TContext
>;
@@ -485,7 +486,7 @@ export const useUpdateDowntimeScheduleByID = <
TError,
{
pathParams: UpdateDowntimeScheduleByIDPathParameters;
- data: BodyType<RuletypesGettablePlannedMaintenanceDTO>;
+ data: BodyType<RuletypesPostablePlannedMaintenanceDTO>;
},
TContext
> => {
diff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.ts
index b9ca9ccde8..04c1ddf282 100644
--- a/frontend/src/api/generated/services/sigNoz.schemas.ts
+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts
@@ -4551,6 +4551,12 @@ export enum RuletypesAlertStateDTO {
nodata = 'nodata',
disabled = 'disabled',
}
+export enum RuletypesAlertTypeDTO {
+ METRIC_BASED_ALERT = 'METRIC_BASED_ALERT',
+ TRACES_BASED_ALERT = 'TRACES_BASED_ALERT',
+ LOGS_BASED_ALERT = 'LOGS_BASED_ALERT',
+ EXCEPTIONS_BASED_ALERT = 'EXCEPTIONS_BASED_ALERT',
+}
export interface RuletypesBasicRuleThresholdDTO {
/**
* @type array
@@ -4609,7 +4615,7 @@ export interface RuletypesCumulativeScheduleDTO {
* @nullable true
*/
minute?: number | null;
- type?: RuletypesScheduleTypeDTO;
+ type: RuletypesScheduleTypeDTO;
/**
* @type integer
* @nullable true
@@ -4653,53 +4659,6 @@ export interface RuletypesEvaluationRollingDTO {
spec?: RuletypesRollingWindowDTO;
}
-export interface RuletypesGettablePlannedMaintenanceDTO {
- /**
- * @type array
- * @nullable true
- */
- alertIds?: string[] | null;
- /**
- * @type string
- * @format date-time
- */
- createdAt?: Date;
- /**
- * @type string
- */
- createdBy?: string;
- /**
- * @type string
- */
- description?: string;
- /**
- * @type string
- */
- id?: string;
- /**
- * @type string
- */
- kind?: string;
- /**
- * @type string
- */
- name: string;
- schedule: RuletypesScheduleDTO;
- /**
- * @type string
- */
- status?: string;
- /**
- * @type string
- * @format date-time
- */
- updatedAt?: Date;
- /**
- * @type string
- */
- updatedBy?: string;
-}
-
export type RuletypesGettableRuleDTOAnnotations = { [key: string]: string };
export type RuletypesGettableRuleDTOLabels = { [key: string]: string };
@@ -4709,10 +4668,7 @@ export interface RuletypesGettableRuleDTO {
* @type string
*/
alert: string;
- /**
- * @type string
- */
- alertType?: string;
+ alertType?: RuletypesAlertTypeDTO;
/**
* @type object
*/
@@ -4721,9 +4677,8 @@ export interface RuletypesGettableRuleDTO {
/**
* @type string
* @format date-time
- * @nullable true
*/
- createAt?: Date | null;
+ createAt: Date;
/**
* @type string
* @nullable true
@@ -4749,7 +4704,7 @@ export interface RuletypesGettableRuleDTO {
/**
* @type string
*/
- id?: string;
+ id: string;
/**
* @type object
*/
@@ -4768,13 +4723,12 @@ export interface RuletypesGettableRuleDTO {
* @type string
*/
source?: string;
- state?: RuletypesAlertStateDTO;
+ state: RuletypesAlertStateDTO;
/**
* @type string
* @format date-time
- * @nullable true
*/
- updateAt?: Date | null;
+ updateAt: Date;
/**
* @type string
* @nullable true
@@ -4786,14 +4740,6 @@ export interface RuletypesGettableRuleDTO {
version?: string;
}
-export interface RuletypesGettableRulesDTO {
- /**
- * @type array
- * @nullable true
- */
- rules?: RuletypesGettableRuleDTO[] | null;
-}
-
export interface RuletypesGettableTestRuleDTO {
/**
* @type integer
@@ -4805,6 +4751,15 @@ export interface RuletypesGettableTestRuleDTO {
message?: string;
}
+export enum RuletypesMaintenanceKindDTO {
+ fixed = 'fixed',
+ recurring = 'recurring',
+}
+export enum RuletypesMaintenanceStatusDTO {
+ active = 'active',
+ upcoming = 'upcoming',
+ expired = 'expired',
+}
export enum RuletypesMatchTypeDTO {
at_least_once = 'at_least_once',
all_the_times = 'all_the_times',
@@ -4833,6 +4788,64 @@ export enum RuletypesPanelTypeDTO {
table = 'table',
graph = 'graph',
}
+export interface RuletypesPlannedMaintenanceDTO {
+ /**
+ * @type array
+ * @nullable true
+ */
+ alertIds?: string[] | null;
+ /**
+ * @type string
+ * @format date-time
+ */
+ createdAt?: Date;
+ /**
+ * @type string
+ */
+ createdBy?: string;
+ /**
+ * @type string
+ */
+ description?: string;
+ /**
+ * @type string
+ */
+ id: string;
+ kind: RuletypesMaintenanceKindDTO;
+ /**
+ * @type string
+ */
+ name: string;
+ schedule: RuletypesScheduleDTO;
+ status: RuletypesMaintenanceStatusDTO;
+ /**
+ * @type string
+ * @format date-time
+ */
+ updatedAt?: Date;
+ /**
+ * @type string
+ */
+ updatedBy?: string;
+}
+
+export interface RuletypesPostablePlannedMaintenanceDTO {
+ /**
+ * @type array
+ * @nullable true
+ */
+ alertIds?: string[] | null;
+ /**
+ * @type string
+ */
+ description?: string;
+ /**
+ * @type string
+ */
+ name: string;
+ schedule: RuletypesScheduleDTO;
+}
+
export type RuletypesPostableRuleDTOAnnotations = { [key: string]: string };
export type RuletypesPostableRuleDTOLabels = { [key: string]: string };
@@ -4842,10 +4855,7 @@ export interface RuletypesPostableRuleDTO {
* @type string
*/
alert: string;
- /**
- * @type string
- */
- alertType?: string;
+ alertType?: RuletypesAlertTypeDTO;
/**
* @type object
*/
@@ -4901,7 +4911,7 @@ export interface RuletypesRecurrenceDTO {
/**
* @type string
*/
- duration?: string;
+ duration: string;
/**
* @type string
* @format date-time
@@ -4912,16 +4922,13 @@ export interface RuletypesRecurrenceDTO {
* @type array
* @nullable true
*/
- repeatOn?: string[] | null;
- /**
- * @type string
- */
- repeatType?: string;
+ repeatOn?: RuletypesRepeatOnDTO[] | null;
+ repeatType: RuletypesRepeatTypeDTO;
/**
* @type string
* @format date-time
*/
- startTime?: Date;
+ startTime: Date;
}
export interface RuletypesRenotifyDTO {
@@ -4939,6 +4946,20 @@ export interface RuletypesRenotifyDTO {
interval?: string;
}
+export enum RuletypesRepeatOnDTO {
+ sunday = 'sunday',
+ monday = 'monday',
+ tuesday = 'tuesday',
+ wednesday = 'wednesday',
+ thursday = 'thursday',
+ friday = 'friday',
+ saturday = 'saturday',
+}
+export enum RuletypesRepeatTypeDTO {
+ daily = 'daily',
+ weekly = 'weekly',
+ monthly = 'monthly',
+}
export interface RuletypesRollingWindowDTO {
/**
* @type string
@@ -5977,7 +5998,15 @@ export type ListDowntimeSchedules200 = {
/**
* @type array
*/
- data: RuletypesGettablePlannedMaintenanceDTO[];
+ data: RuletypesPlannedMaintenanceDTO[];
+ /**
+ * @type string
+ */
+ status: string;
+};
+
+export type CreateDowntimeSchedule201 = {
+ data: RuletypesPlannedMaintenanceDTO;
/**
* @type string
*/
@@ -5991,7 +6020,7 @@ export type GetDowntimeScheduleByIDPathParameters = {
id: string;
};
export type GetDowntimeScheduleByID200 = {
- data: RuletypesGettablePlannedMaintenanceDTO;
+ data: RuletypesPlannedMaintenanceDTO;
/**
* @type string
*/
@@ -6799,7 +6828,10 @@ export type GetUsersByRoleID200 = {
};
export type ListRules200 = {
- data: RuletypesGettableRulesDTO;
+ /**
+ * @type array
+ */
+ data: RuletypesGettableRuleDTO[];
/**
* @type string
*/
diff --git a/pkg/apiserver/signozapiserver/ruler.go b/pkg/apiserver/signozapiserver/ruler.go
index 51cd2663ac..7aaf66f91c 100644
--- a/pkg/apiserver/signozapiserver/ruler.go
+++ b/pkg/apiserver/signozapiserver/ruler.go
@@ -15,7 +15,7 @@ func (provider *provider) addRulerRoutes(router *mux.Router) error {
Tags: []string{"rules"},
Summary: "List alert rules",
Description: "This endpoint lists all alert rules with their current evaluation state",
- Response: new(ruletypes.GettableRules),
+ Response: make([]*ruletypes.GettableRule, 0),
ResponseContentType: "application/json",
SuccessStatusCode: http.StatusOK,
SecuritySchemes: newSecuritySchemes(types.RoleViewer),
@@ -117,7 +117,7 @@ func (provider *provider) addRulerRoutes(router *mux.Router) error {
Summary: "List downtime schedules",
Description: "This endpoint lists all planned maintenance / downtime schedules",
RequestQuery: new(ruletypes.ListPlannedMaintenanceParams),
- Response: make([]*ruletypes.GettablePlannedMaintenance, 0),
+ Response: make([]*ruletypes.PlannedMaintenance, 0),
ResponseContentType: "application/json",
SuccessStatusCode: http.StatusOK,
SecuritySchemes: newSecuritySchemes(types.RoleViewer),
@@ -130,7 +130,7 @@ func (provider *provider) addRulerRoutes(router *mux.Router) error {
Tags: []string{"downtimeschedules"},
Summary: "Get downtime schedule by ID",
Description: "This endpoint returns a downtime schedule by ID",
- Response: new(ruletypes.GettablePlannedMaintenance),
+ Response: new(ruletypes.PlannedMaintenance),
ResponseContentType: "application/json",
SuccessStatusCode: http.StatusOK,
ErrorStatusCodes: []int{http.StatusNotFound},
@@ -144,8 +144,10 @@ func (provider *provider) addRulerRoutes(router *mux.Router) error {
Tags: []string{"downtimeschedules"},
Summary: "Create downtime schedule",
Description: "This endpoint creates a new planned maintenance / downtime schedule",
- Request: new(ruletypes.GettablePlannedMaintenance),
+ Request: new(ruletypes.PostablePlannedMaintenance),
RequestContentType: "application/json",
+ Response: new(ruletypes.PlannedMaintenance),
+ ResponseContentType: "application/json",
SuccessStatusCode: http.StatusCreated,
ErrorStatusCodes: []int{http.StatusBadRequest},
SecuritySchemes: newSecuritySchemes(types.RoleEditor),
@@ -158,7 +160,7 @@ func (provider *provider) addRulerRoutes(router *mux.Router) error {
Tags: []string{"downtimeschedules"},
Summary: "Update downtime schedule",
Description: "This endpoint updates a downtime schedule by ID",
- Request: new(ruletypes.GettablePlannedMaintenance),
+ Request: new(ruletypes.PostablePlannedMaintenance),
RequestContentType: "application/json",
SuccessStatusCode: http.StatusNoContent,
ErrorStatusCodes: []int{http.StatusBadRequest, http.StatusNotFound},
diff --git a/pkg/query-service/rules/manager.go b/pkg/query-service/rules/manager.go
index 752667ad78..19f5637dc3 100644
--- a/pkg/query-service/rules/manager.go
+++ b/pkg/query-service/rules/manager.go
@@ -856,9 +856,9 @@ func (m *Manager) ListRuleStates(ctx context.Context) (*ruletypes.GettableRules,
} else {
ruleResponse.State = rm.State()
}
- ruleResponse.CreatedAt = &s.CreatedAt
+ ruleResponse.CreatedAt = s.CreatedAt
ruleResponse.CreatedBy = &s.CreatedBy
- ruleResponse.UpdatedAt = &s.UpdatedAt
+ ruleResponse.UpdatedAt = s.UpdatedAt
ruleResponse.UpdatedBy = &s.UpdatedBy
resp = append(resp, &ruleResponse)
}
@@ -885,9 +885,9 @@ func (m *Manager) GetRule(ctx context.Context, id valuer.UUID) (*ruletypes.Getta
} else {
r.State = rm.State()
}
- r.CreatedAt = &s.CreatedAt
+ r.CreatedAt = s.CreatedAt
r.CreatedBy = &s.CreatedBy
- r.UpdatedAt = &s.UpdatedAt
+ r.UpdatedAt = s.UpdatedAt
r.UpdatedBy = &s.UpdatedBy
return &r, nil
diff --git a/pkg/query-service/rules/prom_rule_task.go b/pkg/query-service/rules/prom_rule_task.go
index 05fa66a759..16537ef412 100644
--- a/pkg/query-service/rules/prom_rule_task.go
+++ b/pkg/query-service/rules/prom_rule_task.go
@@ -330,7 +330,7 @@ func (g *PromRuleTask) Eval(ctx context.Context, ts time.Time) {
}()
g.logger.InfoContext(ctx, "promql rule task", "name", g.name, "eval_started_at", ts)
- maintenance, err := g.maintenanceStore.GetAllPlannedMaintenance(ctx, g.orgID.StringValue())
+ maintenance, err := g.maintenanceStore.ListPlannedMaintenance(ctx, g.orgID.StringValue())
if err != nil {
g.logger.ErrorContext(ctx, "error in processing sql query", errors.Attr(err))
}
diff --git a/pkg/query-service/rules/rule_task.go b/pkg/query-service/rules/rule_task.go
index 5b0e6c1a48..75a72a3957 100644
--- a/pkg/query-service/rules/rule_task.go
+++ b/pkg/query-service/rules/rule_task.go
@@ -318,7 +318,7 @@ func (g *RuleTask) Eval(ctx context.Context, ts time.Time) {
g.logger.DebugContext(ctx, "rule task eval started", "name", g.name, "start_time", ts)
- maintenance, err := g.maintenanceStore.GetAllPlannedMaintenance(ctx, g.orgID.StringValue())
+ maintenance, err := g.maintenanceStore.ListPlannedMaintenance(ctx, g.orgID.StringValue())
if err != nil {
g.logger.ErrorContext(ctx, "error in processing sql query", errors.Attr(err))
diff --git a/pkg/ruler/rulestore/sqlrulestore/maintenance.go b/pkg/ruler/rulestore/sqlrulestore/maintenance.go
index 0f713c7e1e..f3c2cb2ac8 100644
--- a/pkg/ruler/rulestore/sqlrulestore/maintenance.go
+++ b/pkg/ruler/rulestore/sqlrulestore/maintenance.go
@@ -20,8 +20,8 @@ func NewMaintenanceStore(store sqlstore.SQLStore) ruletypes.MaintenanceStore {
return &maintenance{sqlstore: store}
}
-func (r *maintenance) GetAllPlannedMaintenance(ctx context.Context, orgID string) ([]*ruletypes.GettablePlannedMaintenance, error) {
- gettableMaintenancesRules := make([]*ruletypes.GettablePlannedMaintenanceRule, 0)
+func (r *maintenance) ListPlannedMaintenance(ctx context.Context, orgID string) ([]*ruletypes.PlannedMaintenance, error) {
+ gettableMaintenancesRules := make([]*ruletypes.PlannedMaintenanceWithRules, 0)
err := r.sqlstore.
BunDB().
NewSelect().
@@ -33,16 +33,16 @@ func (r *maintenance) GetAllPlannedMaintenance(ctx context.Context, orgID string
return nil, err
}
- gettablePlannedMaintenance := make([]*ruletypes.GettablePlannedMaintenance, 0)
+ gettablePlannedMaintenance := make([]*ruletypes.PlannedMaintenance, 0)
for _, gettableMaintenancesRule := range gettableMaintenancesRules {
- gettablePlannedMaintenance = append(gettablePlannedMaintenance, gettableMaintenancesRule.ConvertGettableMaintenanceRuleToGettableMaintenance())
+ gettablePlannedMaintenance = append(gettablePlannedMaintenance, gettableMaintenancesRule.ToPlannedMaintenance())
}
return gettablePlannedMaintenance, nil
}
-func (r *maintenance) GetPlannedMaintenanceByID(ctx context.Context, id valuer.UUID) (*ruletypes.GettablePlannedMaintenance, error) {
- storableMaintenanceRule := new(ruletypes.GettablePlannedMaintenanceRule)
+func (r *maintenance) GetPlannedMaintenanceByID(ctx context.Context, id valuer.UUID) (*ruletypes.PlannedMaintenance, error) {
+ storableMaintenanceRule := new(ruletypes.PlannedMaintenanceWithRules)
err := r.sqlstore.
BunDB().
NewSelect().
@@ -54,13 +54,13 @@ func (r *maintenance) GetPlannedMaintenanceByID(ctx context.Context, id valuer.U
return nil, r.sqlstore.WrapNotFoundErrf(err, errors.CodeNotFound, "planned maintenance with ID: %s does not exist", id.StringValue())
}
- return storableMaintenanceRule.ConvertGettableMaintenanceRuleToGettableMaintenance(), nil
+ return storableMaintenanceRule.ToPlannedMaintenance(), nil
}
-func (r *maintenance) CreatePlannedMaintenance(ctx context.Context, maintenance ruletypes.GettablePlannedMaintenance) (valuer.UUID, error) {
+func (r *maintenance) CreatePlannedMaintenance(ctx context.Context, maintenance *ruletypes.PostablePlannedMaintenance) (*ruletypes.PlannedMaintenance, error) {
claims, err := authtypes.ClaimsFromContext(ctx)
if err != nil {
- return valuer.UUID{}, err
+ return nil, err
}
storablePlannedMaintenance := ruletypes.StorablePlannedMaintenance{
@@ -82,10 +82,10 @@ func (r *maintenance) CreatePlannedMaintenance(ctx context.Context, maintenance
}
maintenanceRules := make([]*ruletypes.StorablePlannedMaintenanceRule, 0)
- for _, ruleIDStr := range maintenance.RuleIDs {
+ for _, ruleIDStr := range maintenance.AlertIds {
ruleID, err := valuer.NewUUID(ruleIDStr)
if err != nil {
- return valuer.UUID{}, err
+ return nil, err
}
maintenanceRules = append(maintenanceRules, &ruletypes.StorablePlannedMaintenanceRule{
@@ -122,10 +122,20 @@ func (r *maintenance) CreatePlannedMaintenance(ctx context.Context, maintenance
return nil
})
if err != nil {
- return valuer.UUID{}, err
+ return nil, err
}
- return storablePlannedMaintenance.ID, nil
+ return &ruletypes.PlannedMaintenance{
+ ID: storablePlannedMaintenance.ID,
+ Name: storablePlannedMaintenance.Name,
+ Description: storablePlannedMaintenance.Description,
+ Schedule: storablePlannedMaintenance.Schedule,
+ RuleIDs: maintenance.AlertIds,
+ CreatedAt: storablePlannedMaintenance.CreatedAt,
+ CreatedBy: storablePlannedMaintenance.CreatedBy,
+ UpdatedAt: storablePlannedMaintenance.UpdatedAt,
+ UpdatedBy: storablePlannedMaintenance.UpdatedBy,
+ }, nil
}
func (r *maintenance) DeletePlannedMaintenance(ctx context.Context, id valuer.UUID) error {
@@ -142,22 +152,27 @@ func (r *maintenance) DeletePlannedMaintenance(ctx context.Context, id valuer.UU
return nil
}
-func (r *maintenance) EditPlannedMaintenance(ctx context.Context, maintenance ruletypes.GettablePlannedMaintenance, id valuer.UUID) error {
+func (r *maintenance) UpdatePlannedMaintenance(ctx context.Context, maintenance *ruletypes.PostablePlannedMaintenance, id valuer.UUID) error {
claims, err := authtypes.ClaimsFromContext(ctx)
if err != nil {
return err
}
+ existing, err := r.GetPlannedMaintenanceByID(ctx, id)
+ if err != nil {
+ return err
+ }
+
storablePlannedMaintenance := ruletypes.StorablePlannedMaintenance{
Identifiable: types.Identifiable{
ID: id,
},
TimeAuditable: types.TimeAuditable{
- CreatedAt: maintenance.CreatedAt,
+ CreatedAt: existing.CreatedAt,
UpdatedAt: time.Now(),
},
UserAuditable: types.UserAuditable{
- CreatedBy: maintenance.CreatedBy,
+ CreatedBy: existing.CreatedBy,
UpdatedBy: claims.Email,
},
Name: maintenance.Name,
@@ -167,7 +182,7 @@ func (r *maintenance) EditPlannedMaintenance(ctx context.Context, maintenance ru
}
storablePlannedMaintenanceRules := make([]*ruletypes.StorablePlannedMaintenanceRule, 0)
- for _, ruleIDStr := range maintenance.RuleIDs {
+ for _, ruleIDStr := range maintenance.AlertIds {
ruleID, err := valuer.NewUUID(ruleIDStr)
if err != nil {
return err
diff --git a/pkg/ruler/signozruler/handler.go b/pkg/ruler/signozruler/handler.go
index a0cd377111..b65fc81fda 100644
--- a/pkg/ruler/signozruler/handler.go
+++ b/pkg/ruler/signozruler/handler.go
@@ -34,7 +34,7 @@ func (handler *handler) ListRules(rw http.ResponseWriter, req *http.Request) {
return
}
- render.Success(rw, http.StatusOK, rules)
+ render.Success(rw, http.StatusOK, rules.Rules)
}
func (handler *handler) GetRuleByID(rw http.ResponseWriter, req *http.Request) {
@@ -191,14 +191,14 @@ func (handler *handler) ListDowntimeSchedules(rw http.ResponseWriter, req *http.
return
}
- schedules, err := handler.ruler.MaintenanceStore().GetAllPlannedMaintenance(ctx, claims.OrgID)
+ schedules, err := handler.ruler.MaintenanceStore().ListPlannedMaintenance(ctx, claims.OrgID)
if err != nil {
render.Error(rw, err)
return
}
if params.Active != nil {
- activeSchedules := make([]*ruletypes.GettablePlannedMaintenance, 0)
+ activeSchedules := make([]*ruletypes.PlannedMaintenance, 0)
for _, schedule := range schedules {
now := time.Now().In(time.FixedZone(schedule.Schedule.Timezone, 0))
if schedule.IsActive(now) == *params.Active {
@@ -209,7 +209,7 @@ func (handler *handler) ListDowntimeSchedules(rw http.ResponseWriter, req *http.
}
if params.Recurring != nil {
- recurringSchedules := make([]*ruletypes.GettablePlannedMaintenance, 0)
+ recurringSchedules := make([]*ruletypes.PlannedMaintenance, 0)
for _, schedule := range schedules {
if schedule.IsRecurring() == *params.Recurring {
recurringSchedules = append(recurringSchedules, schedule)
@@ -244,8 +244,8 @@ func (handler *handler) CreateDowntimeSchedule(rw http.ResponseWriter, req *http
ctx, cancel := context.WithTimeout(req.Context(), 30*time.Second)
defer cancel()
- var schedule ruletypes.GettablePlannedMaintenance
- if err := binding.JSON.BindBody(req.Body, &schedule); err != nil {
+ schedule := new(ruletypes.PostablePlannedMaintenance)
+ if err := binding.JSON.BindBody(req.Body, schedule); err != nil {
render.Error(rw, err)
return
}
@@ -255,13 +255,13 @@ func (handler *handler) CreateDowntimeSchedule(rw http.ResponseWriter, req *http
return
}
- _, err := handler.ruler.MaintenanceStore().CreatePlannedMaintenance(ctx, schedule)
+ created, err := handler.ruler.MaintenanceStore().CreatePlannedMaintenance(ctx, schedule)
if err != nil {
render.Error(rw, err)
return
}
- render.Success(rw, http.StatusCreated, nil)
+ render.Success(rw, http.StatusCreated, created)
}
func (handler *handler) UpdateDowntimeScheduleByID(rw http.ResponseWriter, req *http.Request) {
@@ -274,8 +274,8 @@ func (handler *handler) UpdateDowntimeScheduleByID(rw http.ResponseWriter, req *
return
}
- var schedule ruletypes.GettablePlannedMaintenance
- if err := binding.JSON.BindBody(req.Body, &schedule); err != nil {
+ schedule := new(ruletypes.PostablePlannedMaintenance)
+ if err := binding.JSON.BindBody(req.Body, schedule); err != nil {
render.Error(rw, err)
return
}
@@ -285,7 +285,7 @@ func (handler *handler) UpdateDowntimeScheduleByID(rw http.ResponseWriter, req *
return
}
- err = handler.ruler.MaintenanceStore().EditPlannedMaintenance(ctx, schedule, id)
+ err = handler.ruler.MaintenanceStore().UpdatePlannedMaintenance(ctx, schedule, id)
if err != nil {
render.Error(rw, err)
return
diff --git a/pkg/types/ruletypes/api_params.go b/pkg/types/ruletypes/api_params.go
index d7b6cf0195..772b80f8ec 100644
--- a/pkg/types/ruletypes/api_params.go
+++ b/pkg/types/ruletypes/api_params.go
@@ -25,6 +25,16 @@ const (
AlertTypeExceptions AlertType = "EXCEPTIONS_BASED_ALERT"
)
+// Enum implements jsonschema.Enum; returns the acceptable values for AlertType.
+func (AlertType) Enum() []any {
+ return []any{
+ AlertTypeMetric,
+ AlertTypeTraces,
+ AlertTypeLogs,
+ AlertTypeExceptions,
+ }
+}
+
const (
DefaultSchemaVersion = "v1"
SchemaVersionV2Alpha1 = "v2alpha1"
@@ -597,13 +607,13 @@ type GettableRules struct {
// GettableRule has info for an alerting rules.
type GettableRule struct {
- Id string `json:"id"`
- State AlertState `json:"state"`
+ Id string `json:"id" required:"true"`
+ State AlertState `json:"state" required:"true"`
PostableRule
- CreatedAt *time.Time `json:"createAt"`
- CreatedBy *string `json:"createBy"`
- UpdatedAt *time.Time `json:"updateAt"`
- UpdatedBy *string `json:"updateBy"`
+ CreatedAt time.Time `json:"createAt" required:"true"`
+ CreatedBy *string `json:"createBy" nullable:"true"`
+ UpdatedAt time.Time `json:"updateAt" required:"true"`
+ UpdatedBy *string `json:"updateBy" nullable:"true"`
}
func (g *GettableRule) MarshalJSON() ([]byte, error) {
diff --git a/pkg/types/ruletypes/evaluation.go b/pkg/types/ruletypes/evaluation.go
index 48adea1442..883fb9a5a3 100644
--- a/pkg/types/ruletypes/evaluation.go
+++ b/pkg/types/ruletypes/evaluation.go
@@ -61,7 +61,7 @@ type CumulativeWindow struct {
}
type CumulativeSchedule struct {
- Type ScheduleType `json:"type"`
+ Type ScheduleType `json:"type" required:"true"`
Minute *int `json:"minute,omitempty"` // 0-59, for all types
Hour *int `json:"hour,omitempty"` // 0-23, for daily/weekly/monthly
Day *int `json:"day,omitempty"` // 1-31, for monthly
diff --git a/pkg/types/ruletypes/maintenance.go b/pkg/types/ruletypes/maintenance.go
index 037909248b..c7ea4a86d3 100644
--- a/pkg/types/ruletypes/maintenance.go
+++ b/pkg/types/ruletypes/maintenance.go
@@ -15,6 +15,42 @@ var (
ErrCodeInvalidPlannedMaintenancePayload = errors.MustNewCode("invalid_planned_maintenance_payload")
)
+type MaintenanceStatus struct {
+ valuer.String
+}
+
+var (
+ MaintenanceStatusActive = MaintenanceStatus{valuer.NewString("active")}
+ MaintenanceStatusUpcoming = MaintenanceStatus{valuer.NewString("upcoming")}
+ MaintenanceStatusExpired = MaintenanceStatus{valuer.NewString("expired")}
+)
+
+// Enum implements jsonschema.Enum; returns the acceptable values for MaintenanceStatus.
+func (MaintenanceStatus) Enum() []any {
+ return []any{
+ MaintenanceStatusActive,
+ MaintenanceStatusUpcoming,
+ MaintenanceStatusExpired,
+ }
+}
+
+type MaintenanceKind struct {
+ valuer.String
+}
+
+var (
+ MaintenanceKindFixed = MaintenanceKind{valuer.NewString("fixed")}
+ MaintenanceKindRecurring = MaintenanceKind{valuer.NewString("recurring")}
+)
+
+// Enum implements jsonschema.Enum; returns the acceptable values for MaintenanceKind.
+func (MaintenanceKind) Enum() []any {
+ return []any{
+ MaintenanceKindFixed,
+ MaintenanceKindRecurring,
+ }
+}
+
type StorablePlannedMaintenance struct {
bun.BaseModel `bun:"table:planned_maintenance"`
types.Identifiable
@@ -26,18 +62,63 @@ type StorablePlannedMaintenance struct {
OrgID string `bun:"org_id,type:text"`
}
-type GettablePlannedMaintenance struct {
- Id string `json:"id"`
+type PlannedMaintenance struct {
+ ID valuer.UUID `json:"id" required:"true"`
+ Name string `json:"name" required:"true"`
+ Description string `json:"description"`
+ Schedule *Schedule `json:"schedule" required:"true"`
+ RuleIDs []string `json:"alertIds"`
+ CreatedAt time.Time `json:"createdAt"`
+ CreatedBy string `json:"createdBy"`
+ UpdatedAt time.Time `json:"updatedAt"`
+ UpdatedBy string `json:"updatedBy"`
+ Status MaintenanceStatus `json:"status" required:"true"`
+ Kind MaintenanceKind `json:"kind" required:"true"`
+}
+
+// PostablePlannedMaintenance is the input payload for creating or updating a
+// planned maintenance. Server-owned fields (id, timestamps, audit users,
+// derived status / kind) are deliberately not accepted from the client.
+type PostablePlannedMaintenance struct {
Name string `json:"name" required:"true"`
Description string `json:"description"`
Schedule *Schedule `json:"schedule" required:"true"`
- RuleIDs []string `json:"alertIds"`
- CreatedAt time.Time `json:"createdAt"`
- CreatedBy string `json:"createdBy"`
- UpdatedAt time.Time `json:"updatedAt"`
- UpdatedBy string `json:"updatedBy"`
- Status string `json:"status"`
- Kind string `json:"kind"`
+ AlertIds []string `json:"alertIds"`
+}
+
+func (p *PostablePlannedMaintenance) Validate() error {
+ if p.Name == "" {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "missing name in the payload")
+ }
+ if p.Schedule == nil {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "missing schedule in the payload")
+ }
+ if p.Schedule.Timezone == "" {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "missing timezone in the payload")
+ }
+
+ if _, err := time.LoadLocation(p.Schedule.Timezone); err != nil {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "invalid timezone in the payload")
+ }
+
+ if !p.Schedule.StartTime.IsZero() && !p.Schedule.EndTime.IsZero() {
+ if p.Schedule.StartTime.After(p.Schedule.EndTime) {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "start time cannot be after end time")
+ }
+ }
+
+ if p.Schedule.Recurrence != nil {
+ if p.Schedule.Recurrence.RepeatType.IsZero() {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "missing repeat type in the payload")
+ }
+ if p.Schedule.Recurrence.Duration.IsZero() {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "missing duration in the payload")
+ }
+ if p.Schedule.Recurrence.EndTime != nil && p.Schedule.Recurrence.EndTime.Before(p.Schedule.Recurrence.StartTime) {
+ return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "end time cannot be before start time")
+ }
+ }
+ return nil
}
type StorablePlannedMaintenanceRule struct {
@@ -47,12 +128,12 @@ type StorablePlannedMaintenanceRule struct {
RuleID valuer.UUID `bun:"rule_id,type:text"`
}
-type GettablePlannedMaintenanceRule struct {
+type PlannedMaintenanceWithRules struct {
*StorablePlannedMaintenance `bun:",extend"`
Rules []*StorablePlannedMaintenanceRule `bun:"rel:has-many,join:id=planned_maintenance_id"`
}
-func (m *GettablePlannedMaintenance) ShouldSkip(ruleID string, now time.Time) bool {
+func (m *PlannedMaintenance) ShouldSkip(ruleID string, now time.Time) bool {
// Check if the alert ID is in the maintenance window
found := false
if len(m.RuleIDs) > 0 {
@@ -122,7 +203,7 @@ func (m *GettablePlannedMaintenance) ShouldSkip(ruleID string, now time.Time) bo
// checkDaily rebases the recurrence start to today (or yesterday if needed)
// and returns true if currentTime is within [candidate, candidate+Duration].
-func (m *GettablePlannedMaintenance) checkDaily(currentTime time.Time, rec *Recurrence, loc *time.Location) bool {
+func (m *PlannedMaintenance) checkDaily(currentTime time.Time, rec *Recurrence, loc *time.Location) bool {
candidate := time.Date(
currentTime.Year(), currentTime.Month(), currentTime.Day(),
rec.StartTime.Hour(), rec.StartTime.Minute(), 0, 0,
@@ -137,7 +218,7 @@ func (m *GettablePlannedMaintenance) checkDaily(currentTime time.Time, rec *Recu
// checkWeekly finds the most recent allowed occurrence by rebasing the recurrence’s
// time-of-day onto the allowed weekday. It does this for each allowed day and returns true
// if the current time falls within the candidate window.
-func (m *GettablePlannedMaintenance) checkWeekly(currentTime time.Time, rec *Recurrence, loc *time.Location) bool {
+func (m *PlannedMaintenance) checkWeekly(currentTime time.Time, rec *Recurrence, loc *time.Location) bool {
// If no days specified, treat as every day (like daily).
if len(rec.RepeatOn) == 0 {
return m.checkDaily(currentTime, rec, loc)
@@ -169,7 +250,7 @@ func (m *GettablePlannedMaintenance) checkWeekly(currentTime time.Time, rec *Rec
// checkMonthly rebases the candidate occurrence using the recurrence's day-of-month.
// If the candidate for the current month is in the future, it uses the previous month.
-func (m *GettablePlannedMaintenance) checkMonthly(currentTime time.Time, rec *Recurrence, loc *time.Location) bool {
+func (m *PlannedMaintenance) checkMonthly(currentTime time.Time, rec *Recurrence, loc *time.Location) bool {
refDay := rec.StartTime.Day()
year, month, _ := currentTime.Date()
lastDay := time.Date(year, month+1, 0, 0, 0, 0, 0, loc).Day()
@@ -201,7 +282,7 @@ func (m *GettablePlannedMaintenance) checkMonthly(currentTime time.Time, rec *Re
return currentTime.Sub(candidate) <= rec.Duration.Duration()
}
-func (m *GettablePlannedMaintenance) IsActive(now time.Time) bool {
+func (m *PlannedMaintenance) IsActive(now time.Time) bool {
ruleID := "maintenance"
if len(m.RuleIDs) > 0 {
ruleID = (m.RuleIDs)[0]
@@ -209,7 +290,7 @@ func (m *GettablePlannedMaintenance) IsActive(now time.Time) bool {
return m.ShouldSkip(ruleID, now)
}
-func (m *GettablePlannedMaintenance) IsUpcoming() bool {
+func (m *PlannedMaintenance) IsUpcoming() bool {
loc, err := time.LoadLocation(m.Schedule.Timezone)
if err != nil {
return false
@@ -225,11 +306,11 @@ func (m *GettablePlannedMaintenance) IsUpcoming() bool {
return false
}
-func (m *GettablePlannedMaintenance) IsRecurring() bool {
+func (m *PlannedMaintenance) IsRecurring() bool {
return m.Schedule.Recurrence != nil
}
-func (m *GettablePlannedMaintenance) Validate() error {
+func (m *PlannedMaintenance) Validate() error {
if m.Name == "" {
return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "missing name in the payload")
}
@@ -252,7 +333,7 @@ func (m *GettablePlannedMaintenance) Validate() error {
}
if m.Schedule.Recurrence != nil {
- if m.Schedule.Recurrence.RepeatType == "" {
+ if m.Schedule.Recurrence.RepeatType.IsZero() {
return errors.Newf(errors.TypeInvalidInput, ErrCodeInvalidPlannedMaintenancePayload, "missing repeat type in the payload")
}
if m.Schedule.Recurrence.Duration.IsZero() {
@@ -265,38 +346,38 @@ func (m *GettablePlannedMaintenance) Validate() error {
return nil
}
-func (m GettablePlannedMaintenance) MarshalJSON() ([]byte, error) {
+func (m PlannedMaintenance) MarshalJSON() ([]byte, error) {
now := time.Now().In(time.FixedZone(m.Schedule.Timezone, 0))
- var status string
+ var status MaintenanceStatus
if m.IsActive(now) {
- status = "active"
+ status = MaintenanceStatusActive
} else if m.IsUpcoming() {
- status = "upcoming"
+ status = MaintenanceStatusUpcoming
} else {
- status = "expired"
+ status = MaintenanceStatusExpired
}
- var kind string
+ var kind MaintenanceKind
if !m.Schedule.StartTime.IsZero() && !m.Schedule.EndTime.IsZero() && m.Schedule.EndTime.After(m.Schedule.StartTime) {
- kind = "fixed"
+ kind = MaintenanceKindFixed
} else {
- kind = "recurring"
+ kind = MaintenanceKindRecurring
}
return json.Marshal(struct {
- Id string `json:"id" db:"id"`
- Name string `json:"name" db:"name"`
- Description string `json:"description" db:"description"`
- Schedule *Schedule `json:"schedule" db:"schedule"`
- AlertIds []string `json:"alertIds" db:"alert_ids"`
- CreatedAt time.Time `json:"createdAt" db:"created_at"`
- CreatedBy string `json:"createdBy" db:"created_by"`
- UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
- UpdatedBy string `json:"updatedBy" db:"updated_by"`
- Status string `json:"status"`
- Kind string `json:"kind"`
+ ID valuer.UUID `json:"id" db:"id"`
+ Name string `json:"name" db:"name"`
+ Description string `json:"description" db:"description"`
+ Schedule *Schedule `json:"schedule" db:"schedule"`
+ AlertIds []string `json:"alertIds" db:"alert_ids"`
+ CreatedAt time.Time `json:"createdAt" db:"created_at"`
+ CreatedBy string `json:"createdBy" db:"created_by"`
+ UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
+ UpdatedBy string `json:"updatedBy" db:"updated_by"`
+ Status MaintenanceStatus `json:"status"`
+ Kind MaintenanceKind `json:"kind"`
}{
- Id: m.Id,
+ ID: m.ID,
Name: m.Name,
Description: m.Description,
Schedule: m.Schedule,
@@ -310,7 +391,7 @@ func (m GettablePlannedMaintenance) MarshalJSON() ([]byte, error) {
})
}
-func (m *GettablePlannedMaintenanceRule) ConvertGettableMaintenanceRuleToGettableMaintenance() *GettablePlannedMaintenance {
+func (m *PlannedMaintenanceWithRules) ToPlannedMaintenance() *PlannedMaintenance {
ruleIDs := []string{}
if m.Rules != nil {
for _, storableMaintenanceRule := range m.Rules {
@@ -318,8 +399,8 @@ func (m *GettablePlannedMaintenanceRule) ConvertGettableMaintenanceRuleToGettabl
}
}
- return &GettablePlannedMaintenance{
- Id: m.ID.StringValue(),
+ return &PlannedMaintenance{
+ ID: m.ID,
Name: m.Name,
Description: m.Description,
Schedule: m.Schedule,
@@ -337,9 +418,9 @@ type ListPlannedMaintenanceParams struct {
}
type MaintenanceStore interface {
- CreatePlannedMaintenance(context.Context, GettablePlannedMaintenance) (valuer.UUID, error)
+ CreatePlannedMaintenance(context.Context, *PostablePlannedMaintenance) (*PlannedMaintenance, error)
DeletePlannedMaintenance(context.Context, valuer.UUID) error
- GetPlannedMaintenanceByID(context.Context, valuer.UUID) (*GettablePlannedMaintenance, error)
- EditPlannedMaintenance(context.Context, GettablePlannedMaintenance, valuer.UUID) error
- GetAllPlannedMaintenance(context.Context, string) ([]*GettablePlannedMaintenance, error)
+ GetPlannedMaintenanceByID(context.Context, valuer.UUID) (*PlannedMaintenance, error)
+ UpdatePlannedMaintenance(context.Context, *PostablePlannedMaintenance, valuer.UUID) error
+ ListPlannedMaintenance(context.Context, string) ([]*PlannedMaintenance, error)
}
diff --git a/pkg/types/ruletypes/maintenance_test.go b/pkg/types/ruletypes/maintenance_test.go
index 22ae497e50..541bc3bc9d 100644
--- a/pkg/types/ruletypes/maintenance_test.go
+++ b/pkg/types/ruletypes/maintenance_test.go
@@ -16,13 +16,13 @@ func TestShouldSkipMaintenance(t *testing.T) {
cases := []struct {
name string
- maintenance *GettablePlannedMaintenance
+ maintenance *PlannedMaintenance
ts time.Time
skip bool
}{
{
name: "only-on-saturday",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "Europe/London",
Recurrence: &Recurrence{
@@ -39,7 +39,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Testing weekly recurrence with midnight crossing
{
name: "weekly-across-midnight-previous-day",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -56,7 +56,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Testing weekly recurrence with midnight crossing
{
name: "weekly-across-midnight-previous-day",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -73,7 +73,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Testing weekly recurrence with multi day duration
{
name: "weekly-across-midnight-previous-day",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -90,7 +90,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Weekly recurrence where the previous day is not in RepeatOn
{
name: "weekly-across-midnight-previous-day-not-in-repeaton",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -107,7 +107,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Daily recurrence with midnight crossing
{
name: "daily-maintenance-across-midnight",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -123,7 +123,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Exactly at start time boundary
{
name: "at-start-time-boundary",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -139,7 +139,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Exactly at end time boundary
{
name: "at-end-time-boundary",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -155,7 +155,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Monthly maintenance with multi-day duration
{
name: "monthly-multi-day-duration",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -171,7 +171,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Weekly maintenance with multi-day duration
{
name: "weekly-multi-day-duration",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -188,7 +188,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Monthly maintenance that crosses to next month
{
name: "monthly-crosses-to-next-month",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -204,7 +204,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Different timezone tests
{
name: "timezone-offset-test",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "America/New_York", // UTC-5 or UTC-4 depending on DST
Recurrence: &Recurrence{
@@ -220,7 +220,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Test negative case - time well outside window
{
name: "daily-maintenance-time-outside-window",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -236,7 +236,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Test for recurring maintenance with an end date that is before the current time
{
name: "recurring-maintenance-with-past-end-date",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -253,7 +253,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Monthly recurring maintenance spanning end of month into beginning of next month
{
name: "monthly-maintenance-spans-month-end",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -269,7 +269,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// Test for RepeatOn with empty array (should apply to all days)
{
name: "weekly-empty-repeaton",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -286,7 +286,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
// February has fewer days than January - test the edge case when maintenance is on 31st
{
name: "monthly-maintenance-february-fewer-days",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -301,7 +301,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "daily-maintenance-crosses-midnight",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -316,7 +316,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "monthly-maintenance-crosses-month-end",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -331,7 +331,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "monthly-maintenance-crosses-month-end-and-duration-is-2-days",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -346,7 +346,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "weekly-maintenance-crosses-midnight",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -362,7 +362,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "monthly-maintenance-crosses-month-end-and-duration-is-2-days",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -377,7 +377,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "daily-maintenance-crosses-midnight",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -392,7 +392,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "monthly-maintenance-crosses-month-end-and-duration-is-2-hours",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -407,7 +407,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "fixed planned maintenance start <= ts <= end",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
StartTime: time.Now().UTC().Add(-time.Hour),
@@ -419,7 +419,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "fixed planned maintenance start >= ts",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
StartTime: time.Now().UTC().Add(time.Hour),
@@ -431,7 +431,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "fixed planned maintenance ts < start",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
StartTime: time.Now().UTC().Add(time.Hour),
@@ -443,7 +443,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat sunday, saturday, weekly for 24 hours, in Us/Eastern timezone",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "US/Eastern",
Recurrence: &Recurrence{
@@ -459,7 +459,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat daily from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -474,7 +474,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat daily from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -489,7 +489,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat daily from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -504,7 +504,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat weekly on monday from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -520,7 +520,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat weekly on monday from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -536,7 +536,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat weekly on monday from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -552,7 +552,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat weekly on monday from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -568,7 +568,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat weekly on monday from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -584,7 +584,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat monthly on 4th from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -599,7 +599,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat monthly on 4th from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
@@ -614,7 +614,7 @@ func TestShouldSkipMaintenance(t *testing.T) {
},
{
name: "recurring maintenance, repeat monthly on 4th from 12:00 to 14:00",
- maintenance: &GettablePlannedMaintenance{
+ maintenance: &PlannedMaintenance{
Schedule: &Schedule{
Timezone: "UTC",
Recurrence: &Recurrence{
diff --git a/pkg/types/ruletypes/recurrence.go b/pkg/types/ruletypes/recurrence.go
index 4ec65ae8f5..5becae1dcf 100644
--- a/pkg/types/ruletypes/recurrence.go
+++ b/pkg/types/ruletypes/recurrence.go
@@ -8,26 +8,52 @@ import (
"github.com/SigNoz/signoz/pkg/valuer"
)
-type RepeatType string
+type RepeatType struct {
+ valuer.String
+}
-const (
- RepeatTypeDaily RepeatType = "daily"
- RepeatTypeWeekly RepeatType = "weekly"
- RepeatTypeMonthly RepeatType = "monthly"
+var (
+ RepeatTypeDaily = RepeatType{valuer.NewString("daily")}
+ RepeatTypeWeekly = RepeatType{valuer.NewString("weekly")}
+ RepeatTypeMonthly = RepeatType{valuer.NewString("monthly")}
)
-type RepeatOn string
+// Enum implements jsonschema.Enum; returns the acceptable values for RepeatType.
+func (RepeatType) Enum() []any {
+ return []any{
+ RepeatTypeDaily,
+ RepeatTypeWeekly,
+ RepeatTypeMonthly,
+ }
+}
+
+type RepeatOn struct {
+ valuer.String
+}
-const (
- RepeatOnSunday RepeatOn = "sunday"
- RepeatOnMonday RepeatOn = "monday"
- RepeatOnTuesday RepeatOn = "tuesday"
- RepeatOnWednesday RepeatOn = "wednesday"
- RepeatOnThursday RepeatOn = "thursday"
- RepeatOnFriday RepeatOn = "friday"
- RepeatOnSaturday RepeatOn = "saturday"
+var (
+ RepeatOnSunday = RepeatOn{valuer.NewString("sunday")}
+ RepeatOnMonday = RepeatOn{valuer.NewString("monday")}
+ RepeatOnTuesday = RepeatOn{valuer.NewString("tuesday")}
+ RepeatOnWednesday = RepeatOn{valuer.NewString("wednesday")}
+ RepeatOnThursday = RepeatOn{valuer.NewString("thursday")}
+ RepeatOnFriday = RepeatOn{valuer.NewString("friday")}
+ RepeatOnSaturday = RepeatOn{valuer.NewString("saturday")}
)
+// Enum implements jsonschema.Enum; returns the acceptable values for RepeatOn.
+func (RepeatOn) Enum() []any {
+ return []any{
+ RepeatOnSunday,
+ RepeatOnMonday,
+ RepeatOnTuesday,
+ RepeatOnWednesday,
+ RepeatOnThursday,
+ RepeatOnFriday,
+ RepeatOnSaturday,
+ }
+}
+
var RepeatOnAllMap = map[RepeatOn]time.Weekday{
RepeatOnSunday: time.Sunday,
RepeatOnMonday: time.Monday,
@@ -39,10 +65,10 @@ var RepeatOnAllMap = map[RepeatOn]time.Weekday{
}
type Recurrence struct {
- StartTime time.Time `json:"startTime"`
+ StartTime time.Time `json:"startTime" required:"true"`
EndTime *time.Time `json:"endTime,omitempty"`
- Duration valuer.TextDuration `json:"duration"`
- RepeatType RepeatType `json:"repeatType"`
+ Duration valuer.TextDuration `json:"duration" required:"true"`
+ RepeatType RepeatType `json:"repeatType" required:"true"`
RepeatOn []RepeatOn `json:"repeatOn"`
}