Skip to content

[FSSDK-11459] Ruby - Add SDK Multi-Region Support for Data Hosting #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

esrakartalOpt
Copy link
Contributor

Summary

  • Add Multi-Region Support for Data Hosting

Test plan

  • Created and added new test cases

Issues

@esrakartalOpt esrakartalOpt marked this pull request as ready for review June 30, 2025 15:59
@esrakartalOpt esrakartalOpt requested a review from Copilot June 30, 2025 16:10
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds multi-region support for data hosting by introducing a region attribute across the SDK, selecting region-specific event endpoints, and updating tests accordingly.

  • Introduce region in DatafileProjectConfig with default 'US'
  • Update EventBuilder and EventFactory to choose endpoints from a frozen ENDPOINTS map keyed by region
  • Add or update test cases to include region in parameters and expect region-specific URLs

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spec/spec_params.rb Add default 'region' key to valid config body
spec/project_spec.rb Include region: 'US' in expected event parameters
spec/optimizely_user_context_spec.rb Add region to expected impression payload
spec/event_builder_spec.rb Introduce @expected_endpoints hash and US region
spec/event/user_event_factory_spec.rb Assert event_context[:region] equals config region
spec/event/forwarding_event_processor_spec.rb Include region: 'US' in forwarding payload
spec/event/event_factory_spec.rb Introduce @expected_endpoints and US region
spec/event/event_entities_spec.rb Include region: 'US' in entity JSON
spec/config/datafile_project_config_spec.rb Add tests for default and specified region
lib/optimizely/project_config.rb Stubbed def region added
lib/optimizely/event_builder.rb Add region param to common params and endpoints
lib/optimizely/event/user_event_factory.rb Pass region into EventContext
lib/optimizely/event/event_factory.rb Add region-based endpoints in log event creation
lib/optimizely/event/entity/event_context.rb Store and serialize region field
lib/optimizely/event/entity/event_batch.rb Track and default region in batch builder
lib/optimizely/config/datafile_project_config.rb Parse and default region on initialization
Comments suppressed due to low confidence (3)

spec/config/datafile_project_config_spec.rb:771

  • [nitpick] The test uses both config_body_JSON and config_body_json for JSON payloads. Consider unifying the variable naming style for consistency.
      config_body_json = JSON.dump(config_body_eu)

spec/event_builder_spec.rb:42

  • You’ve defined EU endpoints in the test fixture but only assert US behavior. Add test cases to cover the EU region selection path.
    @expected_endpoints = {

spec/event/event_factory_spec.rb:37

  • The fixture includes EU endpoints, but there’s no assertion for EU region. Add tests to verify that EventFactory picks the EU URL when region: 'EU'.
    @expected_endpoints = {

@@ -62,6 +62,8 @@ def host_for_odp; end

def all_segments; end

def region; end
Copy link
Preview

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

The region method is currently a stub and returns nothing. It should return the instance variable, e.g., def region; @region; end.

Copilot uses AI. Check for mistakes.

event_params = get_common_params(project_config, user_id, attributes)
impression_params = get_impression_params(project_config, experiment, variation_id)
event_params[:visitors][0][:snapshots].push(impression_params)

Event.new(:post, ENDPOINT, event_params, POST_HEADERS)
endpoint = ENDPOINTS[region.to_sym]
Copy link
Preview

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

Converting region directly to a symbol may fail if the string is lowercase. Normalize the key, e.g., region.to_s.upcase.to_sym to ensure a match in ENDPOINTS.

Suggested change
endpoint = ENDPOINTS[region.to_sym]
endpoint = ENDPOINTS[region.to_s.upcase.to_sym]

Copilot uses AI. Check for mistakes.


builder.with_visitors(visitors)
event_batch = builder.build
Event.new(:post, ENDPOINT, event_batch.as_json, POST_HEADERS)

endpoint = ENDPOINTS[user_context[:region].to_sym] || ENDPOINTS[:US]
Copy link
Preview

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

Symbolizing user_context[:region] as-is can miss the intended key if the casing differs. Consider normalizing with user_context[:region].to_s.upcase.to_sym.

Suggested change
endpoint = ENDPOINTS[user_context[:region].to_sym] || ENDPOINTS[:US]
endpoint = ENDPOINTS[user_context[:region].to_s.upcase.to_sym] || ENDPOINTS[:US]

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants