Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(alerts): seed schema defaults into alert wizard payloads (#75222)

Aleksander Błaszkiewiczd6d68ca6e474
diff --git a/frontend/src/lib/components/Alerting/AlertWizard/alertWizardLogic.ts b/frontend/src/lib/components/Alerting/AlertWizard/alertWizardLogic.ts
index 97f2c3cf613b..e812ee2ddd45 100644
--- a/frontend/src/lib/components/Alerting/AlertWizard/alertWizardLogic.ts
+++ b/frontend/src/lib/components/Alerting/AlertWizard/alertWizardLogic.ts
@@ -164,6 +164,20 @@ export function decorateAlertName(baseName: string, selectedKinds: string[] | nu
return `${baseName}${formatKindsSuffix(selectedKinds)}`
}
+function buildAlertInputs(
+ template: HogFunctionTemplateType,
+ subTemplateInputs: Record<string, CyclotronJobInputType> | null | undefined,
+ inputValues: Record<string, CyclotronJobInputType>
+): Record<string, CyclotronJobInputType> {
+ const inputs: Record<string, CyclotronJobInputType> = {}
+ for (const schema of template.inputs_schema ?? []) {
+ if (schema.default !== undefined) {
+ inputs[schema.key] = { value: schema.default }
+ }
+ }
+ return { ...inputs, ...subTemplateInputs, ...inputValues }
+}
+
function extractDestinationKeyFromAlert(alert: HogFunctionType, allDestinations: WizardDestination[]): string | null {
const templateId = alert.template?.id
if (!templateId) {
@@ -664,11 +678,6 @@ export const alertWizardLogic = kea<alertWizardLogicType>([
return
}
- const mergedInputs: Record<string, any> = { ...subTemplate.inputs }
- for (const [key, val] of Object.entries(values.inputValues)) {
- mergedInputs[key] = val
- }
-
const selectedTemplate = values.selectedTemplate
if (!selectedTemplate) {
lemonToast.error('Template not loaded yet')
@@ -676,6 +685,8 @@ export const alertWizardLogic = kea<alertWizardLogicType>([
return
}
+ const mergedInputs = buildAlertInputs(selectedTemplate, subTemplate.inputs, values.inputValues)
+
const configuration: Record<string, any> = {
type: 'internal_destination',
template_id: destination.templateId,
@@ -754,11 +765,14 @@ export const alertWizardLogic = kea<alertWizardLogicType>([
return
}
- const mergedInputs: Record<string, any> = { ...subTemplate.inputs }
- for (const [key, val] of Object.entries(values.inputValues)) {
- mergedInputs[key] = val
+ const selectedTemplate = values.selectedTemplate
+ if (!selectedTemplate) {
+ lemonToast.error('Template not loaded yet')
+ return
}
+ const mergedInputs = buildAlertInputs(selectedTemplate, subTemplate.inputs, values.inputValues)
+
const filters = applyKindFilter(subTemplate.filters, values.selectedKinds)
const name = decorateAlertName(subTemplate.name ?? '', values.selectedKinds)
const description = decorateAlertName(subTemplate.description ?? '', values.selectedKinds)