-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[exporter/elasticsearch] Implement elasticsearch.mapping.hints attribute handling for data points in OTel mapping mode #35479
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f5d42d5
Add aggregate_metric_double hint
carsonip aa6d0b0
Update dynamic template
carsonip 90d39df
Use doc count hint
carsonip 167b962
Merge branch 'main' into mapping-hint
carsonip faafd42
Remove FIXME
carsonip 082a220
Preprocess hints a bit
carsonip f49a400
Fix exporter test
carsonip 17b8df5
Add aggregate_metric_double hint test
carsonip 0129c45
Rename func
carsonip b438056
make lint
carsonip e2ae342
Preallocate slice
carsonip 97543bd
Only enable mapping hints for otel mode
carsonip 1887649
Add changelog
carsonip 9aae60d
Only handle mapping hint key at data point level
carsonip 2731b3a
make goporto
carsonip 5504eab
Merge branch 'main' into mapping-hint
carsonip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package elasticsearchexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter" | ||
|
||
import ( | ||
"slices" | ||
|
||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
) | ||
|
||
const ( | ||
mappingHintsAttrKey = "elasticsearch.mapping.hints" | ||
) | ||
|
||
type mappingHint string | ||
|
||
const ( | ||
hintAggregateMetricDouble mappingHint = "aggregate_metric_double" | ||
hintDocCount mappingHint = "_doc_count" | ||
) | ||
|
||
type mappingHintGetter struct { | ||
hints []mappingHint | ||
} | ||
|
||
func newMappingHintGetter(attr pcommon.Map) (g mappingHintGetter) { | ||
v, ok := attr.Get(mappingHintsAttrKey) | ||
if !ok || v.Type() != pcommon.ValueTypeSlice { | ||
return | ||
} | ||
slice := v.Slice() | ||
g.hints = slices.Grow(g.hints, slice.Len()) | ||
for i := 0; i < slice.Len(); i++ { | ||
g.hints = append(g.hints, mappingHint(slice.At(i).Str())) | ||
} | ||
return | ||
} | ||
|
||
func (g mappingHintGetter) HasMappingHint(hint mappingHint) bool { | ||
return slices.Contains(g.hints, hint) | ||
} |
This file contains hidden or 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,88 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package elasticsearchexporter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
) | ||
|
||
func TestHasHint(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
attrsFunc func() pcommon.Map | ||
hint mappingHint | ||
want bool | ||
}{ | ||
{ | ||
name: "empty map", | ||
attrsFunc: pcommon.NewMap, | ||
hint: hintAggregateMetricDouble, | ||
want: false, | ||
}, | ||
{ | ||
name: "bad type", | ||
attrsFunc: func() pcommon.Map { | ||
m := pcommon.NewMap() | ||
m.PutBool(mappingHintsAttrKey, true) | ||
return m | ||
}, | ||
hint: hintAggregateMetricDouble, | ||
want: false, | ||
}, | ||
{ | ||
name: "bad inner type", | ||
attrsFunc: func() pcommon.Map { | ||
m := pcommon.NewMap() | ||
s := m.PutEmptySlice(mappingHintsAttrKey) | ||
s.AppendEmpty().SetBool(true) | ||
return m | ||
}, | ||
hint: hintAggregateMetricDouble, | ||
want: false, | ||
}, | ||
{ | ||
name: "hit", | ||
attrsFunc: func() pcommon.Map { | ||
m := pcommon.NewMap() | ||
s := m.PutEmptySlice(mappingHintsAttrKey) | ||
s.AppendEmpty().SetStr(string(hintAggregateMetricDouble)) | ||
return m | ||
}, | ||
hint: hintAggregateMetricDouble, | ||
want: true, | ||
}, | ||
{ | ||
name: "hit 2nd", | ||
attrsFunc: func() pcommon.Map { | ||
m := pcommon.NewMap() | ||
s := m.PutEmptySlice(mappingHintsAttrKey) | ||
s.AppendEmpty().SetStr(string(hintDocCount)) | ||
s.AppendEmpty().SetStr(string(hintAggregateMetricDouble)) | ||
return m | ||
}, | ||
hint: hintAggregateMetricDouble, | ||
want: true, | ||
}, | ||
{ | ||
name: "miss", | ||
attrsFunc: func() pcommon.Map { | ||
m := pcommon.NewMap() | ||
s := m.PutEmptySlice(mappingHintsAttrKey) | ||
s.AppendEmpty().SetStr(string(hintDocCount)) | ||
return m | ||
}, | ||
hint: hintAggregateMetricDouble, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.want, newMappingHintGetter(tt.attrsFunc()).HasMappingHint(tt.hint)) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[to reviewer] Removing changelog for previous doc count PR as this PR supersedes it. It does not make sense for the doc count PR changelog to be in the release notes of the next version if it is not relevant.