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

PIR Stabilization: Extract Operation Building from Processor #2743

Merged

Conversation

aataraxiaa
Copy link
Contributor

@aataraxiaa aataraxiaa commented May 5, 2024

Task/Issue URL: https://app.asana.com/0/1199230911884351/1207175016813446/f
Tech Design URL: https://app.asana.com/0/0/1207199754528648/f
CC:

Description:
This PR includes all changes relating to this tech design sub-task. Specifically:

  1. Extracts DataBrokerOperationsCollection building to a dedicated type, and adds tests
  2. Encapsulates all dependencies needed to create operations into a dedicated type
  3. Uses DataBrokerOperationsBuilder to build operations in the ‘Processor'
  4. Renames DataBrokerOperationsCollection to DataBrokerOperation
  5. Renames original DataBrokerOperation to DataBrokerJob, and renames related types
  6. Renames BrokerOperationData and related types to BrokerJobData

Note: There is a lot of renaming changes in this PR. To mitigate this, the renaming changes are all grouped in dedicated commits. Therefore, to review this PR, it’s best to review commit-by-commit. This way you can focus on the commits which are not purely renaming-related.

Steps to test this PR:

  1. Launch the browser
  2. Open PIR and initiate a new scan (i.e new profile or edit existing profile)
  3. Ensure the scan runs and results are received

Internal references:

Pull Request Review Checklist
Software Engineering Expectations
Technical Design Template
Pull Request Documentation

Copy link
Contributor

github-actions bot commented May 5, 2024

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against ee49467

@aataraxiaa aataraxiaa changed the base branch from main to feature/pir-stabilization May 6, 2024 13:51
@aataraxiaa aataraxiaa marked this pull request as ready for review May 6, 2024 13:53
@aataraxiaa aataraxiaa requested a review from THISISDINOSAUR May 6, 2024 14:05
@aataraxiaa
Copy link
Contributor Author

CC @Bunn - this is the PR we chatted about on MM.


typealias OperationType = DataBrokerOperation.OperationType

