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

[chore][exporter/elasticsearch] refactor, consolidate exporters #33318

Merged

Conversation

axw
Copy link
Contributor

@axw axw commented May 31, 2024

Description:

Replace the elasticsearchTracesExporter and elasticsearchLogsExporter with a single elasticsearchExporter that handles both.

Tests have been cleaned up to reduce repetition between traces and logs exporters, e.g. config validation tests have been moved to more specific TestConfig* tests. To enable this, some further validation has been added to Config.Validate, which was previously done only when reaching the go-elasticsearch code when constructing exporters.

Various tests have been updated to use the public APIs rather than internal functions, so we're testing behaviour rather than the implementation; this will enable further refactoring without breaking tests.

Link to tracking Issue:

None

Testing:

Ran the unit tests. This is a non-functional change.

Documentation:

N/A, non-functional change.

Replace the elasticsearchTracesExporter and
elasticsearchLogsExporter with a single
elasticsearchExporter that handles both.

Tests have been cleaned up to reduce repetition
between traces and logs exporters, e.g. config
validation tests have been moved to more
specific TestConfig* tests. To enable this,
some further validation has been added to
Config.Validate, which was previousy done only
when reaching the go-elasticsearch code when
constructing exporters.

Various tests have been updated to use the
public APIs rather than internal functions,
so we're testing behaviour rather than the
implementation; this will enable further
refactoring without breaking tests.
@axw axw changed the title [exporter/elasticsearch] refactor, consolidate exporters [chore][exporter/elasticsearch] refactor, consolidate exporters May 31, 2024
@axw axw marked this pull request as ready for review May 31, 2024 07:50
@axw axw requested review from a team and jpkrohling May 31, 2024 07:50
Copy link
Contributor

@carsonip carsonip left a comment

Choose a reason for hiding this comment

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

looks good with 1 nit

exporter/elasticsearchexporter/utils_test.go Outdated Show resolved Hide resolved
Copy link
Member

@lahsivjar lahsivjar left a comment

Choose a reason for hiding this comment

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

A minor comment and a non-blocking discussion point.

exporter/elasticsearchexporter/utils_test.go Outdated Show resolved Hide resolved
@@ -28,7 +27,7 @@ type elasticsearchTracesExporter struct {
model mappingModel
}

func newTracesExporter(logger *zap.Logger, cfg *Config) (*elasticsearchTracesExporter, error) {
func newExporter(logger *zap.Logger, cfg *Config, index string, dynamicIndex bool) (*elasticsearchExporter, error) {
Copy link
Member

Choose a reason for hiding this comment

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

[Non blocking/discussion] I was thinking of refactoring this a bit more (possibly in the future) to use the same instance of the exporter (and thus the bulk indexer) for both logs and traces (and eventually metrics) - IMO, this will allow us to better reason about resource consumption.

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 like the idea, but I'm unsure how one would go about it. Is there any prior art? Probably worth opening an issue so this idea and any discussion doesn't get lost.

Copy link
Member

Choose a reason for hiding this comment

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

There is SharedComponent however we can't probably use it as is.

Probably worth opening an issue so this idea and any discussion doesn't get lost.

Sounds good, I will create an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Created an issue: #33326

I have a few ideas on how this could look like. Will create a followup PR for discussions after this PR is merged.

Co-authored-by: Carson Ip <carsonip@users.noreply.github.com>
@axw axw requested a review from carsonip May 31, 2024 10:56
@@ -28,7 +27,6 @@ elasticsearch/log:
endpoints: [http://localhost:9200]
logs_index: my_log_index
timeout: 2m
cloudid: TRNMxjXlNJEt
Copy link
Member

Choose a reason for hiding this comment

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

Looks no breaking changes this PR, except here why delete cloudid? others LGTM

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 had to remove it because of the changes to Config.Validate:

  • this cloudid value is invalid
  • it's not permitted to have both cloudid and endpoints set

These would already have caused failures before, but only when creating the exporter, I just moved it to Config.Validate so the error occurs sooner.

There's a new valid entry called elasticsearch/cloudid which covers it.

Copy link
Member

@andrzej-stencel andrzej-stencel left a comment

Choose a reason for hiding this comment

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

👍

@andrzej-stencel andrzej-stencel merged commit 4148641 into open-telemetry:main Jun 3, 2024
162 checks passed
@github-actions github-actions bot added this to the next release milestone Jun 3, 2024
@axw axw deleted the elasticsearchexporter-refactor branch June 4, 2024 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants