Skip to content

Conversation

@abishanan-shopify
Copy link
Contributor

@abishanan-shopify abishanan-shopify commented Jun 16, 2025

Addressing this issue: #633

Changes

Created ConfigurationValidator class that handles all validations and constraints for the following Semian config values:

  • name: Must be string / symbol and cannot be a duplicate Semian name of one that exists in Semian.resources
  • :circuit_breaker & :bulkhead: Cannot both be disabled
  • :tickets & :quota: If bulkhead, can only have :tickets or :quota, cannot be both
    • :tickets: Must be between 0 and Semian::MAX_TICKETS, inclusive
    • :quota: Must be a ratio between 0 and 1, inclusive
  • :success_threshold, :error_threshold & :error_timeout: If circuit breaker, validate that these required params exist.
  • :success_threshold & :error_threshold: If circuit breaker, validate that they are positive numbers
  • :error_timeout, :error_threshold_timeout, :half_open_resource_timeout, :lumping_interval: If circuit breaker and exists, validate that they are non-negative.

We have also added constraints to the timeout values to ensure that Semians don't end up in weird scenarios (never opens, closes, never half-opens, etc.):

  • lumping_interval * (error_threshold - 1) <= error_threshold_timeout

We also added a new flag - force_config_validation to pass as an argument to Semian to force configuration validation at runtime if desired (otherwise it will be logged verbosely in I/O)

Finally, we added test cases to address each of the above constraints, and modified non-validation related test cases to conform to ConfigurationValidator class.

Rationale

We are looking to add validations to configuration options on Semians, to ensure that invalid or otherwise impossible Semian configuration are not created (result in an Exception raised) and do not persist in production. This will help alleviate any cases of incidents or investigations where Semians do not open due to impossible conditions.

Why are some validations required and others are not?

This is to avoid regression in our previous validation logic -- we want to make sure that we don't unexpectedly crash developers' Semians, but we don't allow things that we have previously disallowed.

This includes:

  • Requiring success_threshold, error_threshold, and error_timeout to be required in circuit breakers
  • Requiring either tickets or quota to be required in bulkheads
  • Making sure tickets are within bounds (0, MAX_TICKETS] (tickets != MAX_TICKETS was not previously enforced so we use flag instead)
  • Making sure quota is within bounds (0, 1] (quota != 1 was not previously enforced so we use the flag instead)

@abishanan-shopify abishanan-shopify self-assigned this Jun 16, 2025
@abishanan-shopify abishanan-shopify force-pushed the semian-config-validation branch 7 times, most recently from 55eea74 to ffd990c Compare June 17, 2025 16:01
@abishanan-shopify abishanan-shopify force-pushed the semian-config-validation branch 13 times, most recently from 9f81ac5 to 98383d1 Compare June 18, 2025 14:47
@abishanan-shopify abishanan-shopify marked this pull request as ready for review June 18, 2025 15:12
@abishanan-shopify abishanan-shopify force-pushed the semian-config-validation branch 4 times, most recently from 5a21caa to 4b9daca Compare June 23, 2025 15:31
@abishanan-shopify abishanan-shopify force-pushed the semian-config-validation branch from d947b5a to c821272 Compare July 29, 2025 20:46
error_threshold_timeout contradiction validation
+ rubocop
@abishanan-shopify abishanan-shopify force-pushed the semian-config-validation branch 2 times, most recently from a238fe2 to 1787285 Compare July 29, 2025 21:12
@AbdulRahmanAlHamali AbdulRahmanAlHamali force-pushed the semian-config-validation branch 3 times, most recently from 6d454cc to c3d6143 Compare August 7, 2025 15:36
@AbdulRahmanAlHamali
Copy link
Contributor

Note: CI on this PR (and others) have been failing because example.com has been acting funkily. We switched all usages to shopify.com instead.

(Ideally we would put these changes in a separate PR, but they are sufficiently trivial)

@iandelahorne
Copy link
Contributor

iandelahorne commented Aug 7, 2025

edit: my previous comment was in error, but this should likely be a minor version bump when we release it

Copy link
Contributor

@iandelahorne iandelahorne left a comment

Choose a reason for hiding this comment

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

Looks good, excited to see this in production later

@abishanan-shopify abishanan-shopify merged commit d3dd83e into main Aug 14, 2025
32 checks passed
@abishanan-shopify abishanan-shopify deleted the semian-config-validation branch August 14, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants