-
Notifications
You must be signed in to change notification settings - Fork 20
feat: Added ODPEventManager implementation #320
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
Conversation
# Conflicts: # OptimizelySDK.Tests/OptimizelySDK.Tests.csproj # OptimizelySDK.sln.DotSettings # OptimizelySDK/Odp/Entity/OdpEvent.cs # OptimizelySDK/OptimizelySDK.csproj
Needed control over threading/non-parallel test execution
This reverts commit d0528e7.
Minimum that still gives me SingleThreaded. Hopefully monodevel will be okay with it
There's gotta be a better way.
Thanks to finding Java's CountDownLatch :-)
to resolve the GH Actions linting
match current supported version of ubuntu image in use
GH Actions Log: >>>> xbuild tool is deprecated and will be removed in future updates, use msbuild instead <<<<
Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com>
…e/odp-event-manager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm but please address some nits.
|
||
/// <summary> | ||
/// Event data in a key-value pair format | ||
/// </summary> | ||
public Dictionary<string, object> Data { get; } | ||
public Dictionary<string, object> Data { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make it private set or what's the need of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mutate the Data
in OdpEventManager.cs's SendEvent() with a call to AugmentCommonData()
|
||
namespace OptimizelySDK.Odp | ||
{ | ||
public interface IOdpEventManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments please.
OptimizelySDK/Odp/OdpConfig.cs
Outdated
/// <returns>true if ODP configuration can be used otherwise false</returns> | ||
public virtual bool IsReady() | ||
{ | ||
return !string.IsNullOrWhiteSpace(ApiKey) && !string.IsNullOrWhiteSpace(ApiHost); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will prefer one not instead of two.
!a && !b = !(a || b)
OptimizelySDK/Odp/OdpEventManager.cs
Outdated
"Guid", | ||
}; | ||
|
||
private readonly Dictionary<string, object> _commonData = new Dictionary<string, object> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move this data initialization into constructor.
OptimizelySDK/Odp/OdpEventManager.cs
Outdated
} | ||
|
||
/// <summary> | ||
/// Immediately send all ODP events in queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Immediately send a signal to send all events in queue.
_eventQueue.Add(_flushSignal); | ||
} | ||
|
||
private void FlushQueue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the one, sends events in queue. please add summary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I see a couple of more thread-safety cases and a few small issues. See my comments.
OptimizelySDK/Odp/OdpEventManager.cs
Outdated
/// </summary> | ||
public void Flush() | ||
{ | ||
_flushingIntervalDeadline = DateTime.Now.MillisecondsSince1970() + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this update here? This is only place we share flushingIntervalDeadline
between threads.
OptimizelySDK/Odp/OdpEventManager.cs
Outdated
/// <param name="odpEvent"></param> | ||
private void AddToBatch(OdpEvent odpEvent) | ||
{ | ||
lock (_mutex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this lock?
OptimizelySDK/Odp/OdpEventManager.cs
Outdated
} | ||
|
||
List<OdpEvent> toProcessBatch; | ||
lock (_mutex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why lock here? All looks like in the same thread.
OptimizelySDK/Odp/OdpEventManager.cs
Outdated
if (Disposed || !IsStarted || !_odpConfig.IsReady()) | ||
{ | ||
_logger.Log(LogLevel.WARN, Constants.ODP_NOT_INTEGRATED_MESSAGE); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to separate cases. ODP_NOT_INTEGRATED may be a wrong message for other conditions.
OptimizelySDK/Odp/OdpEventManager.cs
Outdated
!_validOdpDataTypes.Any(t => | ||
t.Equals(item.Value.GetType().Name, StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can consider to improve this. For a long data set and valid type set, this can be slow for every event.
|
||
/// <summary> | ||
/// Add additional common data including an idempotent ID and execution context to event data | ||
/// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment that sourceData has a higher priority if keys conflict?
OptimizelySDK/Odp/OdpConfig.cs
Outdated
/// <summary> | ||
/// Public API key for the ODP account from which the audience segments will be fetched (optional). | ||
/// </summary> | ||
public string ApiKey { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to lock-protect all these "ApiKey", "ApiHost" and "SegmentsToCheck" get/set for thread-safety?
@jaeopt, let me know if you have any further changes you'd like to see. Thanks. 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - I see one log message inappropriate. Other than all looks good!
OptimizelySDK/Odp/OdpEventManager.cs
Outdated
|
||
if (IsStarted && !Disposed) | ||
{ | ||
_logger.Log(LogLevel.WARN, Constants.ODP_NOT_ENABLED_MESSAGE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this message correct for when IsStarted is already ON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you. It doesn't seem quite right.
I couldn't decide which message to provide from the TDD's "3.6 Errors/Log Messages".
I was hoping for something like "ODP has not been started."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikechu-optimizely It should be something like "already started". Not related to ODP.
Summary
Added
OdpEventManager
implementation.Test plan
Jira
FSSDK-8444