-
Notifications
You must be signed in to change notification settings - Fork 55
Refactor Builder to make it easier to use #523
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
base: main
Are you sure you want to change the base?
Refactor Builder to make it easier to use #523
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bergmannf The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #523 +/- ##
==========================================
+ Coverage 32.68% 32.94% +0.25%
==========================================
Files 37 37
Lines 2472 2459 -13
==========================================
+ Hits 808 810 +2
+ Misses 1603 1588 -15
Partials 61 61
🚀 New features to boost your workflow:
|
@@ -68,7 +68,20 @@ As PagerDuty itself does not provide finer granularity for webhooks than service | |||
To add a new alert investigation: | |||
|
|||
- run `make bootstrap-investigation` to generate boilerplate code in `pkg/investigations` (This creates the corresponding folder & .go file, and also appends the investigation to the `availableInvestigations` interface in `registry.go`.). | |||
- investigation.Resources contain initialized clients for the clusters aws environment, ocm and more. See [Integrations](#integrations) | |||
- The `Run` method of your investigation receives a `ResourceBuilder`. Use its `With...` methods to request the resources your investigation needs, then call `Build()` to get a `Resources` struct containing them. The builder automatically handles dependencies between resources (e.g., requesting an AWS client will also initialize the cluster object). For example: |
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.
I think we forgot to update the bootstrap:
https://github.com/openshift/configuration-anomaly-detection/blob/main/hack/bootstrap-investigation.sh
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.
Updated - I didn't know we had some scaffolding for investigations 🥳
f426d63
to
681dd06
Compare
LGTM this just needs a rebase @bergmannf |
This commit refactors the \`ResourceBuilder\` to be more user-friendly and robust. The previous implementation required callers to manage dependencies between resources manually and was prone to runtime errors if resources were not requested in the correct order. The key changes include: - A new \`NewResourceBuilder\` constructor now handles the initial setup of required components like OCM and PagerDuty clients, simplifying the builder's API. - The \`Build()\` method now lazily initializes resources only when they are explicitly requested via \`With...\` methods. This includes deferring the \`GetClusterInfo\` call until necessary. - Dependency management is now handled internally by the builder. For example, requesting an AWS client via \`WithAwsClient()\` will automatically ensure the cluster object is also built. - Investigation \`Run\` methods have been updated to explicitly declare their resource dependencies using the new builder methods. This refactoring resolves several build and runtime errors, improves the developer experience by providing a clearer and safer API, and makes investigations easier to write and maintain. Co-authored-by: Aider <using Gemini>
Explain how to use the ResourceBuilder in a new investigation, including requesting resources and the automatic dependency handling. Co-authored-by: Aider <using Gemini>
The error can convey more information than a simple bool. If it's nil = all good, otherwise the error can be returned why the investigation was stopped.
681dd06
to
e7b448c
Compare
@bergmannf: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What type of PR is this?
Feature
What this PR does / Why we need it?
Reworks the ResourceBuilder to make it slightly easier to use - also updates the documentation to explain how to use it better.
Special notes for your reviewer
This PR was co-authored by Aider with Gemini.
Test Coverage
Guidelines for CAD investigations
Test coverage checks
Pre-checks (if applicable)