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

feat: unroll processor #2021

Merged
merged 16 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions factories/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/observiq/bindplane-agent/processor/samplingprocessor"
"github.com/observiq/bindplane-agent/processor/spancountprocessor"
"github.com/observiq/bindplane-agent/processor/throughputmeasurementprocessor"
"github.com/observiq/bindplane-agent/processor/unrollprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/cumulativetodeltaprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatorateprocessor"
Expand Down Expand Up @@ -87,4 +88,5 @@ var defaultProcessors = []processor.Factory{
throughputmeasurementprocessor.NewFactory(),
tailsamplingprocessor.NewFactory(),
transformprocessor.NewFactory(),
unrollprocessor.NewFactory(),
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/observiq/bindplane-agent

go 1.22.7
go 1.23.3

require (
github.com/google/uuid v1.6.0
Expand All @@ -25,6 +25,7 @@ require (
github.com/observiq/bindplane-agent/processor/samplingprocessor v1.66.0
github.com/observiq/bindplane-agent/processor/spancountprocessor v1.66.0
github.com/observiq/bindplane-agent/processor/throughputmeasurementprocessor v1.66.0
github.com/observiq/bindplane-agent/processor/unrollprocessor v1.66.0
github.com/observiq/bindplane-agent/receiver/awss3rehydrationreceiver v1.66.0
github.com/observiq/bindplane-agent/receiver/azureblobrehydrationreceiver v1.66.0
github.com/observiq/bindplane-agent/receiver/httpreceiver v1.66.0
Expand Down Expand Up @@ -853,6 +854,8 @@ replace github.com/observiq/bindplane-agent/processor/datapointcountprocessor =>

replace github.com/observiq/bindplane-agent/processor/lookupprocessor => ./processor/lookupprocessor

replace github.com/observiq/bindplane-agent/processor/unrollprocessor => ./processor/unrollprocessor

replace github.com/observiq/bindplane-agent/expr => ./expr

replace github.com/observiq/bindplane-agent/counter => ./counter
Expand Down
1 change: 1 addition & 0 deletions processor/unrollprocessor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
Empty file.
42 changes: 42 additions & 0 deletions processor/unrollprocessor/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright observIQ, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package unrollprocessor

import (
"errors"
)

// Config is the configuration for the unroll processor.
type Config struct {
UnrollKey string `mapstructure:"unroll_key"`
Field UnrollField `mapstructure:"field"`
}

// UnrollField is the field to unroll.
type UnrollField string

const (
// UnrollFieldBody is the only supported field for unrolling logs.
UnrollFieldBody UnrollField = "body"
)

// Validate checks the configuration for any issues.
func (c *Config) Validate() error {
if c.Field != UnrollFieldBody {
return errors.New("only unrolling logs from a body slice is currently supported")
}

return nil
}
19 changes: 19 additions & 0 deletions processor/unrollprocessor/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright observIQ, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate mdatagen metadata.yaml

// Package transformprocessor contains the logic to execute telemetry transform based
// on the OpenTelemetry Transformation Language.
package unrollprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/unrollprocessor"
68 changes: 68 additions & 0 deletions processor/unrollprocessor/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright observIQ, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package unrollprocessor // import "github.com/observiq/bindplane-agent/processor/unrollprocessor"

import (
"context"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"

"github.com/observiq/bindplane-agent/processor/unrollprocessor/internal/metadata"
)

var processorCapabilities = consumer.Capabilities{MutatesData: true}

const typeStr = "unroll"

// NewFactory returns a new factory for the Transform processor.
func NewFactory() processor.Factory {
return processor.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithLogs(createLogsProcessor, metadata.LogsStability),
)
}

func createDefaultConfig() component.Config {
return &Config{
UnrollKey: "message",
Field: UnrollFieldBody,
}
}

func createLogsProcessor(
ctx context.Context,
set processor.Settings,
cfg component.Config,
nextConsumer consumer.Logs,
) (processor.Logs, error) {
oCfg := cfg.(*Config)

proc, err := newUnrollProcessor(oCfg)
if err != nil {
return nil, fmt.Errorf("invalid config for \"unroll\" processor %w", err)
}
return processorhelper.NewLogs(
ctx,
set,
cfg,
nextConsumer,
proc.ProcessLogs,
processorhelper.WithCapabilities(processorCapabilities))
}
135 changes: 135 additions & 0 deletions processor/unrollprocessor/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions processor/unrollprocessor/generated_package_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions processor/unrollprocessor/go.mod
dpaasman00 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module github.com/observiq/bindplane-agent/processor/unrollprocessor

go 1.23.3

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.114.0
go.opentelemetry.io/collector/component/componenttest v0.114.0
go.opentelemetry.io/collector/confmap v1.20.0
go.opentelemetry.io/collector/consumer v0.114.0
go.opentelemetry.io/collector/consumer/consumertest v0.114.0
go.opentelemetry.io/collector/pdata v1.20.0
go.opentelemetry.io/collector/processor v0.114.0
go.opentelemetry.io/collector/processor/processortest v0.114.0
go.uber.org/goleak v1.3.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
go.opentelemetry.io/collector/component/componentstatus v0.114.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.114.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.114.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.114.0 // indirect
go.opentelemetry.io/collector/pdata/testdata v0.114.0 // indirect
go.opentelemetry.io/collector/pipeline v0.114.0 // indirect
go.opentelemetry.io/collector/processor/processorprofiles v0.114.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading