-
Notifications
You must be signed in to change notification settings - Fork 129
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
feat: logs friendly names with plugins #662
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.
Mostly tidying. The changelog process change was something I was thinking about for a while (IMO it has been a significant workflow improvement in the other repos where we've adopted it), and the buried breaking change here is something that's hard to catch when instead writing it at the end, so asking for some scope creep to change process here as well.
utils/utils.go
Outdated
func AsKongConsumer(c kong.Consumer) *kong.Consumer { | ||
consumer := &kong.Consumer{ID: kong.String(*c.ID)} | ||
if c.Username != nil { | ||
consumer.Username = kong.String(*c.Username) | ||
} | ||
return consumer | ||
} | ||
|
||
func AsKongService(s kong.Service) *kong.Service { | ||
service := &kong.Service{ID: kong.String(*s.ID)} | ||
if s.Name != nil { | ||
service.Name = kong.String(*s.Name) | ||
} | ||
return service | ||
} | ||
|
||
func AsKongRoute(r kong.Route) *kong.Route { | ||
route := &kong.Route{ID: kong.String(*r.ID)} | ||
if r.Name != nil { | ||
route.Name = kong.String(*r.Name) | ||
} | ||
return route | ||
} |
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.
These are exported and should have doc comments, especially since it's kinda hard to understand why you'd use them--reading them is kinda weird since it looks like they take a kong.X
and return a copy of it, kinda, with a bunch of fields stripped out?
Naming like AsFooBar(f foo.Bar) *foo.Bar
reads weird since I'd normally expect that for functions that transform one type into a different similar type, but these instead take a type and return the same type with most fields omitted, so we should consider a different name for them even.
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.
Yeah I totally agree...what about GetStrippedRoute
or GetRouteWithIDAndName
?
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.
GetIDNameOnlyServiceCopy
?
The doc comments are the more important part. Something like
// GetRouteWithIDAndName takes a kong.Route and returns a reference to a new kong.Route. The new kong.Route has the ID and Name fields from the input route, but none of the other input route's fields.
And above all such functions:
// These functions return stripped copies (ID and Name only) of Kong resource objects. We use these elsewhere [in place] because we cannot use the original objects, as objects with all fields present would [result in some unwanted outcome].
with the [placeholder]
bits filled in. It's not immediately clear to me why we wouldn't use the original objects (they do already have their Name and ID, so it seems like we'd just be able to use them as-is), so while I assume there is some reason, I can't intuit it, and suspect that future readers will have the same confusion.
Hijacking the end of this for a pre-release changelog entry reminder also.
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.
did a bit more of investigation here and it seems that we actually only need to zero-out the timestamps from the entities, instead of creating new ones only with IDs and Names 1364c15
That said, it was done this way (setting only the IDs in current main
and adding the Names in the original PR) because that's just what's needed for referenced entities. For example, this test is currently failing because the embedded entity now has all its field, instead of having just the few required ones.
(it's better to fully visualise it from here)
WDYT?
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.
Ah, now it makes sense. That explanation was basically exactly what I was looking for in the comment 😄 I wasn't making the connection that these were references. With that in mind, the original name/ID only approach makes more sense than timestamp stripping:
// These GetFooReference functions return stripped copies (ID and Name only) of Kong resource structs. We use these
// within KongRawState structs to indicate entity relationships. While state files indicate relationships by nesting (A
// collection of services is [{name: "foo", id: "1234", connect_timeout: 600000, routes: [{name: "fooRoute"}]}]),
// KongRawState is flattened, with all entities listed independently at the top level. To preserve the relationships, these
// flattened entities include references (the route from earlier becomes {name: "fooRoute", service: {name: "foo", id:
// "1234"}}).
// GetRouteReference returns a name+ID only copy of the input route, for use in references from other objects
GetRouteReference() {
... return the ID/name only copy
}
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.
Totally agree, that wasn't clear to me either :)
1256568
to
51e19d2
Compare
Codecov Report
@@ Coverage Diff @@
## main #662 +/- ##
==========================================
- Coverage 44.37% 43.59% -0.78%
==========================================
Files 74 74
Lines 8778 8966 +188
==========================================
+ Hits 3895 3909 +14
- Misses 4522 4688 +166
- Partials 361 369 +8
Continue to review full report at Codecov.
|
2679999
to
1268ed6
Compare
1268ed6
to
284d718
Compare
Kong and Konnect APIs only require IDs for referenced entities. In some cases, injecting the entities name in the requests is problematic. This makes sure these names are stripped before making API requests, while preserving the capability of logging user-friendly messages as added in #662
Kong and Konnect APIs only require IDs for referenced entities. In some cases, injecting the entities name in the requests is problematic. This makes sure these names are stripped before making API requests, while preserving the capability of logging user-friendly messages as added in #662
* feat: add names and usernames to plugin, consumer and route * refactor: use of go-kong's FriendlyName() instead of Identifier() in logs * feat: ignore diff for names in embedded entities * tests: add test for plugins on entities creation Co-authored-by: Matthieu Morel <matthieu.morel@cnp.fr>
Kong and Konnect APIs only require IDs for referenced entities. In some cases, injecting the entities name in the requests is problematic. This makes sure these names are stripped before making API requests, while preserving the capability of logging user-friendly messages as added in #662
Based on the initial work in #459
Changes from the first PR:
main
and solved conflicts