Skip to content

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

Merged
merged 88 commits into from
Nov 18, 2022

Conversation

mikechu-optimizely
Copy link
Contributor

Summary

Added OdpEventManager implementation.

Test plan

  • Unit tests added
  • Existing tests continue to pass

Jira

FSSDK-8444

# 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
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 <<<<
@mikechu-optimizely mikechu-optimizely removed the request for review from a team November 16, 2022 15:52
Copy link
Contributor

@msohailhussain msohailhussain left a 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; }
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 make it private set or what's the need of it?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

comments please.

/// <returns>true if ODP configuration can be used otherwise false</returns>
public virtual bool IsReady()
{
return !string.IsNullOrWhiteSpace(ApiKey) && !string.IsNullOrWhiteSpace(ApiHost);
Copy link
Contributor

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)

"Guid",
};

private readonly Dictionary<string, object> _commonData = new Dictionary<string, object>
Copy link
Contributor

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.

}

/// <summary>
/// Immediately send all ODP events in queue
Copy link
Contributor

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()
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 the one, sends events in queue. please add summary.

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! I see a couple of more thread-safety cases and a few small issues. See my comments.

/// </summary>
public void Flush()
{
_flushingIntervalDeadline = DateTime.Now.MillisecondsSince1970() +
Copy link
Contributor

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.

/// <param name="odpEvent"></param>
private void AddToBatch(OdpEvent odpEvent)
{
lock (_mutex)
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 remove this lock?

}

List<OdpEvent> toProcessBatch;
lock (_mutex)
Copy link
Contributor

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.

Comment on lines 247 to 251
if (Disposed || !IsStarted || !_odpConfig.IsReady())
{
_logger.Log(LogLevel.WARN, Constants.ODP_NOT_INTEGRATED_MESSAGE);
return;
}
Copy link
Contributor

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.

Comment on lines 339 to 340
!_validOdpDataTypes.Any(t =>
t.Equals(item.Value.GetType().Name, StringComparison.OrdinalIgnoreCase))
Copy link
Contributor

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>
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 add a comment that sourceData has a higher priority if keys conflict?

/// <summary>
/// Public API key for the ODP account from which the audience segments will be fetched (optional).
/// </summary>
public string ApiKey { get; private set; }
Copy link
Contributor

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?

@mikechu-optimizely
Copy link
Contributor Author

@jaeopt, let me know if you have any further changes you'd like to see. Thanks. 😃

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 - I see one log message inappropriate. Other than all looks good!


if (IsStarted && !Disposed)
{
_logger.Log(LogLevel.WARN, Constants.ODP_NOT_ENABLED_MESSAGE);
Copy link
Contributor

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?

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 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."

Copy link
Contributor

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.

@mikechu-optimizely mikechu-optimizely merged commit 3eb53bd into master Nov 18, 2022
@mikechu-optimizely mikechu-optimizely deleted the mike/odp-event-manager branch November 18, 2022 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants