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(logs): allow 0 as threshold count for log alerts (#60445)

Jon McCallum0677aeda419c
diff --git a/products/logs/backend/alerts_api.py b/products/logs/backend/alerts_api.py
index 375507ed4a50..c16aa20aa54a 100644
--- a/products/logs/backend/alerts_api.py
+++ b/products/logs/backend/alerts_api.py
@@ -154,9 +154,9 @@ class LogsAlertConfigurationSerializer(serializers.ModelSerializer):
"or filterGroup (property filter group object). May be empty on draft alerts (enabled=false).",
)
threshold_count = serializers.IntegerField(
- min_value=1,
+ min_value=0,
default=100,
- help_text="Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.",
+ help_text="Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log.",
)
first_enabled_at = serializers.DateTimeField(
read_only=True,
@@ -580,7 +580,7 @@ class LogsAlertSimulateBucketSerializer(serializers.Serializer):
class LogsAlertSimulateRequestSerializer(serializers.Serializer):
filters = LogsAlertFiltersField(help_text="Filter criteria — same format as LogsAlertConfiguration.filters.")
threshold_count = serializers.IntegerField(
- min_value=1,
+ min_value=0,
help_text="Threshold count to evaluate against.",
)
threshold_operator = serializers.ChoiceField(
diff --git a/products/logs/backend/migrations/0013_alter_logsalertconfiguration_threshold_count.py b/products/logs/backend/migrations/0013_alter_logsalertconfiguration_threshold_count.py
new file mode 100644
index 000000000000..3de263564798
--- /dev/null
+++ b/products/logs/backend/migrations/0013_alter_logsalertconfiguration_threshold_count.py
@@ -0,0 +1,17 @@
+# Generated by Django 5.2.13 on 2026-05-28 14:30
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("logs", "0012_alter_logsalertevent_kind"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="logsalertconfiguration",
+ name="threshold_count",
+ field=models.PositiveIntegerField(default=100),
+ ),
+ ]
diff --git a/products/logs/backend/migrations/max_migration.txt b/products/logs/backend/migrations/max_migration.txt
index a0a073983d26..bbb022ee1172 100644
--- a/products/logs/backend/migrations/max_migration.txt
+++ b/products/logs/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0012_alter_logsalertevent_kind
+0013_alter_logsalertconfiguration_threshold_count
diff --git a/products/logs/backend/models.py b/products/logs/backend/models.py
index 7e42a665dd3f..cb606d9ac346 100644
--- a/products/logs/backend/models.py
+++ b/products/logs/backend/models.py
@@ -4,7 +4,6 @@ from datetime import UTC, datetime, timedelta
from typing import TYPE_CHECKING
from django.core.exceptions import ValidationError
-from django.core.validators import MinValueValidator
from django.db import models
from posthog.models.activity_logging.model_activity import ModelActivityMixin
@@ -66,7 +65,7 @@ class LogsAlertConfiguration(ModelActivityMixin, CreatedMetaFields, UpdatedMetaF
filters = models.JSONField(default=dict)
# Threshold
- threshold_count = models.PositiveIntegerField(validators=[MinValueValidator(1)], default=100)
+ threshold_count = models.PositiveIntegerField(default=100)
threshold_operator = models.CharField(
max_length=10,
choices=ThresholdOperator,
diff --git a/products/logs/frontend/components/LogsAlerting/LogsAlertForm.tsx b/products/logs/frontend/components/LogsAlerting/LogsAlertForm.tsx
index 516e3376640b..c2d179a9cab7 100644
--- a/products/logs/frontend/components/LogsAlerting/LogsAlertForm.tsx
+++ b/products/logs/frontend/components/LogsAlerting/LogsAlertForm.tsx
@@ -146,9 +146,9 @@ export function LogsAlertForm(): JSX.Element {
/>
<LemonInput
type="number"
- min={1}
+ min={0}
value={alertForm.thresholdCount}
- onChange={(val) => setAlertFormValue('thresholdCount', val ?? 1)}
+ onChange={(val) => setAlertFormValue('thresholdCount', val ?? 0)}
className="w-24"
size="small"
data-attr="logs-alert-threshold-count"
diff --git a/products/logs/frontend/generated/api.schemas.ts b/products/logs/frontend/generated/api.schemas.ts
index 731e6acee54a..2f1c16c9cf27 100644
--- a/products/logs/frontend/generated/api.schemas.ts
+++ b/products/logs/frontend/generated/api.schemas.ts
@@ -488,8 +488,8 @@ export interface LogsAlertConfigurationApi {
/** Filter criteria — subset of LogsViewerFilters. Must contain at least one of: severityLevels (list of severity strings), serviceNames (list of service name strings), or filterGroup (property filter group object). May be empty on draft alerts (enabled=false). */
filters?: LogsAlertFiltersApi
/**
- * Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.
- * @minimum 1
+ * Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log.
+ * @minimum 0
*/
threshold_count?: number
/** Whether the alert fires when the count is above or below the threshold.
@@ -595,8 +595,8 @@ export interface PatchedLogsAlertConfigurationApi {
/** Filter criteria — subset of LogsViewerFilters. Must contain at least one of: severityLevels (list of severity strings), serviceNames (list of service name strings), or filterGroup (property filter group object). May be empty on draft alerts (enabled=false). */
filters?: LogsAlertFiltersApi
/**
- * Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.
- * @minimum 1
+ * Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log.
+ * @minimum 0
*/
threshold_count?: number
/** Whether the alert fires when the count is above or below the threshold.
@@ -760,7 +760,7 @@ export interface LogsAlertSimulateRequestApi {
filters: LogsAlertFiltersApi
/**
* Threshold count to evaluate against.
- * @minimum 1
+ * @minimum 0
*/
threshold_count: number
/** Whether the alert fires when the count is above or below the threshold.
diff --git a/products/logs/frontend/generated/api.zod.ts b/products/logs/frontend/generated/api.zod.ts
index 0c36981ec2b9..a2dc034eb4d6 100644
--- a/products/logs/frontend/generated/api.zod.ts
+++ b/products/logs/frontend/generated/api.zod.ts
@@ -69,6 +69,7 @@ export const logsAlertsCreateBodyNameMax = 255
export const logsAlertsCreateBodyEnabledDefault = true
export const logsAlertsCreateBodyThresholdCountDefault = 100
+export const logsAlertsCreateBodyThresholdCountMin = 0
export const logsAlertsCreateBodyThresholdOperatorDefault = `above`
export const logsAlertsCreateBodyWindowMinutesDefault = 5
@@ -124,10 +125,10 @@ export const LogsAlertsCreateBody = /* @__PURE__ */ zod.object({
),
threshold_count: zod
.number()
- .min(1)
+ .min(logsAlertsCreateBodyThresholdCountMin)
.default(logsAlertsCreateBodyThresholdCountDefault)
.describe(
- 'Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.'
+ "Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log."
),
threshold_operator: zod
.enum(['above', 'below'])
@@ -168,6 +169,7 @@ export const logsAlertsUpdateBodyNameMax = 255
export const logsAlertsUpdateBodyEnabledDefault = true
export const logsAlertsUpdateBodyThresholdCountDefault = 100
+export const logsAlertsUpdateBodyThresholdCountMin = 0
export const logsAlertsUpdateBodyThresholdOperatorDefault = `above`
export const logsAlertsUpdateBodyWindowMinutesDefault = 5
@@ -223,10 +225,10 @@ export const LogsAlertsUpdateBody = /* @__PURE__ */ zod.object({
),
threshold_count: zod
.number()
- .min(1)
+ .min(logsAlertsUpdateBodyThresholdCountMin)
.default(logsAlertsUpdateBodyThresholdCountDefault)
.describe(
- 'Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.'
+ "Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log."
),
threshold_operator: zod
.enum(['above', 'below'])
@@ -267,6 +269,7 @@ export const logsAlertsPartialUpdateBodyNameMax = 255
export const logsAlertsPartialUpdateBodyEnabledDefault = true
export const logsAlertsPartialUpdateBodyThresholdCountDefault = 100
+export const logsAlertsPartialUpdateBodyThresholdCountMin = 0
export const logsAlertsPartialUpdateBodyThresholdOperatorDefault = `above`
export const logsAlertsPartialUpdateBodyWindowMinutesDefault = 5
@@ -322,10 +325,10 @@ export const LogsAlertsPartialUpdateBody = /* @__PURE__ */ zod.object({
),
threshold_count: zod
.number()
- .min(1)
+ .min(logsAlertsPartialUpdateBodyThresholdCountMin)
.default(logsAlertsPartialUpdateBodyThresholdCountDefault)
.describe(
- 'Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.'
+ "Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log."
),
threshold_operator: zod
.enum(['above', 'below'])
@@ -393,6 +396,8 @@ export const LogsAlertsDestinationsDeleteCreateBody = /* @__PURE__ */ zod.object
* Simulate a logs alert on historical data using the full state machine. Read-only — no alert check records are created.
*/
+export const logsAlertsSimulateCreateBodyThresholdCountMin = 0
+
export const logsAlertsSimulateCreateBodyCheckIntervalMinutesDefault = 5
export const logsAlertsSimulateCreateBodyCheckIntervalMinutesMax = 60
@@ -434,7 +439,10 @@ export const LogsAlertsSimulateCreateBody = /* @__PURE__ */ zod.object({
.default(null),
})
.describe('Filter criteria — same format as LogsAlertConfiguration.filters.'),
- threshold_count: zod.number().min(1).describe('Threshold count to evaluate against.'),
+ threshold_count: zod
+ .number()
+ .min(logsAlertsSimulateCreateBodyThresholdCountMin)
+ .describe('Threshold count to evaluate against.'),
threshold_operator: zod
.enum(['above', 'below'])
.describe('\* `above` - Above\n\* `below` - Below')
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index fe4121569d47..e0589503e2fa 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -20960,8 +20960,8 @@ export namespace Schemas {
/** Filter criteria — subset of LogsViewerFilters. Must contain at least one of: severityLevels (list of severity strings), serviceNames (list of service name strings), or filterGroup (property filter group object). May be empty on draft alerts (enabled=false). */
filters?: LogsAlertFilters;
/**
- * Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.
- * @minimum 1
+ * Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log.
+ * @minimum 0
*/
threshold_count?: number;
/** Whether the alert fires when the count is above or below the threshold.
@@ -21132,7 +21132,7 @@ export namespace Schemas {
filters: LogsAlertFilters;
/**
* Threshold count to evaluate against.
- * @minimum 1
+ * @minimum 0
*/
threshold_count: number;
/** Whether the alert fires when the count is above or below the threshold.
@@ -29053,8 +29053,8 @@ export namespace Schemas {
/** Filter criteria — subset of LogsViewerFilters. Must contain at least one of: severityLevels (list of severity strings), serviceNames (list of service name strings), or filterGroup (property filter group object). May be empty on draft alerts (enabled=false). */
filters?: LogsAlertFilters;
/**
- * Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.
- * @minimum 1
+ * Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log.
+ * @minimum 0
*/
threshold_count?: number;
/** Whether the alert fires when the count is above or below the threshold.
diff --git a/services/mcp/src/generated/logs/api.ts b/services/mcp/src/generated/logs/api.ts
index eadf822ba2c3..d7e37d7d8eb1 100644
--- a/services/mcp/src/generated/logs/api.ts
+++ b/services/mcp/src/generated/logs/api.ts
@@ -97,6 +97,7 @@ export const logsAlertsCreateBodyFiltersOneFilterGroupDefault = null
export const logsAlertsCreateBodyFiltersOneServiceNamesDefault = null
export const logsAlertsCreateBodyFiltersOneSeverityLevelsDefault = null
export const logsAlertsCreateBodyThresholdCountDefault = 100
+export const logsAlertsCreateBodyThresholdCountMin = 0
export const logsAlertsCreateBodyThresholdOperatorDefault = `above`
export const logsAlertsCreateBodyWindowMinutesDefault = 5
@@ -1249,10 +1250,10 @@ export const LogsAlertsCreateBody = /* @__PURE__ */ zod.object({
),
threshold_count: zod
.number()
- .min(1)
+ .min(logsAlertsCreateBodyThresholdCountMin)
.default(logsAlertsCreateBodyThresholdCountDefault)
.describe(
- 'Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.'
+ "Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log."
),
threshold_operator: zod
.enum(['above', 'below'])
@@ -1372,6 +1373,8 @@ export const logsAlertsPartialUpdateBodyFiltersOneFilterGroupOneValuesItemValues
export const logsAlertsPartialUpdateBodyFiltersOneFilterGroupDefault = null
export const logsAlertsPartialUpdateBodyFiltersOneServiceNamesDefault = null
export const logsAlertsPartialUpdateBodyFiltersOneSeverityLevelsDefault = null
+export const logsAlertsPartialUpdateBodyThresholdCountMin = 0
+
export const logsAlertsPartialUpdateBodyEvaluationPeriodsMax = 10
export const logsAlertsPartialUpdateBodyDatapointsToAlarmMax = 10
@@ -2518,10 +2521,10 @@ export const LogsAlertsPartialUpdateBody = /* @__PURE__ */ zod.object({
),
threshold_count: zod
.number()
- .min(1)
+ .min(logsAlertsPartialUpdateBodyThresholdCountMin)
.optional()
.describe(
- 'Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100.'
+ "Number of matching log entries that constitutes a threshold breach within the evaluation window. Defaults to 100. Use 0 with the 'above' operator to fire on any matching log."
),
threshold_operator: zod
.enum(['above', 'below'])
@@ -2703,6 +2706,8 @@ export const logsAlertsSimulateCreateBodyFiltersOneFilterGroupOneValuesItemValue
export const logsAlertsSimulateCreateBodyFiltersOneFilterGroupDefault = null
export const logsAlertsSimulateCreateBodyFiltersOneServiceNamesDefault = null
export const logsAlertsSimulateCreateBodyFiltersOneSeverityLevelsDefault = null
+export const logsAlertsSimulateCreateBodyThresholdCountMin = 0
+
export const logsAlertsSimulateCreateBodyCheckIntervalMinutesDefault = 5
export const logsAlertsSimulateCreateBodyCheckIntervalMinutesMax = 60
@@ -3841,7 +3846,10 @@ export const LogsAlertsSimulateCreateBody = /* @__PURE__ */ zod.object({
.default(logsAlertsSimulateCreateBodyFiltersOneSeverityLevelsDefault),
})
.describe('Filter criteria — same format as LogsAlertConfiguration.filters.'),
- threshold_count: zod.number().min(1).describe('Threshold count to evaluate against.'),
+ threshold_count: zod
+ .number()
+ .min(logsAlertsSimulateCreateBodyThresholdCountMin)
+ .describe('Threshold count to evaluate against.'),
threshold_operator: zod
.enum(['above', 'below'])
.describe('* `above` - Above\n* `below` - Below')