forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/elasticsearch] Data stream routing based on
data_stream.*
…
… attributes (open-telemetry#33794) **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.--> Taking over from open-telemetry#33755 - Add data stream routing based on `data_stream.*` attributes - Refine metrics grouping to work with DS routing **Link to tracking Issue:** Closes open-telemetry#33755 Fixes open-telemetry#33756 **Testing:** <Describe what testing was performed and which tests were added.> See unit tests **Documentation:** <Describe the documentation added.> Updated readme --------- Co-authored-by: Andrzej Stencel <[email protected]> Co-authored-by: Andrew Wilkins <[email protected]>
- Loading branch information
1 parent
cbc04f3
commit 0814644
Showing
12 changed files
with
655 additions
and
274 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
.chloggen/elasticsearch-exporter-attribute-based-data-stream-routing.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: exporter/elasticsearch | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add data stream routing | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [33794, 33756] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | | ||
`data_stream.dataset` and `data_stream.namespace` in attributes will be respected when config `*_dynamic_index.enabled` is true. | ||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package elasticsearchexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter" | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
) | ||
|
||
func routeWithDefaults(defaultDSType, defaultDSDataset, defaultDSNamespace string) func( | ||
pcommon.Map, | ||
pcommon.Map, | ||
pcommon.Map, | ||
string, | ||
) string { | ||
return func( | ||
recordAttr pcommon.Map, | ||
scopeAttr pcommon.Map, | ||
resourceAttr pcommon.Map, | ||
fIndex string, | ||
) string { | ||
// Order: | ||
// 1. read data_stream.* from attributes | ||
// 2. read elasticsearch.index.* from attributes | ||
// 3. use default hardcoded data_stream.* | ||
dataset, datasetExists := getFromAttributes(dataStreamDataset, defaultDSDataset, recordAttr, scopeAttr, resourceAttr) | ||
namespace, namespaceExists := getFromAttributes(dataStreamNamespace, defaultDSNamespace, recordAttr, scopeAttr, resourceAttr) | ||
dataStreamMode := datasetExists || namespaceExists | ||
if !dataStreamMode { | ||
prefix, prefixExists := getFromAttributes(indexPrefix, "", resourceAttr, scopeAttr, recordAttr) | ||
suffix, suffixExists := getFromAttributes(indexSuffix, "", resourceAttr, scopeAttr, recordAttr) | ||
if prefixExists || suffixExists { | ||
return fmt.Sprintf("%s%s%s", prefix, fIndex, suffix) | ||
} | ||
} | ||
recordAttr.PutStr(dataStreamDataset, dataset) | ||
recordAttr.PutStr(dataStreamNamespace, namespace) | ||
recordAttr.PutStr(dataStreamType, defaultDSType) | ||
return fmt.Sprintf("%s-%s-%s", defaultDSType, dataset, namespace) | ||
} | ||
} | ||
|
||
// routeLogRecord returns the name of the index to send the log record to according to data stream routing attributes and prefix/suffix attributes. | ||
// This function may mutate record attributes. | ||
func routeLogRecord( | ||
record plog.LogRecord, | ||
scope pcommon.InstrumentationScope, | ||
resource pcommon.Resource, | ||
fIndex string, | ||
) string { | ||
route := routeWithDefaults(defaultDataStreamTypeLogs, defaultDataStreamDataset, defaultDataStreamNamespace) | ||
return route(record.Attributes(), scope.Attributes(), resource.Attributes(), fIndex) | ||
} | ||
|
||
// routeDataPoint returns the name of the index to send the data point to according to data stream routing attributes. | ||
// This function may mutate record attributes. | ||
func routeDataPoint( | ||
dataPoint pmetric.NumberDataPoint, | ||
scope pcommon.InstrumentationScope, | ||
resource pcommon.Resource, | ||
fIndex string, | ||
) string { | ||
route := routeWithDefaults(defaultDataStreamTypeMetrics, defaultDataStreamDataset, defaultDataStreamNamespace) | ||
return route(dataPoint.Attributes(), scope.Attributes(), resource.Attributes(), fIndex) | ||
} | ||
|
||
// routeSpan returns the name of the index to send the span to according to data stream routing attributes. | ||
// This function may mutate record attributes. | ||
func routeSpan( | ||
span ptrace.Span, | ||
scope pcommon.InstrumentationScope, | ||
resource pcommon.Resource, | ||
fIndex string, | ||
) string { | ||
route := routeWithDefaults(defaultDataStreamTypeTraces, defaultDataStreamDataset, defaultDataStreamNamespace) | ||
return route(span.Attributes(), scope.Attributes(), resource.Attributes(), fIndex) | ||
} |
Oops, something went wrong.