Skip to content

Commit 3213ad0

Browse files
authored
[chore][pkg/ottl] Move symbol tables into internal/ctx packages (#38145)
This is another small step to normalize the ottl contexts.
1 parent d22aafc commit 3213ad0

File tree

11 files changed

+107
-70
lines changed

11 files changed

+107
-70
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package ctxdatapoint // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxdatapoint"
5+
6+
import (
7+
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
8+
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxmetric"
9+
)
10+
11+
var SymbolTable = func() map[ottl.EnumSymbol]ottl.Enum {
12+
st := map[ottl.EnumSymbol]ottl.Enum{
13+
"FLAG_NONE": 0,
14+
"FLAG_NO_RECORDED_VALUE": 1,
15+
}
16+
for k, v := range ctxmetric.SymbolTable {
17+
st[k] = v
18+
}
19+
return st
20+
}()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package ctxlog // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxlog"
5+
6+
import (
7+
"go.opentelemetry.io/collector/pdata/plog"
8+
9+
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
10+
)
11+
12+
var SymbolTable = map[ottl.EnumSymbol]ottl.Enum{
13+
"SEVERITY_NUMBER_UNSPECIFIED": ottl.Enum(plog.SeverityNumberUnspecified),
14+
"SEVERITY_NUMBER_TRACE": ottl.Enum(plog.SeverityNumberTrace),
15+
"SEVERITY_NUMBER_TRACE2": ottl.Enum(plog.SeverityNumberTrace2),
16+
"SEVERITY_NUMBER_TRACE3": ottl.Enum(plog.SeverityNumberTrace3),
17+
"SEVERITY_NUMBER_TRACE4": ottl.Enum(plog.SeverityNumberTrace4),
18+
"SEVERITY_NUMBER_DEBUG": ottl.Enum(plog.SeverityNumberDebug),
19+
"SEVERITY_NUMBER_DEBUG2": ottl.Enum(plog.SeverityNumberDebug2),
20+
"SEVERITY_NUMBER_DEBUG3": ottl.Enum(plog.SeverityNumberDebug3),
21+
"SEVERITY_NUMBER_DEBUG4": ottl.Enum(plog.SeverityNumberDebug4),
22+
"SEVERITY_NUMBER_INFO": ottl.Enum(plog.SeverityNumberInfo),
23+
"SEVERITY_NUMBER_INFO2": ottl.Enum(plog.SeverityNumberInfo2),
24+
"SEVERITY_NUMBER_INFO3": ottl.Enum(plog.SeverityNumberInfo3),
25+
"SEVERITY_NUMBER_INFO4": ottl.Enum(plog.SeverityNumberInfo4),
26+
"SEVERITY_NUMBER_WARN": ottl.Enum(plog.SeverityNumberWarn),
27+
"SEVERITY_NUMBER_WARN2": ottl.Enum(plog.SeverityNumberWarn2),
28+
"SEVERITY_NUMBER_WARN3": ottl.Enum(plog.SeverityNumberWarn3),
29+
"SEVERITY_NUMBER_WARN4": ottl.Enum(plog.SeverityNumberWarn4),
30+
"SEVERITY_NUMBER_ERROR": ottl.Enum(plog.SeverityNumberError),
31+
"SEVERITY_NUMBER_ERROR2": ottl.Enum(plog.SeverityNumberError2),
32+
"SEVERITY_NUMBER_ERROR3": ottl.Enum(plog.SeverityNumberError3),
33+
"SEVERITY_NUMBER_ERROR4": ottl.Enum(plog.SeverityNumberError4),
34+
"SEVERITY_NUMBER_FATAL": ottl.Enum(plog.SeverityNumberFatal),
35+
"SEVERITY_NUMBER_FATAL2": ottl.Enum(plog.SeverityNumberFatal2),
36+
"SEVERITY_NUMBER_FATAL3": ottl.Enum(plog.SeverityNumberFatal3),
37+
"SEVERITY_NUMBER_FATAL4": ottl.Enum(plog.SeverityNumberFatal4),
38+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package ctxmetric // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxmetric"
5+
6+
import (
7+
"go.opentelemetry.io/collector/pdata/pmetric"
8+
9+
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
10+
)
11+
12+
var SymbolTable = map[ottl.EnumSymbol]ottl.Enum{
13+
"AGGREGATION_TEMPORALITY_UNSPECIFIED": ottl.Enum(pmetric.AggregationTemporalityUnspecified),
14+
"AGGREGATION_TEMPORALITY_DELTA": ottl.Enum(pmetric.AggregationTemporalityDelta),
15+
"AGGREGATION_TEMPORALITY_CUMULATIVE": ottl.Enum(pmetric.AggregationTemporalityCumulative),
16+
"METRIC_DATA_TYPE_NONE": ottl.Enum(pmetric.MetricTypeEmpty),
17+
"METRIC_DATA_TYPE_GAUGE": ottl.Enum(pmetric.MetricTypeGauge),
18+
"METRIC_DATA_TYPE_SUM": ottl.Enum(pmetric.MetricTypeSum),
19+
"METRIC_DATA_TYPE_HISTOGRAM": ottl.Enum(pmetric.MetricTypeHistogram),
20+
"METRIC_DATA_TYPE_EXPONENTIAL_HISTOGRAM": ottl.Enum(pmetric.MetricTypeExponentialHistogram),
21+
"METRIC_DATA_TYPE_SUMMARY": ottl.Enum(pmetric.MetricTypeSummary),
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package ctxspan // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxspan"
5+
6+
import (
7+
"go.opentelemetry.io/collector/pdata/ptrace"
8+
9+
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
10+
)
11+
12+
var SymbolTable = map[ottl.EnumSymbol]ottl.Enum{
13+
"SPAN_KIND_UNSPECIFIED": ottl.Enum(ptrace.SpanKindUnspecified),
14+
"SPAN_KIND_INTERNAL": ottl.Enum(ptrace.SpanKindInternal),
15+
"SPAN_KIND_SERVER": ottl.Enum(ptrace.SpanKindServer),
16+
"SPAN_KIND_CLIENT": ottl.Enum(ptrace.SpanKindClient),
17+
"SPAN_KIND_PRODUCER": ottl.Enum(ptrace.SpanKindProducer),
18+
"SPAN_KIND_CONSUMER": ottl.Enum(ptrace.SpanKindConsumer),
19+
"STATUS_CODE_UNSET": ottl.Enum(ptrace.StatusCodeUnset),
20+
"STATUS_CODE_OK": ottl.Enum(ptrace.StatusCodeOk),
21+
"STATUS_CODE_ERROR": ottl.Enum(ptrace.StatusCodeError),
22+
}

pkg/ottl/contexts/internal/metric.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ type MetricContext interface {
1717
GetMetric() pmetric.Metric
1818
}
1919

20-
var MetricSymbolTable = map[ottl.EnumSymbol]ottl.Enum{
21-
"AGGREGATION_TEMPORALITY_UNSPECIFIED": ottl.Enum(pmetric.AggregationTemporalityUnspecified),
22-
"AGGREGATION_TEMPORALITY_DELTA": ottl.Enum(pmetric.AggregationTemporalityDelta),
23-
"AGGREGATION_TEMPORALITY_CUMULATIVE": ottl.Enum(pmetric.AggregationTemporalityCumulative),
24-
"METRIC_DATA_TYPE_NONE": ottl.Enum(pmetric.MetricTypeEmpty),
25-
"METRIC_DATA_TYPE_GAUGE": ottl.Enum(pmetric.MetricTypeGauge),
26-
"METRIC_DATA_TYPE_SUM": ottl.Enum(pmetric.MetricTypeSum),
27-
"METRIC_DATA_TYPE_HISTOGRAM": ottl.Enum(pmetric.MetricTypeHistogram),
28-
"METRIC_DATA_TYPE_EXPONENTIAL_HISTOGRAM": ottl.Enum(pmetric.MetricTypeExponentialHistogram),
29-
"METRIC_DATA_TYPE_SUMMARY": ottl.Enum(pmetric.MetricTypeSummary),
30-
}
31-
3220
func MetricPathGetSetter[K MetricContext](path ottl.Path[K]) (ottl.GetSetter[K], error) {
3321
if path == nil {
3422
return nil, ctxerror.New("nil", "nil", ctxmetric.Name, ctxmetric.DocRef)

pkg/ottl/contexts/internal/span.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ type SpanContext interface {
2424
GetSpan() ptrace.Span
2525
}
2626

27-
var SpanSymbolTable = map[ottl.EnumSymbol]ottl.Enum{
28-
"SPAN_KIND_UNSPECIFIED": ottl.Enum(ptrace.SpanKindUnspecified),
29-
"SPAN_KIND_INTERNAL": ottl.Enum(ptrace.SpanKindInternal),
30-
"SPAN_KIND_SERVER": ottl.Enum(ptrace.SpanKindServer),
31-
"SPAN_KIND_CLIENT": ottl.Enum(ptrace.SpanKindClient),
32-
"SPAN_KIND_PRODUCER": ottl.Enum(ptrace.SpanKindProducer),
33-
"SPAN_KIND_CONSUMER": ottl.Enum(ptrace.SpanKindConsumer),
34-
"STATUS_CODE_UNSET": ottl.Enum(ptrace.StatusCodeUnset),
35-
"STATUS_CODE_OK": ottl.Enum(ptrace.StatusCodeOk),
36-
"STATUS_CODE_ERROR": ottl.Enum(ptrace.StatusCodeError),
37-
}
38-
3927
func SpanPathGetSetter[K SpanContext](lowerContext string, path ottl.Path[K]) (ottl.GetSetter[K], error) {
4028
if path == nil {
4129
return nil, ctxerror.New("nil", "nil", ctxspan.Name, ctxspan.DocRef)

pkg/ottl/contexts/ottldatapoint/datapoint.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,9 @@ func NewConditionSequence(conditions []*ottl.Condition[TransformContext], teleme
191191
return c
192192
}
193193

194-
var symbolTable = map[ottl.EnumSymbol]ottl.Enum{
195-
"FLAG_NONE": 0,
196-
"FLAG_NO_RECORDED_VALUE": 1,
197-
}
198-
199-
func init() {
200-
for k, v := range internal.MetricSymbolTable {
201-
symbolTable[k] = v
202-
}
203-
}
204-
205194
func parseEnum(val *ottl.EnumSymbol) (*ottl.Enum, error) {
206195
if val != nil {
207-
if enum, ok := symbolTable[*val]; ok {
196+
if enum, ok := ctxdatapoint.SymbolTable[*val]; ok {
208197
return &enum, nil
209198
}
210199
return nil, fmt.Errorf("enum symbol, %s, not found", *val)

pkg/ottl/contexts/ottllog/log.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -186,37 +186,9 @@ func NewConditionSequence(conditions []*ottl.Condition[TransformContext], teleme
186186
return c
187187
}
188188

189-
var symbolTable = map[ottl.EnumSymbol]ottl.Enum{
190-
"SEVERITY_NUMBER_UNSPECIFIED": ottl.Enum(plog.SeverityNumberUnspecified),
191-
"SEVERITY_NUMBER_TRACE": ottl.Enum(plog.SeverityNumberTrace),
192-
"SEVERITY_NUMBER_TRACE2": ottl.Enum(plog.SeverityNumberTrace2),
193-
"SEVERITY_NUMBER_TRACE3": ottl.Enum(plog.SeverityNumberTrace3),
194-
"SEVERITY_NUMBER_TRACE4": ottl.Enum(plog.SeverityNumberTrace4),
195-
"SEVERITY_NUMBER_DEBUG": ottl.Enum(plog.SeverityNumberDebug),
196-
"SEVERITY_NUMBER_DEBUG2": ottl.Enum(plog.SeverityNumberDebug2),
197-
"SEVERITY_NUMBER_DEBUG3": ottl.Enum(plog.SeverityNumberDebug3),
198-
"SEVERITY_NUMBER_DEBUG4": ottl.Enum(plog.SeverityNumberDebug4),
199-
"SEVERITY_NUMBER_INFO": ottl.Enum(plog.SeverityNumberInfo),
200-
"SEVERITY_NUMBER_INFO2": ottl.Enum(plog.SeverityNumberInfo2),
201-
"SEVERITY_NUMBER_INFO3": ottl.Enum(plog.SeverityNumberInfo3),
202-
"SEVERITY_NUMBER_INFO4": ottl.Enum(plog.SeverityNumberInfo4),
203-
"SEVERITY_NUMBER_WARN": ottl.Enum(plog.SeverityNumberWarn),
204-
"SEVERITY_NUMBER_WARN2": ottl.Enum(plog.SeverityNumberWarn2),
205-
"SEVERITY_NUMBER_WARN3": ottl.Enum(plog.SeverityNumberWarn3),
206-
"SEVERITY_NUMBER_WARN4": ottl.Enum(plog.SeverityNumberWarn4),
207-
"SEVERITY_NUMBER_ERROR": ottl.Enum(plog.SeverityNumberError),
208-
"SEVERITY_NUMBER_ERROR2": ottl.Enum(plog.SeverityNumberError2),
209-
"SEVERITY_NUMBER_ERROR3": ottl.Enum(plog.SeverityNumberError3),
210-
"SEVERITY_NUMBER_ERROR4": ottl.Enum(plog.SeverityNumberError4),
211-
"SEVERITY_NUMBER_FATAL": ottl.Enum(plog.SeverityNumberFatal),
212-
"SEVERITY_NUMBER_FATAL2": ottl.Enum(plog.SeverityNumberFatal2),
213-
"SEVERITY_NUMBER_FATAL3": ottl.Enum(plog.SeverityNumberFatal3),
214-
"SEVERITY_NUMBER_FATAL4": ottl.Enum(plog.SeverityNumberFatal4),
215-
}
216-
217189
func parseEnum(val *ottl.EnumSymbol) (*ottl.Enum, error) {
218190
if val != nil {
219-
if enum, ok := symbolTable[*val]; ok {
191+
if enum, ok := ctxlog.SymbolTable[*val]; ok {
220192
return &enum, nil
221193
}
222194
return nil, fmt.Errorf("enum symbol, %s, not found", *val)

pkg/ottl/contexts/ottlmetric/metrics.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,9 @@ func NewConditionSequence(conditions []*ottl.Condition[TransformContext], teleme
159159
return c
160160
}
161161

162-
var symbolTable = internal.MetricSymbolTable
163-
164162
func parseEnum(val *ottl.EnumSymbol) (*ottl.Enum, error) {
165163
if val != nil {
166-
if enum, ok := symbolTable[*val]; ok {
164+
if enum, ok := ctxmetric.SymbolTable[*val]; ok {
167165
return &enum, nil
168166
}
169167
return nil, fmt.Errorf("enum symbol, %s, not found", *val)

pkg/ottl/contexts/ottlspan/span.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func NewConditionSequence(conditions []*ottl.Condition[TransformContext], teleme
166166

167167
func parseEnum(val *ottl.EnumSymbol) (*ottl.Enum, error) {
168168
if val != nil {
169-
if enum, ok := internal.SpanSymbolTable[*val]; ok {
169+
if enum, ok := ctxspan.SymbolTable[*val]; ok {
170170
return &enum, nil
171171
}
172172
return nil, fmt.Errorf("enum symbol, %s, not found", *val)

0 commit comments

Comments
 (0)