protocol DataBrokerOperationsBuilder {
Copy link
Contributor Author

@aataraxiaa aataraxiaa May 6, 2024

Choose a reason for hiding this comment

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

Some feedback here re: naming of Builder. I don’t feel too strongly, but will wait for any more input here from reviewers before making any changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also have little opinion on it, except for avoiding initializer since it's obviously a thing already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to DataBrokerOperationsCreator

Copy link
Contributor

@THISISDINOSAUR THISISDINOSAUR left a comment

Choose a reason for hiding this comment

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

Massive props for seperating out different commits, it makes it much easier to review!


typealias OperationType = DataBrokerOperation.OperationType

protocol DataBrokerOperationsBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

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

I also have little opinion on it, except for avoiding initializer since it's obviously a thing already

func operations(operationType: OperationType,
priorityDate: Date?,
showWebView: Bool,
operationDependencies: OperationDependencies) throws -> [DataBrokerOperationsCollection] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't quite come up with anything I'm completely happy with, but it would be good to distinguish between the types of parameters here (a/ things that dictate the type of operations returned and b/ things the operations depend on), how about:

func operations(forOperationType operationType: OperationType,
                    withPriorityDate priorityDate: Date?,
                    showWebView: Bool,
                    operationDependencies: OperationDependencies) throws -> [DataBrokerOperationsCollection]

Although if you accused me of never getting over Objective-C from this suggestion it would be hard to rebuke

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice idea (even if influenced by Obj-C 😄). I’ll make the suggested changes.

@@ -146,7 +136,6 @@ final class DataBrokerOperation: Operation {
allBrokerProfileQueryData = try database.fetchAllBrokerProfileQueryData()
} catch {
os_log("DataBrokerOperationsCollection error: runOperation, error: %{public}@", log: .error, error.localizedDescription)
errorDelegate?.dataBrokerOperation(self, didErrorBeforeStartingBrokerOperations: error)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the plan for error propagation?

Copy link
Contributor Author

@aataraxiaa aataraxiaa May 8, 2024

Choose a reason for hiding this comment

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

Good question! My initial thinking here was:

  • We are currently not utilizing the error propagation (we were simply firing a pixel, while also injecting the pixel handler into DataBrokerOperation. So I just changed to fire the pixel directly in the DataBrokerOperation.
  • Based on above, I didn’t want to carry-over code from the old implementation if there was no explicit use for it.
  • I considered error propagation, and decided that not including it right now (as we don’t use it), while also refactoring in a way that it’s easy to add later, was the way to go.
  • However , saying all that, I think we can conclusively say that we do want error propagation as some point, and so it’s not an over-optimization. As such, I can re-add it, and we can decide how to use it later.

Edit: After looking more at the code, and thinking about this, I don’t think we should propagate at the moment. This is because we also ‘handle’ errors in the barrier block of the processor. As follows:

operationQueue.addBarrierBlock {
            let operationErrors = operations.compactMap { $0.error }
            let errorCollection = operationErrors.count != 0 ? DataBrokerProtectionSchedulerErrorCollection(operationErrors: operationErrors) : nil
            completion(errorCollection)
        }

Not sure this is what we want, but until we know it isn’t, I don’t think we need an explicit propagation from individual operations.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we at least need a plan for it, do you have any ideas on what the best way to add it would be? It might be easier to reason about in the context of the next PR

I think we do need to make sure if the function is interrupted it still returns scan errors correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, yup, agree that we need to ensure that interrupted operation queues should still return errors, and also that this will be easier to reason about with the subsequent ‘QueueManager’ work. I’ll fix Swiftlint errors and merge this.

Copy link
Contributor

@THISISDINOSAUR THISISDINOSAUR left a comment

Choose a reason for hiding this comment

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

LGTM!

@aataraxiaa aataraxiaa force-pushed the pete/extract-operation-collection branch from bab2f29 to 1452cc5 Compare May 8, 2024 13:25
@aataraxiaa aataraxiaa changed the base branch from feature/pir-stabilization to main May 8, 2024 13:41
@aataraxiaa aataraxiaa changed the base branch from main to feature/pir-stabilization May 8, 2024 13:41
@Bunn
Copy link
Collaborator

Bunn commented May 8, 2024

LGTM, just note that the failing tests are failing for an actual reason:

Error: cannot find type 'SchedulerConfig' in scope
final class MockSchedulerConfig: SchedulerConfig {

Please take a look at this before merging

@aataraxiaa aataraxiaa merged commit 8614459 into feature/pir-stabilization May 8, 2024
19 checks passed
@aataraxiaa aataraxiaa deleted the pete/extract-operation-collection branch May 8, 2024 15:59
THISISDINOSAUR added a commit that referenced this pull request May 22, 2024
Task/Issue URL:
https://app.asana.com/0/1199230911884351/1207338264132623/f
Tech Design URL:
https://app.asana.com/0/481882893211075/1207174884557414/f
CC:

**Description**:
This PR has the effect of mergeing four different PRs into main:
#2777
#2758
#2757
#2743
This covers significant changes to the XPC interface and how the main
app uses it, the background manager, the scheduler, and the processor.
See individual PRs for details.

There's no code changes here that haven't been reviewed separately as
part of those PRs, so it's up to you how you want to review it code
wise. The more important step at this stage is manual testing.

**Steps to test this PR**:
1. Because this is a fairly significant set of changes, we need to be as
thorough as we can in testing DBP generally works and really try to
break it. Because of this, I'm keen that anyone testing things of their
own ways to break it before trying the steps below.
2. Edit/add profile data, and before scans finish, edit it again. Scans
should start afresh, and you should see an interrupted pixel fire. Check
that you don't get a scans completed notification
3. Edit/add profile data, and before scans finish, close the app, and
reopen it. The same set of manual scans should still continue, and a
blocked pixel should fire.
4. With profile data already existing but initial scans having finished,
close the app and reopen it. Scheduled scans should run.
5. With profile data already existing, and with the app closed, launch
the background agent, scheduled scans should run
6. Edit/add profile data, put the laptop to sleep/lock it/restart it,
check that scans continue as expected.
7. Check that the background agent activity lines up with the UI, I.e.
the progress bar and when we sent the scans completed notification is
accurate

<!--
Tagging instructions
If this PR isn't ready to be merged for whatever reason it should be
marked with the `DO NOT MERGE` label (particularly if it's a draft)
If it's pending Product Review/PFR, please add the `Pending Product
Review` label.

If at any point it isn't actively being worked on/ready for
review/otherwise moving forward (besides the above PR/PFR exception)
strongly consider closing it (or not opening it in the first place). If
you decide not to close it, make sure it's labelled to make it clear the
PRs state and comment with more information.
-->

---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)

---------

Co-authored-by: Pete Smith <[email protected]>
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