Skip to content

fix(uptime): Allow strings in config thresholds#104706

Merged
evanpurkhiser merged 1 commit intomasterfrom
evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds
Dec 12, 2025
Merged

fix(uptime): Allow strings in config thresholds#104706
evanpurkhiser merged 1 commit intomasterfrom
evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds

Conversation

@evanpurkhiser
Copy link
Copy Markdown
Member

@evanpurkhiser evanpurkhiser commented Dec 10, 2025

Fixes NEW-664: Fix setting failure threshold in uptime detector creation

Adds a DRF validator for the config field, replacing the generic JSONField. This addresses a few problems

  • The DRF validator will handle coercing strings to numbers (for fields like failureThreshold and recoveryThreshold. Without the DRF validator the JSON Schema simply rejects numbers as strings, which is how our frontend forms send data.

  • Previously validation errors of the config were reported under the config key. But since many fields on the frontend may map to the config, there's no simple way to display config errors on their associated fields. With the DRF serializer we're able to correctly report errors tied back to specific fields (see the updated tests)

@evanpurkhiser evanpurkhiser requested a review from a team as a code owner December 10, 2025 20:06
@linear
Copy link
Copy Markdown

linear bot commented Dec 10, 2025

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 10, 2025
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds branch from 6211ae2 to 311d266 Compare December 10, 2025 22:07
@evanpurkhiser evanpurkhiser requested a review from a team as a code owner December 10, 2025 22:07
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds branch from 311d266 to 53215e3 Compare December 10, 2025 22:10
@evanpurkhiser evanpurkhiser enabled auto-merge (squash) December 10, 2025 22:13
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds branch from 53215e3 to 5b3b5a7 Compare December 11, 2025 21:05
@getsentry getsentry deleted a comment from codecov bot Dec 11, 2025
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds branch from 5b3b5a7 to 55f6954 Compare December 11, 2025 22:41
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds branch from 55f6954 to 29d1339 Compare December 12, 2025 15:53
Comment on lines +531 to +541
elif (
mode_in_request
and requested_mode != current_mode
and requested_mode != UptimeMonitorMode.MANUAL
and not is_superuser
):
raise serializers.ValidationError({"mode": ["Only superusers can modify `mode`"]})
else:
# On create, non-superusers can only set MANUAL mode
if "mode" in attrs and attrs["mode"] != UptimeMonitorMode.MANUAL and not is_superuser:
raise serializers.ValidationError({"mode": ["Only superusers can modify `mode`"]})

This comment was marked as outdated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was correct. Fixed now

Copy link
Copy Markdown
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems 👍 to me from the detector platform perspective; i'm not sure about the details involved so probably good to have dan give it the final +1.

class UptimeDomainCheckFailureValidator(BaseDetectorTypeValidator):
enforce_single_datasource = True
data_sources = serializers.ListField(child=UptimeMonitorDataSourceValidator(), required=False)
config = UptimeDomainCheckFailureConfigValidator(required=False) # type: ignore[assignment]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any thoughts on how we might be able to have a similar abstraction enforced through the base detector? my guess is that most detectors will have the not great error handling for the json config field.

it'd also be cool if we updated the base detector to allow for this kind of override without having to add a lint exception. 🤔


anywho, no action needed for this pr, just curious to get your take.

@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds branch from 29d1339 to 7f3a110 Compare December 12, 2025 18:07
@evanpurkhiser evanpurkhiser merged commit a45ac4f into master Dec 12, 2025
67 checks passed
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/fix-uptime-allow-strings-in-config-thresholds branch December 12, 2025 19:05
@github-actions github-actions bot locked and limited conversation to collaborators Dec 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants