-
Notifications
You must be signed in to change notification settings - Fork 1.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
Implement unmarshal metrics with jsoniter #5433
Implement unmarshal metrics with jsoniter #5433
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.
💪
General LGTM. Just two small nits.
pdata/pmetric/json.go
Outdated
return kv | ||
} | ||
|
||
func readAnyValue(iter *jsoniter.Iterator, f string) otlpcommon.AnyValue { |
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 common function could be move to some place. https://github.com/open-telemetry/opentelemetry-collector/tree/main/pdata/internal
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 agree, but I'm not sure where it's appropriate to move it。
There seems to be no suitable place under package internal
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.
@bogdandrutu @dmitryax Could you help review, thank you.
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.
Let's use a pdata/internal/json
pdata/pmetric/json_test.go
Outdated
if assert.Error(t, iter.Error) { | ||
assert.Contains(t, iter.Error.Error(), "unknown field") | ||
} | ||
} |
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.
It will be better to add benchmark compare to jsonpb.
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 will do it
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
still valid |
Codecov Report
@@ Coverage Diff @@
## main #5433 +/- ##
==========================================
+ Coverage 91.44% 91.72% +0.28%
==========================================
Files 196 197 +1
Lines 11958 12475 +517
==========================================
+ Hits 10935 11443 +508
- Misses 808 816 +8
- Partials 215 216 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@atingchen thank you for the PR. I started reviewing it but I see that the build is failing. Can you please fix the build to make sure all github actions pass so that we can then review the PR. Faster performance is great, however we need to make there is very thorough coverage by the tests since this deals with data received externally. |
@tigrannajaryan Thank you for your comments. I will fix it as soon as possible |
Please make sure EasyCLA passes and there are no irrelevant changes. |
6d8da86
to
9a5b5a0
Compare
It is caused by the error of executing the command |
Please make sure the build passes. Preferably you should do this before creating a PR. |
9a5b5a0
to
6860a53
Compare
@open-telemetry/collector-approvers please review. Question: do we need any additional precautions to ensure we did not break OTLP/JSON compatibility or the tests that are introduced are good enough? |
5aa8020
to
dec0094
Compare
CHANGELOG.md
Outdated
@@ -20,6 +20,7 @@ | |||
- Expose `pcommon.NewSliceFromRaw` function (#5679) | |||
- `loggingexporter`: create the exporter's logger from the service's logger (#5677) | |||
- Add `otelcol_exporter_queue_capacity` metrics show the collector's exporter queue capacity (#5475) | |||
- Add `jsoniter` Unmarshaller (#5433) |
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 should be more specific. Where is jsoniter
used? Is it added or replacing something? It looks like this only applies to metrics, is there a reason for that?
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.
Compare with jsonpb unmarshaller, jsoniter does not use reflect, more efficient, less GC pressure.
The ChangeLog will be more specific.
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.
It looks like this only applies to metrics, is there a reason for that?
Traces were done earlier: #4986
Is it possible to maintain the current implementation somewhere and add tests that demonstrate that the same JSON documents are unmarshalled to equivalent pdata structures by both implementations? I think that would give me the most confidence in the new implementation. It would also allow us to introduce this change with a feature gate, which would allow users who ran into issues we didn't test for to quickly revert to the old implementation. |
Thanks for your suggestion, I'll think about how to implement it |
dec0094
to
9c97c4b
Compare
CHANGELOG.md
Outdated
@@ -126,7 +126,7 @@ There isn't a valid core binary for this release. Use v0.57.2 instead. | |||
- Expose `pcommon.NewSliceFromRaw` function (#5679) | |||
- `loggingexporter`: create the exporter's logger from the service's logger (#5677) | |||
- Add `otelcol_exporter_queue_capacity` metrics show the collector's exporter queue capacity (#5475) | |||
- Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter (#5685) | |||
- Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter (#5685) |
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.
- Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter (#5685) | |
- Add support to handle 402, 413, 414, 431 http error code as permanent errors in OTLP exporter (#5685) |
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.
Ping on this
pdata/pmetric/json.go
Outdated
return kv | ||
} | ||
|
||
func readAnyValue(iter *jsoniter.Iterator, f string) otlpcommon.AnyValue { |
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.
Let's use a pdata/internal/json
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.
Fix lint issues
internal/json/common.go:21: File is not `goimports`-ed with -local go.opentelemetry.io/collector (goimports)
jsoniter "github.com/json-iterator/go"
internal/json/common_test.go:21: File is not `goimports`-ed with -local go.opentelemetry.io/collector (goimports)
"github.com/stretchr/testify/assert"
…etrics. 2. Some functions move to pdata/internal/json 3.Ignore unknown fields and have a debug log for them
6416178
to
ac4a9b9
Compare
Description:
I implement unmarshal metrics with jsoniter iterator parser, compare with jsonpb unmarshaller, jsoniter does not use reflect, more efficient, less GC pressure.
Link to tracking Issue: [#4986 ]
Testing:
unit test. construct a trace message, fill all the fields, use jsonpb marshal to json bytes, use jsoniter unmarshal to struct, test assert there are equal.