Skip to content

Commit 1a67042

Browse files
Merge branch 'main' into add-splunk-rolling-restart-metric
2 parents be06d28 + d1f343c commit 1a67042

File tree

15 files changed

+197
-13
lines changed

15 files changed

+197
-13
lines changed

pkg/ottl/boolean_value.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import (
1111
// boolExpressionEvaluator is a function that returns the result.
1212
type boolExpressionEvaluator[K any] func(ctx context.Context, tCtx K) (bool, error)
1313

14+
// BoolExpr represents a condition in OTTL
1415
type BoolExpr[K any] struct {
1516
boolExpressionEvaluator[K]
1617
}
1718

19+
// Eval evaluates an OTTL condition
1820
func (e BoolExpr[K]) Eval(ctx context.Context, tCtx K) (bool, error) {
1921
return e.boolExpressionEvaluator(ctx, tCtx)
2022
}

pkg/ottl/config.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import (
88
"strings"
99
)
1010

11+
// ErrorMode is the way OTTL should handle errors.
1112
type ErrorMode string
1213

1314
const (
14-
IgnoreError ErrorMode = "ignore"
15+
// IgnoreError means OTTL will only log errors.
16+
IgnoreError ErrorMode = "ignore"
17+
// PropagateError means OTTL will log and return errors.
1518
PropagateError ErrorMode = "propagate"
16-
SilentError ErrorMode = "silent"
19+
// SilentError means OTTL will not log or return errors.
20+
SilentError ErrorMode = "silent"
1721
)
1822

1923
func (e *ErrorMode) UnmarshalText(text []byte) error {
@@ -27,13 +31,17 @@ func (e *ErrorMode) UnmarshalText(text []byte) error {
2731
}
2832
}
2933

34+
// LogicOperation represents the logical operations OTTL understands.
3035
type LogicOperation string
3136

3237
const (
38+
// And is the logical operator "and".
3339
And LogicOperation = "and"
34-
Or LogicOperation = "or"
40+
// Or is the logical operator "or".
41+
Or LogicOperation = "or"
3542
)
3643

44+
// UnmarshalText unmarshals a string into a LogicOperation. It errors if the string is not "and" or "or".
3745
func (l *LogicOperation) UnmarshalText(text []byte) error {
3846
str := LogicOperation(strings.ToLower(string(text)))
3947
switch str {

pkg/ottl/contexts/ottldatapoint/datapoint.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
2323
)
2424

25+
// ContextName is the name of the context for datapoints.
2526
// Experimental: *NOTE* this constant is subject to change or removal in the future.
2627
const ContextName = ctxdatapoint.Name
2728

@@ -32,6 +33,7 @@ var (
3233
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
3334
)
3435

36+
// TransformContext represents a Datapoint and all its hierarchy.
3537
type TransformContext struct {
3638
dataPoint any
3739
metric pmetric.Metric
@@ -43,6 +45,7 @@ type TransformContext struct {
4345
resourceMetrics pmetric.ResourceMetrics
4446
}
4547

48+
// MarshalLogObject serializes the TransformContext into a zapcore.ObjectEncoder for logging.
4649
func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
4750
err := encoder.AddObject("resource", logging.Resource(tCtx.resource))
4851
err = errors.Join(err, encoder.AddObject("scope", logging.InstrumentationScope(tCtx.instrumentationScope)))
@@ -65,6 +68,7 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err
6568

6669
type TransformContextOption func(*TransformContext)
6770

71+
// NewTransformContext creates a new TransformContext with the provided parameters.
6872
func NewTransformContext(dataPoint any, metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics, options ...TransformContextOption) TransformContext {
6973
tc := TransformContext{
7074
dataPoint: dataPoint,
@@ -82,35 +86,42 @@ func NewTransformContext(dataPoint any, metric pmetric.Metric, metrics pmetric.M
8286
return tc
8387
}
8488

89+
// GetDataPoint returns the datapoint from the TransformContext.
8590
func (tCtx TransformContext) GetDataPoint() any {
8691
return tCtx.dataPoint
8792
}
8893

94+
// GetInstrumentationScope returns the instrumentation scope from the TransformContext.
8995
func (tCtx TransformContext) GetInstrumentationScope() pcommon.InstrumentationScope {
9096
return tCtx.instrumentationScope
9197
}
9298

99+
// GetResource returns the resource from the TransformContext.
93100
func (tCtx TransformContext) GetResource() pcommon.Resource {
94101
return tCtx.resource
95102
}
96103

104+
// GetMetric returns the metric from the TransformContext.
97105
func (tCtx TransformContext) GetMetric() pmetric.Metric {
98106
return tCtx.metric
99107
}
100108

109+
// GetMetrics returns the metric slice from the TransformContext.
101110
func (tCtx TransformContext) GetMetrics() pmetric.MetricSlice {
102111
return tCtx.metrics
103112
}
104113

114+
// GetScopeSchemaURLItem returns the scope schema URL item from the TransformContext.
105115
func (tCtx TransformContext) GetScopeSchemaURLItem() ctxcommon.SchemaURLItem {
106116
return tCtx.scopeMetrics
107117
}
108118

119+
// GetResourceSchemaURLItem returns the resource schema URL item from the TransformContext.
109120
func (tCtx TransformContext) GetResourceSchemaURLItem() ctxcommon.SchemaURLItem {
110121
return tCtx.resourceMetrics
111122
}
112123

113-
// EnablePathContextNames enables the support to path's context names on statements.
124+
// EnablePathContextNames enables the support for path's context names on statements.
114125
// When this option is configured, all statement's paths must have a valid context prefix,
115126
// otherwise an error is reported.
116127
//
@@ -128,12 +139,14 @@ func EnablePathContextNames() ottl.Option[TransformContext] {
128139

129140
type StatementSequenceOption func(*ottl.StatementSequence[TransformContext])
130141

142+
// WithStatementSequenceErrorMode sets the error mode for a statement sequence.
131143
func WithStatementSequenceErrorMode(errorMode ottl.ErrorMode) StatementSequenceOption {
132144
return func(s *ottl.StatementSequence[TransformContext]) {
133145
ottl.WithStatementSequenceErrorMode[TransformContext](errorMode)(s)
134146
}
135147
}
136148

149+
// NewStatementSequence creates a new statement sequence with the provided statements and options.
137150
func NewStatementSequence(statements []*ottl.Statement[TransformContext], telemetrySettings component.TelemetrySettings, options ...StatementSequenceOption) ottl.StatementSequence[TransformContext] {
138151
s := ottl.NewStatementSequence(statements, telemetrySettings)
139152
for _, op := range options {
@@ -144,12 +157,14 @@ func NewStatementSequence(statements []*ottl.Statement[TransformContext], teleme
144157

145158
type ConditionSequenceOption func(*ottl.ConditionSequence[TransformContext])
146159

160+
// WithConditionSequenceErrorMode sets the error mode for a condition sequence.
147161
func WithConditionSequenceErrorMode(errorMode ottl.ErrorMode) ConditionSequenceOption {
148162
return func(c *ottl.ConditionSequence[TransformContext]) {
149163
ottl.WithConditionSequenceErrorMode[TransformContext](errorMode)(c)
150164
}
151165
}
152166

167+
// NewConditionSequence creates a new condition sequence with the provided conditions and options.
153168
func NewConditionSequence(conditions []*ottl.Condition[TransformContext], telemetrySettings component.TelemetrySettings, options ...ConditionSequenceOption) ottl.ConditionSequence[TransformContext] {
154169
c := ottl.NewConditionSequence(conditions, telemetrySettings)
155170
for _, op := range options {
@@ -158,6 +173,7 @@ func NewConditionSequence(conditions []*ottl.Condition[TransformContext], teleme
158173
return c
159174
}
160175

176+
// NewParser creates a new Datapoint parser with the provided functions and options.
161177
func NewParser(
162178
functions map[string]ottl.Factory[TransformContext],
163179
telemetrySettings component.TelemetrySettings,

pkg/ottl/contexts/ottllog/log.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
2323
)
2424

25+
// ContextName is the name of the context for logs.
2526
// Experimental: *NOTE* this constant is subject to change or removal in the future.
2627
const ContextName = ctxlog.Name
2728

@@ -31,6 +32,7 @@ var (
3132
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
3233
)
3334

35+
// TransformContext represents a log and its associated hierarchy.
3436
type TransformContext struct {
3537
logRecord plog.LogRecord
3638
instrumentationScope pcommon.InstrumentationScope
@@ -42,6 +44,7 @@ type TransformContext struct {
4244

4345
type logRecord plog.LogRecord
4446

47+
// MarshalLogObject serializes the log into a zapcore.ObjectEncoder for logging.
4548
func (l logRecord) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
4649
lr := plog.LogRecord(l)
4750
spanID := lr.SpanID()
@@ -59,6 +62,7 @@ func (l logRecord) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
5962
return err
6063
}
6164

65+
// MarshalLogObject serializes the TransformContext into a zapcore.ObjectEncoder for logging.
6266
func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
6367
err := encoder.AddObject("resource", logging.Resource(tCtx.resource))
6468
err = errors.Join(err, encoder.AddObject("scope", logging.InstrumentationScope(tCtx.instrumentationScope)))
@@ -67,8 +71,10 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err
6771
return err
6872
}
6973

74+
// TransformContextOption represents an option for configuring a TransformContext.
7075
type TransformContextOption func(*TransformContext)
7176

77+
// NewTransformContext creates a new TransformContext with the provided parameters.
7278
func NewTransformContext(logRecord plog.LogRecord, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeLogs plog.ScopeLogs, resourceLogs plog.ResourceLogs, options ...TransformContextOption) TransformContext {
7379
tc := TransformContext{
7480
logRecord: logRecord,
@@ -84,27 +90,32 @@ func NewTransformContext(logRecord plog.LogRecord, instrumentationScope pcommon.
8490
return tc
8591
}
8692

93+
// GetLogRecord returns the log record from the TransformContext.
8794
func (tCtx TransformContext) GetLogRecord() plog.LogRecord {
8895
return tCtx.logRecord
8996
}
9097

98+
// GetInstrumentationScope returns the instrumentation scope from the TransformContext.
9199
func (tCtx TransformContext) GetInstrumentationScope() pcommon.InstrumentationScope {
92100
return tCtx.instrumentationScope
93101
}
94102

103+
// GetResource returns the resource from the TransformContext.
95104
func (tCtx TransformContext) GetResource() pcommon.Resource {
96105
return tCtx.resource
97106
}
98107

108+
// GetScopeSchemaURLItem returns the scope schema URL item from the TransformContext.
99109
func (tCtx TransformContext) GetScopeSchemaURLItem() ctxcommon.SchemaURLItem {
100110
return tCtx.scopeLogs
101111
}
102112

113+
// GetResourceSchemaURLItem returns the resource schema URL item from the TransformContext.
103114
func (tCtx TransformContext) GetResourceSchemaURLItem() ctxcommon.SchemaURLItem {
104115
return tCtx.resourceLogs
105116
}
106117

107-
// EnablePathContextNames enables the support to path's context names on statements.
118+
// EnablePathContextNames enables the support for path's context names on statements.
108119
// When this option is configured, all statement's paths must have a valid context prefix,
109120
// otherwise an error is reported.
110121
//
@@ -119,14 +130,17 @@ func EnablePathContextNames() ottl.Option[TransformContext] {
119130
}
120131
}
121132

133+
// StatementSequenceOption represents an option for configuring a statement sequence.
122134
type StatementSequenceOption func(*ottl.StatementSequence[TransformContext])
123135

136+
// WithStatementSequenceErrorMode sets the error mode for a statement sequence.
124137
func WithStatementSequenceErrorMode(errorMode ottl.ErrorMode) StatementSequenceOption {
125138
return func(s *ottl.StatementSequence[TransformContext]) {
126139
ottl.WithStatementSequenceErrorMode[TransformContext](errorMode)(s)
127140
}
128141
}
129142

143+
// NewStatementSequence creates a new statement sequence with the provided statements and options.
130144
func NewStatementSequence(statements []*ottl.Statement[TransformContext], telemetrySettings component.TelemetrySettings, options ...StatementSequenceOption) ottl.StatementSequence[TransformContext] {
131145
s := ottl.NewStatementSequence(statements, telemetrySettings)
132146
for _, op := range options {
@@ -135,14 +149,17 @@ func NewStatementSequence(statements []*ottl.Statement[TransformContext], teleme
135149
return s
136150
}
137151

152+
// ConditionSequenceOption represents an option for configuring a condition sequence.
138153
type ConditionSequenceOption func(*ottl.ConditionSequence[TransformContext])
139154

155+
// WithConditionSequenceErrorMode sets the error mode for a condition sequence.
140156
func WithConditionSequenceErrorMode(errorMode ottl.ErrorMode) ConditionSequenceOption {
141157
return func(c *ottl.ConditionSequence[TransformContext]) {
142158
ottl.WithConditionSequenceErrorMode[TransformContext](errorMode)(c)
143159
}
144160
}
145161

162+
// NewConditionSequence creates a new condition sequence with the provided conditions and options.
146163
func NewConditionSequence(conditions []*ottl.Condition[TransformContext], telemetrySettings component.TelemetrySettings, options ...ConditionSequenceOption) ottl.ConditionSequence[TransformContext] {
147164
c := ottl.NewConditionSequence(conditions, telemetrySettings)
148165
for _, op := range options {
@@ -151,6 +168,7 @@ func NewConditionSequence(conditions []*ottl.Condition[TransformContext], teleme
151168
return c
152169
}
153170

171+
// NewParser creates a new log parser with the provided functions and options.
154172
func NewParser(
155173
functions map[string]ottl.Factory[TransformContext],
156174
telemetrySettings component.TelemetrySettings,

0 commit comments

Comments
 (0)