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

[NT-685] Abstract TrackingClient to be configurable #983

Merged
merged 10 commits into from
Dec 9, 2019

Conversation

justinswart
Copy link
Contributor

@justinswart justinswart commented Dec 5, 2019

📲 What

Renames our existing KoalaTrackingClient to TrackingClient and adds TrackingClientConfiguration which is a struct with which we can initialize TrackingClient so that we can use it for more than one tracking endpoint.

Note: We could even create a TrackingClient to forward our events to something like Crashlytics for our breadcrumbs. Currently we do this with a callback at the time of tracking, but I think we should move that to be its own TrackingClient.

Also note: Koala itself will be renamed separately too. Currently it really just behaves as an interface for sending the events to the clients.

🤔 Why

We're going to be sending tracking events to two endpoints until we're able to fully deprecate Koala, this allows us to do so in a somewhat controlled manner and still keeps things testable.

🛠 How

  • Abstracted any endpoint-specific functionality from TrackingClient to TrackingClientConfiguration either via simple properties or closures.
  • Updated Koala's initializer so that it can be initialized with two tracking clients.
    • Koala will send all tracking events to both clients, we will be doing some filtering of whitelisted events one we know what they are. I would suggest that we do this filtering in Koala so that we can test it through mocked clients.
  • Wrote tests for these endpoint-specific parts of TrackingClientConfiguration, this actually gives us a bit more test coverage than before because these parts of KoalaTrackingClient weren't tested.

✅ Acceptance criteria

With the simulator set to staging, return true for isKoalaTrackingEnabled (to be renamed) in EnvironmentVariables.swift. Use Charles Proxy to inspect traffic.

  • Observe that tracking events are sent to both the DataLake and Koala endpoint.
  • Observe that both requests return 200 and are in the correct structure for each endpoint (e.g. POST for Koala, PUT for DataLake, etc.).

⏰ TODO

  • Additional tests once we have whitelisted events.
  • Additional clean-up noted in comments.

internal let dateType = MockDate.self
internal let mainBundle = MockBundle()
internal let reachability = MutableProperty(Reachability.wifi)
internal let scheduler = TestScheduler(startDate: MockDate().date)
internal let trackingClient = MockTrackingClient()
internal let trackingClient = MockTrackingClient() // TODO: Rename
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming this resulted in ~700 changes so I will do that separately.

@@ -54,7 +55,11 @@ internal class TestCase: FBSnapshotTestCase {
debounceInterval: .seconds(0),
device: MockDevice(),
isVoiceOverRunning: { false },
koala: Koala(client: self.trackingClient, loggedInUser: nil),
koala: Koala(
dataLakeClient: self.dataLakeTrackingClient,
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 is a mock client set for this by default in TestCase but I think we can add tests once we whitelist events.

@@ -355,15 +356,17 @@ public final class Koala {

public init(
bundle: NSBundleType = Bundle.main,
client: TrackingClientType,
dataLakeClient: TrackingClientType = TrackingClient(.dataLake), // TODO: Remove default value
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also to reduce the amount of line changes in this PR I'm passing in a default value here. We can tackle this separately.

@@ -2028,7 +2031,12 @@ public final class Koala {

self.logEventCallback?(event, props)

self.client.track(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently we just send all events to both clients. We will whitelist before this point.


if dataString.count >= 10_000 {
// swiftlint:disable:next line_length
print("\(config.identifier.emoji) [\(config.identifier) Error]: Base64 payload is longer than 10,000 characters.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just something we printed at this point previously, not sure how important it is to keep.

Copy link
Contributor

@ifbarrera ifbarrera left a comment

Choose a reason for hiding this comment

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

This is a great start! Really easy to follow and keeps things pretty DRY. Nice work! 👏

@nativeksr
Copy link
Collaborator

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@justinswart justinswart merged commit 6dfa3c6 into master Dec 9, 2019
@justinswart justinswart deleted the new-tracking-client branch December 9, 2019 18:34
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