-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add support for targetPercentile
RMF rule parameter
#809
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8950b7a
Add JsonTargetPercentile to the config.
samsymons fe147e0
Add a `RemoteConfigRule` object.
samsymons 99ccefd
Update tests.
samsymons 2e7f2d8
Test target percentile.
samsymons 3d1e2f5
Check the message percentile when evaluating rules.
samsymons 3e76183
Add tests for percentile matching.
samsymons 4b336b1
Fix SwiftLint.
samsymons 2bab68a
Add tests for user defaults store.
samsymons d218ef2
Fix compiler warnings and private init.
samsymons de941ca
Fix SwiftLint again.
samsymons ff34df3
Merge branch 'main' into sam/remote-messaging-target-percentile
samsymons 0a93216
Merge branch 'main' into sam/remote-messaging-target-percentile
samsymons c4d1563
Merge branch 'main' into sam/remote-messaging-target-percentile
samsymons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,15 @@ import Foundation | |
|
||
public struct RemoteConfigModel { | ||
let messages: [RemoteMessageModel] | ||
let rules: [Int: [MatchingAttribute]] | ||
let rules: [RemoteConfigRule] | ||
} | ||
|
||
public struct RemoteConfigRule { | ||
let id: Int | ||
let targetPercentile: RemoteConfigTargetPercentile? | ||
let attributes: [MatchingAttribute] | ||
} | ||
|
||
public struct RemoteConfigTargetPercentile { | ||
let before: Float? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the percentile that will be sampled before we apply the attributes. The alternative here is that we do the sampling after matching attributes, but it was agreed that we'll only support the |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Sources/RemoteMessaging/RemoteMessagingPercentileStoring.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// RemoteMessagingPercentileStoring.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol RemoteMessagingPercentileStoring { | ||
func percentile(forMessageId: String) -> Float | ||
} | ||
|
||
public class RemoteMessagingPercentileUserDefaultsStore: RemoteMessagingPercentileStoring { | ||
samsymons marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private let userDefaults: UserDefaults | ||
|
||
init(userDefaults: UserDefaults) { | ||
self.userDefaults = userDefaults | ||
} | ||
|
||
public func percentile(forMessageId: String) -> Float { | ||
return 0.95 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Tests/BrowserServicesKitTests/RemoteMessaging/Mocks/MockRemoteMessagePercentileStore.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// MockRemoteMessagePercentileStore.swift | ||
// DuckDuckGo | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import RemoteMessaging | ||
|
||
class MockRemoteMessagePercentileStore: RemoteMessagingPercentileStoring { | ||
|
||
var percentileStorage: [String: Float] = [:] | ||
var defaultPercentage: Float = 0 | ||
|
||
func percentile(forMessageId messageID: String) -> Float { | ||
if let percentile = percentileStorage[messageID] { | ||
return percentile | ||
} | ||
|
||
percentileStorage[messageID] = defaultPercentage | ||
return defaultPercentage | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 technically less efficient than the old implementation, but a bit simpler. We have so few rules at one time that the difference here is negligible, but let me know if you feel otherwise.