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/elasticsearch] Add OTel mapping mode for metrics #34248

Merged
merged 35 commits into from
Aug 19, 2024

Conversation

carsonip
Copy link
Contributor

@carsonip carsonip commented Jul 25, 2024

Description:

Add OTel mapping mode for metrics.

OTel mapping mode is a new mapping mode described in https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/elasticsearchexporter#elasticsearch-document-mapping

Link to tracking Issue:

Testing:

Added exporter test

Documentation:

@github-actions github-actions bot added the cmd/otelcontribcol otelcontribcol command label Aug 12, 2024
@carsonip carsonip changed the title [WIP][exporter/elasticsearch] OTel mapping mode for metrics [exporter/elasticsearch] Add OTel mapping mode for metrics Aug 13, 2024
// Move them to the top of the document and remove them from the record
attributeMap := dp.Attributes()

forEachDataStreamKey := func(fn func(key string)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactoring done in #34472

@carsonip carsonip marked this pull request as ready for review August 13, 2024 16:12
@carsonip carsonip requested review from a team and TylerHelmuth August 13, 2024 16:12
return nil
}

func metricDpToDynamicTemplate(metric pmetric.Metric, dp dataPoint) string {
Copy link
Contributor

@axw axw Aug 14, 2024

Choose a reason for hiding this comment

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

This might be a little bit hard to understand for someone not already familiar with all the details. Perhaps add a link to the metrics@mappings template, and explain that we're telling Elasticsearch which template to use for dynamic mapping?

Comment on lines +755 to +756
mapHashExcludeDataStreamAttr(hasher, scopeAttrs)
mapHashExcludeDataStreamAttr(hasher, dp.Attributes())
Copy link
Contributor

Choose a reason for hiding this comment

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

We're excluding them because docs are already grouped by resource, and data_stream.* is set in the resource attributes by the document router - right? Maybe worth another comment here?

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'll add a comment. It is because e.g. if both scope DS dataset and record level DS dataset are present, scope DS dataset will effectively be ignored, and will not affect the resulting document, as the record level one will be used. We'll risk duplicates if we factor it in during hashing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the other hand, documents are already passed into the function is already "sharded" by index name, which is also a reason why it isn't needed in hashing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for making me think more about it. ECS mode should use this mapHashExcludeDataStreamAttr as well.

Copy link
Contributor

@axw axw left a comment

Choose a reason for hiding this comment

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

LGTM! For otel mode I'm hoping that we can skip objmodel entirely, and encode data directly to JSON. IIANM duplicates should be impossible in otel mode, so I think that should be possible.

component: elasticsearchexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add OTel mapping mode for metrics
Copy link
Contributor

Choose a reason for hiding this comment

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

that's a bit mysterious, can you add to what mapping we map to?

Suggested change
note: Add OTel mapping mode for metrics
note: Add support for Elastic ECS data model mapping from OpenTelemetry metrics. See <URL> for the mapping.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Would be good to update the "Exporting metrics" section of the exporter's README to document which mapping modes are supported for metrics (ECS, OTel) and how they work.

Unrelated to this PR, after #34045 the README incorrectly says that only Sum and Gauge metric types are supported, this should also be updated.

@andrzej-stencel andrzej-stencel merged commit eb2c463 into open-telemetry:main Aug 19, 2024
154 checks passed
@github-actions github-actions bot added this to the next release milestone Aug 19, 2024
f7o pushed a commit to f7o/opentelemetry-collector-contrib that referenced this pull request Sep 12, 2024
…metry#34248)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Add OTel mapping mode for metrics.

OTel mapping mode is a new mapping mode described in
https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/elasticsearchexporter#elasticsearch-document-mapping

**Link to tracking Issue:** <Issue number if applicable>

**Testing:** <Describe what testing was performed and which tests were
added.>

Added exporter test

**Documentation:** <Describe the documentation added.>
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.

7 participants