-
Notifications
You must be signed in to change notification settings - Fork 21
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(message): Add Flag Support #264
Conversation
message/message.go
Outdated
@@ -16,6 +16,15 @@ import ( | |||
const ( | |||
// metaKey is a prefix used to access the meta field in a Message. | |||
metaKey = "meta " | |||
|
|||
// IsControl indicates that the message is a control message. | |||
IsControl = iota |
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.
Style: It might be more clear that these are part of the flag system if their names are: FlagIsControl
, FlagSkipNullValues
, etc?
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 was avoiding stutter, like:
msg.HasFlag(message.FlagIsControl)
The Uber style guide has what looks like a good solution to this problem, so I added that.
message/message.go
Outdated
@@ -44,6 +53,8 @@ type Message struct { | |||
// | |||
// Control messages trigger special behavior in transforms and conditions. | |||
ctrl bool | |||
|
|||
flags []any |
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.
Is flags every a non int
value from the iota
above? If not, maybe this should have a stronger type than any.
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.
fixed
Description
message
packagecondition
package,transform
package, andcmd
apps for message flagsMotivation and Context
Recent releases have been opinionated about how to process data and we should move toward a future where there is less "internal magic" and things happening without user's being aware. This is most evident in how messages are skipped during data transformation if the accessed value is missing:
This might be the best choice for most use cases, but unless you know that lines like this exist, you have no idea this is happening. (There are some other examples of this as well, but this PR is focused on addressing message skips.) Message flags are foundational to fixing this problem because they make it possible to embed configs directly in messages, like this:
Using flags, packages (condition, transform, etc.) can check for attributes like this:
This isn't a new concept because this is what the
ctrl
attribute already does for messages (except it was not created within a larger system of flags). These are now equivalent:This PR is a feature and refactor to avoid a breaking change (missing values still cause a message skip for most transform functions), but in the future we will likely have a configuration that looks like this so that it's configurable by users:
How Has This Been Tested?
Types of changes
Checklist: