Skip to content

feat: add odp manager #314

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

Merged
merged 4 commits into from
Sep 26, 2022
Merged

feat: add odp manager #314

merged 4 commits into from
Sep 26, 2022

Conversation

andrewleap-optimizely
Copy link
Contributor

Summary

Provides all internal services related to the ODP integration:

  • OdpSegmentManager
  • OdpEventManager
  • OdpSegmentsCache

Internal API:

  • fetch_qualified_segments
  • identify_user
  • send_event

Test plan

  • odp_manager_spec.rb

Ticket

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.

Looks good! A few changes suggested.

#
# @return - Array of qualified segments or nil.
options ||= []
unless @enabled && @segment_manager
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
unless @enabled && @segment_manager
unless @enabled

segment_manager is not-null always?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I'm just used to convincing the type checker... but ruby does not care, so it's removed 🥳

end

unless Helpers::Validator.odp_data_types_valid?(data)
@logger.log(Logger::DEBUG, format(ODP_LOGS[:ODP_EVENT_NOT_DISPATCHED], action, 'ODP data is not valid'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@logger.log(Logger::DEBUG, format(ODP_LOGS[:ODP_EVENT_NOT_DISPATCHED], action, 'ODP data is not valid'))
@logger.log(Logger::ERROR, format(ODP_LOGS[:ODP_EVENT_NOT_DISPATCHED], action, ODP_NOT_ENABLED))

# @param identifiers - a hash for identifiers.
# @param data - a hash for associated data. The default event data will be added to this data before sending to the ODP server.
unless @enabled && @event_manager
@logger.log(Logger::DEBUG, format(ODP_LOGS[:ODP_EVENT_NOT_DISPATCHED], action, 'ODP disabled'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@logger.log(Logger::DEBUG, format(ODP_LOGS[:ODP_EVENT_NOT_DISPATCHED], action, 'ODP disabled'))
@logger.log(Logger::DEBUG, format(ODP_LOGS[:ODP_EVENT_NOT_DISPATCHED], action, ODP_NOT_ENABLED))

end

def close!
@event_manager&.stop!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@event_manager&.stop!
return unless @enabled
@event_manager.stop!

Just for clarity?

@odp_config = OdpConfig.new

unless @enabled
@logger.log(Logger::DEBUG, 'ODP is disabled')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@logger.log(Logger::DEBUG, 'ODP is disabled')
@logger.log(Logger::INFO, ODP_NOT_ENABLED)

end

def identify_user(user_id:)
send_event(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call "@event_manager.send_event()" directly?
"identify_user" is implicit call by SDK while "send_event" explicit call by the client, so errors can be handled differently. When ODP_DISABLED, "identify_user" can drop silently (with debug log) and can skip parameter validation, while "send_event" should log error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense to me

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

Looks Great! I have just asked one question that i am curios about but that does not block this PR from my side.

@event_manager.send_event(type: type, action: action, identifiers: identifiers, data: data)
end

def update_odp_config(api_key, api_host, segments_to_check)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is great! I am just curios who will call this function? should we add a notification listener here and make odpmanager self update itself? Or are we expecting to do something like that and trigger updates from the outside by calling this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea the idea is to register the listener at client initialization and have the callback be a client method, thus avoiding having to pass in the NotificationListener and the ProjectConfig. Seems to make sense because the callback needs access to both ProjectConfig and OdpConfig. Thoughts/opinions?

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

@andrewleap-optimizely andrewleap-optimizely merged commit b495a48 into master Sep 26, 2022
@andrewleap-optimizely andrewleap-optimizely deleted the aleap/add_odp_manager branch September 26, 2022 20:51
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.

3 participants