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

[exporter/kafka] support custom metrics & logs marshalers #8248

Closed
wants to merge 2 commits into from

Conversation

faceair
Copy link

@faceair faceair commented Mar 2, 2022

Description:

I'm trying to use opentelemetry-collector to collect logs, and the format of the logs input to kafka is our internal format, so I need the kafka exporter to support the customization as well.
The kafka exporter already supports custom marshaler for trace, so adding a new marshaler for log & metrics should do the same.

@faceair faceair requested review from a team and pmm-sumo March 2, 2022 08:30
@pmm-sumo
Copy link
Contributor

pmm-sumo commented Mar 2, 2022

@faceair could you include unit tests for the newly added functions?

@faceair
Copy link
Author

faceair commented Mar 12, 2022

Hi @pmm-sumo , I have added unit tests, please help review again.

@pmm-sumo pmm-sumo added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Mar 13, 2022
cfg.Metadata.Full = false

t.Run("custom_encoding", func(t *testing.T) {
cfg.Encoding = cm.Encoding()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this tests actually are only somewhat useful. They only check that Encoding() function yields a result and factory accepts WithLogsMarshalers/WithMetricMarshalers.

TBH, the currently existing test (the only one which calls WithTracesMarshallers) is not very useful either for the same reasons.

Perhaps that's OK (what's your guidance on this @MovieStoreGuy @pavolloffay?). I was thinking that maybe some sorts of tests matching non default marshaler encoding could be created instead, but perhaps it's too much of a stretch for a relatively simple API change here

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies, didn't mean to leave this for so long. Github notifications are not my friend for some time now.

Currently late evening atm, so I come to review back tomorrow to full understand what is happening.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree with @pmm-sumo.

The minimal required testing of custom encodings is that the encoded data matches a known output.
Testing that the set encoding matches the expected result is just the start.

@bgranetzke
Copy link
Contributor

I have a use case to plug custom metric/log marshalers as well (keyed messages). Thank you for the PR.

@bgranetzke
Copy link
Contributor

bgranetzke commented Apr 5, 2022

I think the linter just wants the }'s on a new line like the prior code:
type customTracesMarshaler struct {}
to

type customTracesMarshaler struct {
}

However, I'm struggling to associate the changes in this PR to something that might consume more memory for TestMetricsFromFile``

Copy link
Contributor

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

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

There is a few things that I care about:

  1. Return an error in tests instead of panicing (avoid flakey tests and follow contribution guide)
  2. Further details on how an end user would configure this
  3. Update the KafkaReceiver to also include additional log and metric marshalers (Haven't verified myself if it does)
  4. Include validate on the data produced by custom encoding within tests.

Once these items are addressed, I am happy to approve this PR :)

Comment on lines +59 to +60
// WithMetricsMarshalers adds metricsMarshalers.
func WithMetricsMarshalers(metricsMarshalers ...MetricsMarshaler) FactoryOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this being references anywhere within that would allow for these to ether be added by default or added via some configuration.

Can I ask how you'd want someone to use this in their exporter?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MovieStoreGuy I think the question for how to use these factory options predates this PR. The WithTraceMarshalers() option existed before this PR. I've attempted 2 methods to utilize the custom options:

  1. pass in explicit options to NewFactory() in components.go. However, this isn't supported with the collector-builder and I could no longer use it
  2. create a custom exporter factory where the NewFactory() just delegates to kafkaexporter.NewFactory() with additional options

Taking a step back, are you aware of precedence for extending subcomponents of exporters/receivers? At a high level, extensions for auth looked close, but when I looked deeper the requirements for high-level abstractions to exist in the collector didn't feel right either (e.g go.opentelemetry.io/collector/config/configauth). I know you are aware #8272 which would have been less messy if custom marshalers could be more easily added.

var _ TracesMarshaler = (*customTracesMarshaler)(nil)

func (c customTracesMarshaler) Marshal(_ pdata.Traces, topic string) ([]*sarama.ProducerMessage, error) {
panic("implement me")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not exactly sure why this should panic in test code, what are you trying to achieve here?

var _ LogsMarshaler = (*customLogsMarshaler)(nil)

func (c customLogsMarshaler) Marshal(logs pdata.Logs, topic string) ([]*sarama.ProducerMessage, error) {
panic("implement me")
Copy link
Contributor

Choose a reason for hiding this comment

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

I really worry about panicing in tests, it isn't go idiomatic and not discouraged by the contribution guide.

Can I ask what you're wanting to achieve here?

cfg.Metadata.Full = false

t.Run("custom_encoding", func(t *testing.T) {
cfg.Encoding = cm.Encoding()
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree with @pmm-sumo.

The minimal required testing of custom encodings is that the encoded data matches a known output.
Testing that the set encoding matches the expected result is just the start.

@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 Apr 23, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 7, 2022

Closed as inactive. Feel free to reopen if this PR is still being worked on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants