-
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.
[chore] [exporter/elasticsearch] Extract mapping hints into an intern…
…al elasticsearch module (#37235) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This is the first (or the first after several attempts canceled for various reasons) attempt to split data serialization/encoding into multiple packages, so we can separate the module per encoding type. See #37207 as the previous attempt which was canceled due to another refactoring that required more ground splitting first. --------- Co-authored-by: Tim Rühsen <tim.ruehsen@gmx.de>
- Loading branch information
1 parent
49d5b89
commit 7ce882e
Showing
5 changed files
with
81 additions
and
76 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
exporter/elasticsearchexporter/internal/elasticsearch/mapping_hint.go
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,44 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package elasticsearch // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter/internal/elasticsearch" | ||
|
||
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 | ||
} | ||
|
||
// NewMappingHintGetter creates a new MappingHintGetter | ||
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 := range slice.Len() { | ||
g.hints = append(g.hints, MappingHint(slice.At(i).Str())) | ||
} | ||
return | ||
} | ||
|
||
// HasMappingHint checks whether the getter contains the requested mapping hint | ||
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
This file was deleted.
Oops, something went wrong.
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