Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg/ottl] Rename ottllogs to ottllog #16242

Merged
merged 8 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/ottl-rename-ottllogs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/ottl

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Rename `ottllogs` to `ottllog`

# One or more tracking issues related to the change
issues: [16242]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Logs Context
# Log Context

The Logs Context is a Context implementation for [pdata Logs](https://github.com/open-telemetry/opentelemetry-collector/tree/main/pdata/plog), the collector's internal representation for OTLP log data. This Context should be used when interacted with OTLP logs.
The Log Context is a Context implementation for [pdata Logs](https://github.com/open-telemetry/opentelemetry-collector/tree/main/pdata/plog), the collector's internal representation for OTLP log data. This Context should be used when interacted with OTLP logs.

## Paths
In general, the Logs Context supports accessing pdata using the field names from the [logs proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/logs/v1/logs.proto). All integers are returned and set via `int64`. All doubles are returned and set via `float64`.
In general, the Log Context supports accessing pdata using the field names from the [logs proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/logs/v1/logs.proto). All integers are returned and set via `int64`. All doubles are returned and set via `float64`.

All TraceIDs and SpanIDs are returned as pdata [SpanID](https://github.com/open-telemetry/opentelemetry-collector/blob/main/pdata/pcommon/spanid.go) and [TraceID](https://github.com/open-telemetry/opentelemetry-collector/blob/main/pdata/pcommon/traceid.go) types. Use the [SpanID function](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/ottlfuncs/README.md#spanid) and [TraceID function](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/ottlfuncs/README.md#traceid) when interacting with pdata representations of SpanID and TraceID. When checking for nil, instead check against an empty byte slice (`SpanID(0x0000000000000000)` and `TraceID(0x00000000000000000000000000000000)`).

Expand All @@ -30,4 +30,4 @@ The following fields are the exception.

## Enums

The Logs Context supports the enum names from the [logs proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/logs/v1/logs.proto).
The Log Context supports the enum names from the [logs proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/logs/v1/logs.proto).
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ottllogs // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs"
package ottllog // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ottllogs
package ottllog

import (
"context"
Expand Down
10 changes: 5 additions & 5 deletions processor/routingprocessor/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor/internal/common"
)

Expand All @@ -35,7 +35,7 @@ type logProcessor struct {
config *Config

extractor extractor
router router[component.LogsExporter, ottllogs.TransformContext]
router router[component.LogsExporter, ottllog.TransformContext]
}

func newLogProcessor(settings component.TelemetrySettings, config component.ProcessorConfig) *logProcessor {
Expand All @@ -44,11 +44,11 @@ func newLogProcessor(settings component.TelemetrySettings, config component.Proc
return &logProcessor{
logger: settings.Logger,
config: cfg,
router: newRouter[component.LogsExporter, ottllogs.TransformContext](
router: newRouter[component.LogsExporter, ottllog.TransformContext](
cfg.Table,
cfg.DefaultExporters,
settings,
ottllogs.NewParser(common.Functions[ottllogs.TransformContext](), settings),
ottllog.NewParser(common.Functions[ottllog.TransformContext](), settings),
),
extractor: newExtractor(cfg.FromAttribute, settings.Logger),
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func (p *logProcessor) route(ctx context.Context, l plog.Logs) error {

for i := 0; i < l.ResourceLogs().Len(); i++ {
rlogs := l.ResourceLogs().At(i)
ltx := ottllogs.NewTransformContext(
ltx := ottllog.NewTransformContext(
plog.LogRecord{},
pcommon.InstrumentationScope{},
rlogs.Resource(),
Expand Down
2 changes: 1 addition & 1 deletion processor/transformprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The contexts allow the OTTL to interact with the underlying telemetry data in it
- [SpanEvent Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlspanevent)
- [Metric Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlmetric)
- [DataPoint Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottldatapoint) <!-- markdown-link-check-disable-line -->
- [Logs Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottllogs)
- [Log Context](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottllog) <!-- markdown-link-check-disable-line -->

Each context allows transformation of its type of telemetry.
For example, statements associated to a `resource` context will be able to transform the resource's `attributes` and `dropped_attributes_count`.
Expand Down
4 changes: 2 additions & 2 deletions processor/transformprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoint"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlspan"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/logs"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (c *Config) Validate() error {
}

if len(c.Logs.Statements) > 0 {
ottllogsp := ottllogs.NewParser(logs.Functions(), component.TelemetrySettings{Logger: zap.NewNop()})
ottllogsp := ottllog.NewParser(logs.Functions(), component.TelemetrySettings{Logger: zap.NewNop()})
_, err := ottllogsp.ParseStatements(c.Logs.Statements)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions processor/transformprocessor/internal/common/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"go.opentelemetry.io/collector/pdata/plog"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlresource"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlscope"
)

var _ consumer.Logs = &logStatements{}

type logStatements []*ottl.Statement[ottllogs.TransformContext]
type logStatements []*ottl.Statement[ottllog.TransformContext]

func (l logStatements) Capabilities() consumer.Capabilities {
return consumer.Capabilities{
Expand All @@ -44,7 +44,7 @@ func (l logStatements) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
slogs := rlogs.ScopeLogs().At(j)
logs := slogs.LogRecords()
for k := 0; k < logs.Len(); k++ {
tCtx := ottllogs.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource())
tCtx := ottllog.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource())
for _, statement := range l {
_, _, err := statement.Execute(ctx, tCtx)
if err != nil {
Expand All @@ -59,7 +59,7 @@ func (l logStatements) ConsumeLogs(ctx context.Context, ld plog.Logs) error {

type LogParserCollection struct {
parserCollection
logParser ottl.Parser[ottllogs.TransformContext]
logParser ottl.Parser[ottllog.TransformContext]
}

type LogParserCollectionOption func(*LogParserCollection) error
Expand All @@ -71,7 +71,7 @@ func NewLogParserCollection(functions map[string]interface{}, settings component
resourceParser: ottlresource.NewParser(ResourceFunctions(), settings),
scopeParser: ottlscope.NewParser(ScopeFunctions(), settings),
},
logParser: ottllogs.NewParser(functions, settings),
logParser: ottllog.NewParser(functions, settings),
}

for _, op := range options {
Expand Down
4 changes: 2 additions & 2 deletions processor/transformprocessor/internal/logs/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package logs // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/logs"

import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common"
)

func Functions() map[string]interface{} {
// No logs-only functions yet.
return common.Functions[ottllogs.TransformContext]()
return common.Functions[ottllog.TransformContext]()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common"
)

func Test_DefaultFunctions(t *testing.T) {
expected := common.Functions[ottllogs.TransformContext]()
expected := common.Functions[ottllog.TransformContext]()
actual := Functions()
require.Equal(t, len(expected), len(actual))
for k := range actual {
Expand Down
8 changes: 4 additions & 4 deletions processor/transformprocessor/internal/logs/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ import (
"go.opentelemetry.io/collector/pdata/plog"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllogs"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common"
)

type Processor struct {
contexts []consumer.Logs
// Deprecated. Use contexts instead
statements []*ottl.Statement[ottllogs.TransformContext]
statements []*ottl.Statement[ottllog.TransformContext]
}

func NewProcessor(statements []string, contextStatements []common.ContextStatements, settings component.TelemetrySettings) (*Processor, error) {
if len(statements) > 0 {
ottlp := ottllogs.NewParser(Functions(), settings)
ottlp := ottllog.NewParser(Functions(), settings)
parsedStatements, err := ottlp.ParseStatements(statements)
if err != nil {
return nil, err
Expand Down Expand Up @@ -71,7 +71,7 @@ func (p *Processor) ProcessLogs(ctx context.Context, ld plog.Logs) (plog.Logs, e
slogs := rlogs.ScopeLogs().At(j)
logs := slogs.LogRecords()
for k := 0; k < logs.Len(); k++ {
tCtx := ottllogs.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource())
tCtx := ottllog.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource())
for _, statement := range p.statements {
_, _, err := statement.Execute(ctx, tCtx)
if err != nil {
Expand Down