[MOB-16678] Handle edge network location hint response#259
[MOB-16678] Handle edge network location hint response#259
Conversation
…andlers to EdgeHitProcessor and NetworkResponseHandler. This makes the EdgeState the holder of the location hint while other classes must call it to get or update the location hint.
…atches a shared state
| // else keep consent pending until the consent preferences update event is received | ||
|
|
||
| // TODO - Always set state or only when properties are not empty ??? | ||
| createSharedState(edgeProperties.toEventData(), nil) |
There was a problem hiding this comment.
Always creates a shared state when EdgeState boots, regardless of location hint value. Another option is to only create the shared state if there is a valid location hint value, but I think creating an initial empty shared state on boot is better approach and more consistent with how other extensions are implemented.
| // lower event numbers than states using nil. If this extension later needs to create shared | ||
| // states from received events, then this code must be refactored to also use received | ||
| // events as the state version. | ||
| createSharedState(self.edgeProperties.toEventData(), nil) |
There was a problem hiding this comment.
I'm using nil here for the shared state version, which will cause the Event Hub to get the next available version number. I'm using nil because this function is called by the NetworkResponseHandler which does not have a triggering event to create a shared state with. Using nil here means I must always use nil when creating a shared state even when I have one available (such as in bootupIfNeeded). The shared state is created mainly for Rules use-cases where a customer may want to build a postback URL using the location hint.
Another option is for NetworkResponseHandler to dispatch an event which is listened for by Edge to handle the location hint. That way there is an event to use to create the shared state. This is how Identity Direct extension handles this case. This option, however, will cause a delay when the location hint is handled and any queued hits will not include the hint in their URLs.
As there are not current plans for Edge to include other properties in it's shared state, I feel the first option of using 'nil' is the better approach, but I wanted to point this out to hear other's thoughts.
Codecov Report
@@ Coverage Diff @@
## dev #259 +/- ##
==========================================
+ Coverage 92.54% 95.45% +2.91%
==========================================
Files 27 28 +1
Lines 1032 1143 +111
==========================================
+ Hits 955 1091 +136
+ Misses 77 52 -25 |
| build-and-test: | ||
| macos: | ||
| xcode: 12.0.1 # Specify the Xcode version to use | ||
| xcode: 13.4.0 # Specify the Xcode version to use |
There was a problem hiding this comment.
Is the code coverage issue fixed in 13.4?
There was a problem hiding this comment.
I'm not seeing an issue with CodeCov. I've updated the version because version 12 of Xcode is no longer supported in CircleCI. The builds just fail now. Their documentation states that they support the latest 4 major.minor versions of Xcode. We've used Xcode 13.0.0 for other projects, but that is the 4th version. If there is a 13.5 version of Xcode, then 13.0.0 may not be supported. I didn't want to bump all the way to Xcode 14, so I picked that latest Xcode 13 image supported by CircleCI.
| } | ||
|
|
||
| enum LocationHint { | ||
| static let SCOPE = "scope" |
There was a problem hiding this comment.
Should we add the "locationHint" constant here only?
static let KEY = "locationHint"
There was a problem hiding this comment.
Can you explain further? I guess I don't understand the question.
There was a problem hiding this comment.
This approach is also fine. I was wondering if changing the location of the constant makes sense.
nit:
Instead of Edge.LOCATION_HINT -> we have it as LocationHint.KEY
| private func setLocationHint(hint: String?, ttlSeconds: TimeInterval?) { | ||
| guard let state = state else { return } | ||
| if let hint = hint, let ttlSeconds = ttlSeconds { | ||
| state.setLocationHint(hint: hint, ttlSeconds: ttlSeconds, createSharedState: createSharedState(data:event:)) |
There was a problem hiding this comment.
Do other extensions use the locationHint from the shared state?
There was a problem hiding this comment.
Not currently and it's not expected as they should send requests through the Edge extension. The shared state is intended for Rules use cases where a customer may want to send a postback directly to the Edge Network. There's no hard requirement for that use-case either, however.
| } else { | ||
| handleStoreEventHandle(handle: eventHandle) | ||
| if let type = eventHandle.type { | ||
| if EdgeConstants.JsonKeys.Response.EVENT_HANDLE_TYPE_STORE == type.lowercased() { |
There was a problem hiding this comment.
nit: Is type.lowercased() required? Calling it only for if condition is little confusing.
There was a problem hiding this comment.
I don't think it's required as the response uses "state:store" (lowercased). However, the original code used it so I preserved the logic. The handle type "locationHint:result" is mix cased so I'm doing an exact match.
Sources/EdgeState.swift
Outdated
| @@ -74,4 +93,57 @@ class EdgeState { | |||
| currentCollectConsent = status | |||
There was a problem hiding this comment.
This is not related to your PR but some of the variables are not guarded by DispatchQueue and this could cause race conditions and crashes.
There was a problem hiding this comment.
I've updated EdgeState to guard the consent status. It's better to do it as it keep the design consistent, however I don't think the consent status is accessed from multiple threads. Can you take another look at this part of the PR?
…-mob-16678-region-id
Description
Handle the EdgeNetwork location hint response from Konductor.
Reads location hint and ttl from Konductor response and stores in EdgeProperties. All requests from the Edge extension will include the location hint in the request URL if available and if not expired. The location hint and expiry date (calculated from the ttlSeconds) is persisted in User Defaults and loaded once the Edge extension launches.
The Edge extension now creates a shared state which includes just the location hint. A shared state is created on launch of the extension and when ever the location hint value changes. A shared state is not created, however, if only the expiry date is updated but the hint value doesn't change.
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: