Skip to content

Commit c0a8b67

Browse files
committed
Change to not expose the context inferrer and removed the ignoreUnknownContext option
1 parent 2054289 commit c0a8b67

File tree

2 files changed

+25
-48
lines changed

2 files changed

+25
-48
lines changed

pkg/ottl/context_inferrer.go

+12-18
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ var (
1818
}
1919
)
2020

21-
// ContextInferrer is an interface used to infer the OTTL context from statements paths.
22-
type ContextInferrer interface {
23-
// Infer returns the OTTL context inferred from the given statements paths.
24-
Infer(statements []string) (string, error)
21+
// contextInferrer is an interface used to infer the OTTL context from statements paths.
22+
type contextInferrer interface {
23+
// infer returns the OTTL context inferred from the given statements paths.
24+
infer(statements []string) (string, error)
2525
}
2626

2727
type priorityContextInferrer struct {
28-
contextPriority map[string]int
29-
ignoreUnknownContext bool
28+
contextPriority map[string]int
3029
}
3130

32-
func (s *priorityContextInferrer) Infer(statements []string) (string, error) {
31+
func (s *priorityContextInferrer) infer(statements []string) (string, error) {
3332
var inferredContext string
3433
var inferredContextPriority int
3534

@@ -42,10 +41,6 @@ func (s *priorityContextInferrer) Infer(statements []string) (string, error) {
4241
for _, p := range getParsedStatementPaths(parsed) {
4342
pathContextPriority, ok := s.contextPriority[p.Context]
4443
if !ok {
45-
if s.ignoreUnknownContext {
46-
continue
47-
}
48-
4944
// Lowest priority
5045
pathContextPriority = math.MaxInt
5146
}
@@ -60,26 +55,25 @@ func (s *priorityContextInferrer) Infer(statements []string) (string, error) {
6055
return inferredContext, nil
6156
}
6257

63-
// DefaultPriorityContextInferrer is like NewPriorityContextInferrer, but using the default
58+
// defaultPriorityContextInferrer is like newPriorityContextInferrer, but using the default
6459
// context priorities and ignoring unknown/non-prioritized contexts.
65-
func DefaultPriorityContextInferrer() ContextInferrer {
66-
return NewPriorityContextInferrer(defaultContextInferPriority, false)
60+
func defaultPriorityContextInferrer() contextInferrer {
61+
return newPriorityContextInferrer(defaultContextInferPriority)
6762
}
6863

69-
// NewPriorityContextInferrer creates a new priority-based context inferrer.
64+
// newPriorityContextInferrer creates a new priority-based context inferrer.
7065
// To infer the context, it compares all [ottl.Path.Context] values, prioritizing them based
7166
// on the provide contextsPriority argument, the lower the context position is in the array,
7267
// the more priority it will have over other items.
7368
// If unknown/non-prioritized contexts are found on the statements, they can be either ignored
7469
// or considered when no other prioritized context is found. To skip unknown contexts, the
7570
// ignoreUnknownContext argument must be set to false.
76-
func NewPriorityContextInferrer(contextsPriority []string, ignoreUnknownContext bool) ContextInferrer {
71+
func newPriorityContextInferrer(contextsPriority []string) contextInferrer {
7772
contextPriority := make(map[string]int, len(contextsPriority))
7873
for i, ctx := range contextsPriority {
7974
contextPriority[ctx] = i
8075
}
8176
return &priorityContextInferrer{
82-
contextPriority: contextPriority,
83-
ignoreUnknownContext: ignoreUnknownContext,
77+
contextPriority: contextPriority,
8478
}
8579
}

pkg/ottl/context_inferrer_test.go

+13-30
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import (
1212

1313
func Test_NewPriorityContextInferrer_Infer(t *testing.T) {
1414
tests := []struct {
15-
name string
16-
priority []string
17-
ignoreUnknown bool
18-
statements []string
19-
expected string
15+
name string
16+
priority []string
17+
statements []string
18+
expected string
2019
}{
2120
{
2221
name: "with priority and contexts",
@@ -45,42 +44,27 @@ func Test_NewPriorityContextInferrer_Infer(t *testing.T) {
4544
expected: "foo",
4645
},
4746
{
48-
name: "with ignore unknown false",
49-
priority: []string{"foo", "bar"},
50-
ignoreUnknown: false,
51-
statements: []string{"set(span.foo, true) where span.bar == true"},
52-
expected: "span",
53-
},
54-
{
55-
name: "with ignore unknown true",
56-
priority: []string{"foo", "bar"},
57-
ignoreUnknown: true,
58-
statements: []string{"set(span.foo, true) where span.bar == true"},
59-
expected: "",
60-
},
61-
{
62-
name: "with ignore unknown true and mixed statement contexts",
63-
priority: []string{"foo", "span"},
64-
ignoreUnknown: true,
65-
statements: []string{"set(bar.foo, true) where span.bar == true"},
66-
expected: "span",
47+
name: "with unknown context",
48+
priority: []string{"foo", "bar"},
49+
statements: []string{"set(span.foo, true) where span.bar == true"},
50+
expected: "span",
6751
},
6852
}
6953

7054
for _, tt := range tests {
7155
t.Run(tt.name, func(t *testing.T) {
72-
inferrer := NewPriorityContextInferrer(tt.priority, tt.ignoreUnknown)
73-
inferredContext, err := inferrer.Infer(tt.statements)
56+
inferrer := newPriorityContextInferrer(tt.priority)
57+
inferredContext, err := inferrer.infer(tt.statements)
7458
require.NoError(t, err)
7559
assert.Equal(t, tt.expected, inferredContext)
7660
})
7761
}
7862
}
7963

8064
func Test_NewPriorityContextInferrer_InvalidStatement(t *testing.T) {
81-
inferrer := NewPriorityContextInferrer([]string{"foo"}, false)
65+
inferrer := newPriorityContextInferrer([]string{"foo"})
8266
statements := []string{"set(foo.field,"}
83-
_, err := inferrer.Infer(statements)
67+
_, err := inferrer.infer(statements)
8468
require.ErrorContains(t, err, "unexpected token")
8569
}
8670

@@ -96,9 +80,8 @@ func Test_DefaultPriorityContextInferrer(t *testing.T) {
9680
"instrumentation_scope",
9781
}
9882

99-
inferrer := DefaultPriorityContextInferrer().(*priorityContextInferrer)
83+
inferrer := defaultPriorityContextInferrer().(*priorityContextInferrer)
10084
require.NotNil(t, inferrer)
101-
require.False(t, inferrer.ignoreUnknownContext)
10285

10386
for pri, ctx := range expectedPriority {
10487
require.Equal(t, pri, inferrer.contextPriority[ctx])

0 commit comments

Comments
 (0)