-
Notifications
You must be signed in to change notification settings - Fork 528
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
New intake decoder #4076
New intake decoder #4076
Conversation
💔 Build FailedExpand to view the summary
Build stats
Steps errorsExpand to view the steps failures
Log outputExpand to view the last 100 lines of log output
|
processor/stream/processor.go
Outdated
type metadataDecoder interface { | ||
Decode(m *model.Metadata) error | ||
Validate(input map[string]interface{}) 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.
WDYT about changing this to be something like
type decodeMetadataFunc func(d decoder.Decoder, *model.Metadata) error
Where decoder.Decoder
is a new interface in the decoder package:
package decoder
type Decoder interface {
Decode(v interface{}) error
}
Internally the decoder could decode to a json.RawMessage
first, and then decode to the struct - until the validation logic is run after decoding into the struct.
I'm not sure if this is great either, I'd just like to keep all the decoding and validation in one call from here. IIUC the Validate call is here only temporarily, and it would later be done immediately after UnmarshalJSON
. How do you expect the code in this package to look ultimately?
760ecd8
to
8874c7a
Compare
@axw when having another look please focus on the |
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.
Thanks, I think this is taking good shape.
beater/api/intake/test_approved/InvalidJSONMetadata.approved.json
Outdated
Show resolved
Hide resolved
model/modeldecoder/v2/simdjson.go
Outdated
if key != "" { | ||
s = fmt.Sprintf("%s.%s", key, s) | ||
} |
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.
Like in the validation code, it would be great if we could use our knowledge of the schema to generate constants (or perfect hash for constant key lookup), to avoid these allocations.
model/modeldecoder/v2/simdjson.go
Outdated
return err | ||
} | ||
|
||
func decodeElements(obj *simdjson.Object, key string, out interface{}) 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.
Do you envision that we will generate type-specific decodeElements functions, or a single one like this with reflection?
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.
Haven't really thought about it, but now that you mention it it should also be possible to generate dedicated decode functions here per key.
model/modeldecoder/v2/simdjson.go
Outdated
func elementToMetadata(key string, elem simdjson.Element, m *Metadata) error { | ||
switch key { | ||
case "cloud.account.id": | ||
if elem.Type == simdjson.TypeString { |
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.
If we silently ignore other types, how will we enforce type validation? Perhaps we should check elem.Type != simdjson.TypeNull
, and then just call elem.Iter.String()
which will return an error if it's not a string?
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 point, will change that
9cd5218
to
313a4e2
Compare
jenkins run hey-apm tests please |
1 similar comment
jenkins run hey-apm tests please |
1c456f0
to
e50dbfc
Compare
Add transaction model to modeldecoder/rumv3` Create mapping function Create decoder and change processor
e50dbfc
to
10ef541
Compare
Closing in favor of #4261 |
Motivation/summary
This is the first step for changing the JSON decoding and validation. The PR introduces dedicated
modeldecoder
models with json tags for thev2
andv3 rum
API. Thegenerated
files are not yet generated, but give an outlook for what should be generated at the end.The next steps are to
Some first benchmarks comparing the decoding step of
metadata
suggest ~3 times less allocations, using the standard lib json decoder.Checklist
I have considered changes for:
How to test these changes
Related issues