Skip to content
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

Conversation

atingchen
Copy link
Contributor

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.

@atingchen atingchen requested review from a team and tigrannajaryan May 26, 2022 14:12
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 26, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@hanjm hanjm left a 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.

return kv
}

func readAnyValue(iter *jsoniter.Iterator, f string) otlpcommon.AnyValue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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

if assert.Error(t, iter.Error) {
assert.Contains(t, iter.Error.Error(), "unknown field")
}
}
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it

@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jun 16, 2022
@hanjm
Copy link
Member

hanjm commented Jun 16, 2022

still valid

@github-actions github-actions bot removed the Stale label Jun 17, 2022
@codecov
Copy link

codecov bot commented Jun 22, 2022

Codecov Report

Merging #5433 (417c99d) into main (9e90e25) will increase coverage by 0.28%.
The diff coverage is 98.47%.

@@            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     
Impacted Files Coverage Δ
pdata/pmetric/json.go 97.94% <98.11%> (-2.06%) ⬇️
pdata/internal/json/common.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@tigrannajaryan
Copy link
Member

@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.

@atingchen atingchen closed this Jun 22, 2022
@atingchen
Copy link
Contributor Author

@tigrannajaryan Thank you for your comments. I will fix it as soon as possible

@atingchen atingchen reopened this Jun 22, 2022
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 10, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@tigrannajaryan
Copy link
Member

Please make sure EasyCLA passes and there are no irrelevant changes.

@atingchen atingchen force-pushed the feature/lookchen-add-jsoniter-unmarshaller branch 2 times, most recently from 6d8da86 to 9a5b5a0 Compare July 12, 2022 11:27
@atingchen
Copy link
Contributor Author

It is caused by the error of executing the command merge, and it has been solved now

@tigrannajaryan
Copy link
Member

Please make sure the build passes. Preferably you should do this before creating a PR. make with various targets can be run locally.

@atingchen atingchen force-pushed the feature/lookchen-add-jsoniter-unmarshaller branch from 9a5b5a0 to 6860a53 Compare July 17, 2022 09:38
@tigrannajaryan
Copy link
Member

@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?

@atingchen atingchen force-pushed the feature/lookchen-add-jsoniter-unmarshaller branch from 5aa8020 to dec0094 Compare July 23, 2022 08:37
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)
Copy link
Member

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?

Copy link
Contributor Author

@atingchen atingchen Jul 26, 2022

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.

Copy link
Member

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

@Aneurysm9
Copy link
Member

@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?

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.

@atingchen
Copy link
Contributor Author

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

@atingchen atingchen force-pushed the feature/lookchen-add-jsoniter-unmarshaller branch from dec0094 to 9c97c4b Compare August 6, 2022 04:44
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping on this

return kv
}

func readAnyValue(iter *jsoniter.Iterator, f string) otlpcommon.AnyValue {
Copy link
Member

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

Copy link
Member

@bogdandrutu bogdandrutu left a 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"

@atingchen atingchen force-pushed the feature/lookchen-add-jsoniter-unmarshaller branch from 6416178 to ac4a9b9 Compare August 16, 2022 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants