-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(notification): move rule service into own package #19804
Conversation
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.
My only nitpick is the stuttering of ruleservice.NewRuleService
but that's not worth worrying about, just personal preference 😄
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 looks good to me. I am tempted to be devil's advocate are ponder if we should keep this code in the same package as Cloud, however, I then convince myself it is a fallacy to think this code will / should remain the same between the two systems.
Once the tests pass, I give it the 🆗
@stuartcarnie I agree. I should have noted this actually. Putting it in the same place leads to the following packages:
Which I couldn't bring myself to do. So I moved them flat into the existing:
But then this created a cycle in dependencies because the services I ported depend on |
LastRunError string `json:"lastRunError,omitempty"` | ||
} | ||
|
||
func (resp *notificationRuleResponse) UnmarshalJSON(v []byte) (err error) { |
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.
Note for reader:
The unmarshalling here never worked. Leading this client to result in a nil
NotificationRule and a nil
error when positively finding a rule.
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 was causing a panic when this client was used for pkger tests.
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.
Great find!
This also introduces the org id resolver type. Which is transplanted from the kv service. As this one function coupled all resource capabilities onto the kv service. Making removing these capabilities impossible. Moving this type out into its own package which depends on each service explicitly ensures we don't have one type which has to implement all the service contracts.
c701836
to
17c9f8e
Compare
933463d
to
764c8a5
Compare
@stuartcarnie and @gavincabbage I updated this PR in a number of ways. See the update in the description. As I kept pulling threads I found a bunch of fun traps. Which the PR should now resolve. |
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.
Great updates George – I can appreciate this is an arduous process, but your work to eliminate the kv.Service
is very valued and appreciated 💯
LastRunError string `json:"lastRunError,omitempty"` | ||
} | ||
|
||
func (resp *notificationRuleResponse) UnmarshalJSON(v []byte) (err error) { |
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.
Great find!
@@ -6,19 +6,19 @@ import ( | |||
"github.com/influxdata/influxdb/v2" | |||
) | |||
|
|||
type OrganizationService interface { | |||
type OrgIDResolver interface { |
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'm not objecting to the name, but throwing out OrgIDFinder
as an alternative, in case you like it and the verb is FindResourceOrganizationID.
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.
Good shout. I actually rename this again in two PRs time to just Resolver
(in the Telegraf PR). But I will rename it Finder in that PR as it finds both org IDs and name 👍
Closes #19798
This creates the separate (non-URM interaction) notification rule service implementation. It is mostly a cut/paste of the kv service as it is today. Without URM interaction. Which we have shown to not be necessary in order to operate properly.
This doesn't remove the original definition in
*kv.Service
yet.That will be delivered in a later PR (likely in the larger #19783).
Update:
A few extra things had to be delivered to put a bow on this:
TL;DRs
resource.OrgIDResolver
to sever the responsibility from*kv.Service
.Exhaustive explanations:
FindNotificationRuleByID
did not work. Because of some poor unmarshalling of the convoluted json format this endpoint produces, it accidentally failed to unmarshall the embedded rule, resulting in a nil rule and a nil error. Referring to this rule down the line caused a panic.testing
. So the best option was to just remove those definitions now we have ported them next to the service itself (innotification/rule/service
package). Doing so left the kv service notification rule service without tests. Since this is deprecating that service to ultimately be removed in the coming week, I decided to just remove it as a part of this PR.