-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/elasticsearch] Implement elasticsearch.mapping.hints attrib…
…ute handling for data points in OTel mapping mode (#35479) **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.--> Supersedes #35348 elasticsearch.mapping.hints takes a slice of strings. `_doc_count` enables emitting `_doc_count` for the document. `aggregate_metric_double` causes histogram or exponential histogram to be emitted as aggregate_metric_double. **Link to tracking Issue:** <Issue number if applicable> **Testing:** <Describe what testing was performed and which tests were added.> **Documentation:** <Describe the documentation added.>
- Loading branch information
Showing
7 changed files
with
254 additions
and
24 deletions.
There are no files selected for viewing
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,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 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.