Skip to content
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

feat: Added ODPManager implementation #489

Merged
merged 8 commits into from
Oct 20, 2022
Merged

Conversation

zashraf1985
Copy link
Contributor

@zashraf1985 zashraf1985 commented Oct 14, 2022

Summary

Added ODPManager Implementation which does the following.

  1. Initializes and provides access to ODPEventManager and ODPSegmentManager
  2. Provides updated ODPConfig settings to event manager and segment manager.
  3. Stops Event Manager thread when closed.

Test plan

  1. Manually tested thoroughly
  2. Added unit tests.

Issues

FSSDK-8388

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. Some changes and clarifications suggested.

this(odpConfig, new ODPSegmentManager(odpConfig, apiManager), new ODPEventManager(odpConfig, apiManager));
}

public ODPManager(@Nonnull ODPConfig odpConfig, @Nonnull ODPSegmentManager segmentManager, @Nonnull ODPEventManager eventManager) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Customization of segmentCache size/timeout and segmentCache itself as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

We also need to support for "disable" entire ODP functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two constructors.

  1. First one only takes the two mandatory arguments of ODPConfig and ApiManager and initializes everything else on default values.
  2. If you want to customize anything at all, use the second constructor which expects you to pass everything from the outside. This is where you will have a chance to initialize your own SegmentManager with your own cacheOptions.

I will recommend to keep these two options for now. We can provide other combinations at the level of factory methods to create the SDK instance later as needed. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am thinking of handling disable / enable at optimizely level. When enabled, ODP object will be there and it will always work. When disabled, there will be no ODP instance at all. What do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are two constructors.

  1. First one only takes the two mandatory arguments of ODPConfig and ApiManager and initializes everything else on default values.
  2. If you want to customize anything at all, use the second constructor which expects you to pass everything from the outside. This is where you will have a chance to initialize your own SegmentManager with your own cacheOptions.

I will recommend to keep these two options for now. We can provide other combinations at the level of factory methods to create the SDK instance later as needed. What do you think?

I see adjusting cache size and timeout more likely options for clients rather than full Cache and OdpManager customazations. Providing that path with factory will be also a good solution too.

Copy link
Contributor

@jaeopt jaeopt Oct 17, 2022

Choose a reason for hiding this comment

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

I am thinking of handling disable / enable at optimizely level. When enabled, ODP object will be there and it will always work. When disabled, there will be no ODP instance at all. What do you suggest?

I was concerned about "if odpManager == null" checking in many places we need odpManager. We can try wrap those checking in OdpManager. Other than that, disabling at the top level is also a good option too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would advise to defer this discussion till the top level PR. We can then see if it looks good at top level other wise i will add this to ODPManager. what do you say?

public void close() {
eventManager.stop();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not have top-level fetchSegments and sendEvent apis. Is it a plan to open directly from OdpEventManager and OdpSegmentManager?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is expected to filter out api requests in this level (like "disable" discards all requests). Also sendEvent data type should be validated here (are we doing this in OdpEventManager?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Disable: I am expecting disable to be handled in optimizely object which will never go to ODPManager at all if disabled.

SendEvent Data validation: I am not sure what validation needs to be done. But if there is one, i would like to add that to eventManager itself. What do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

See TDD which defines accepted types for event data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

about top level fetch and event methods, SegmentManager and EventManager provide some overrides. If i add all those overrides, it looks redundant. I thought it made more sense to provide access to segmentManager and eventManager directly through getters to use those methods.

}

public Boolean updateSettings(String apiHost, String apiKey, List<String> allSegments) {
ODPConfig newConfig = new ODPConfig(apiKey, apiHost, allSegments);
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 flush events in queue before updating apiKey/apiHost? It should not be common but when clients change the ODP account, all events in the queue should be flushed to the old account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@zashraf1985 zashraf1985 removed their assignment Oct 18, 2022
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 couple of small changes suggested.


@Transient
public Boolean isDataValid() {
for (Object entry: this.data.values()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

null is also valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -85,6 +87,10 @@ public void identifyUser(@Nullable String vuid, String userId) {
}

public void sendEvent(ODPEvent event) {
if (!event.isDataValid()) {
logger.error("Error Sending Event: 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.

Can we change it to standard message - "ODP event send failed ()"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

2. Fixed ODP event error message
@zashraf1985 zashraf1985 removed their assignment Oct 20, 2022
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

@zashraf1985 zashraf1985 merged commit 7428c4c into master Oct 20, 2022
@zashraf1985 zashraf1985 deleted the zeeshan/ats-odp-manager branch October 20, 2022 18:31
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