import {z} from 'zod' export type GetApiApiV1ConfigConsumptionBudgetsSlugArgs = {slug: string}; export type GetApiApiV1ConfigConsumptionBudgetsSlugOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const consumptionBudgetAlertActionConfig = z.object({annotations: z.record(z.string(), z.string()).optional(), instant_rate_sustain_secs: z.number().int().optional(), labels: z.record(z.string(), z.string()).optional()}); export const configv1LogSearchFilter = z.object({query: z.string().optional()}); export const consumptionBudgetPriorityFilter = z.object({dataset_slug: z.string().optional(), log_filter: configv1LogSearchFilter.optional()}); export const consumptionBudgetPriority = z.object({filters: z.array(consumptionBudgetPriorityFilter), priority: z.number().int()}); export const consumptionBudgetResourceGroup = z.enum(["LOG_PERSISTED_BYTES", "LOG_PROCESSED_BYTES", "METRIC_PERSISTED_SERIES", "METRIC_ALL", "LOG_ALL", "TRACE_PROCESSED_BYTES", "TRACE_PERSISTED_BYTES", "TRACE_ALL", "ALL"]); export const consumptionBudgetThresholdAction = z.enum(["ALERT_WARN", "ALERT_CRITICAL", "DROP"]); export const thresholdInstantRate = z.object({fixed_value_per_sec: z.string()}); export const consumptionBudgetThresholdType = z.enum(["DAILY_VOLUME", "INSTANT_RATE", "WEEKLY_VOLUME", "MONTHLY_VOLUME", "HOURLY_VOLUME", "ROLLING_1_HOUR_VOLUME", "ROLLING_3_HOUR_VOLUME", "ROLLING_1_DAY_VOLUME", "ROLLING_7_DAY_VOLUME", "ROLLING_30_MINUTE_VOLUME"]); export const consumptionBudgetUnit = z.enum(["NATIVE", "CREDITS"]); export const thresholdVolume = z.object({fixed_value: z.string()}); export const configv1ConsumptionBudgetThreshold = z.object({action: consumptionBudgetThresholdAction, instant_rate: thresholdInstantRate.optional(), resource_group: consumptionBudgetResourceGroup.optional(), type: consumptionBudgetThresholdType, unit: consumptionBudgetUnit.optional(), volume: thresholdVolume.optional()}); export const configv1ConsumptionBudget = z.object({alert_action_config: consumptionBudgetAlertActionConfig.optional(), created_at: z.string().optional(), default_priority: z.number().int().optional(), name: z.string(), notification_policy_slug: z.string().optional(), partition_slug_path: z.string(), priorities: z.array(consumptionBudgetPriority).optional(), resource: consumptionBudgetResourceGroup.optional(), slug: z.string().optional(), thresholds: z.array(configv1ConsumptionBudgetThreshold).optional(), updated_at: z.string().optional()}); export const configv1ReadConsumptionBudgetResponse = z.object({consumption_budget: configv1ConsumptionBudget.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * GET /api/v1/config/consumption-budgets/{slug} */ export const getApiApiV1ConfigConsumptionBudgetsSlug = async (args: GetApiApiV1ConfigConsumptionBudgetsSlugArgs, options?: GetApiApiV1ConfigConsumptionBudgetsSlugOptions) => { const {baseUrl = "https://tenant.chronosphere.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/consumption-budgets/${encodeURIComponent(String(args.slug))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(configv1ReadConsumptionBudgetResponse, await res.json()) };