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

[processor/transform] Move config structure to TQL #13373

Merged
merged 6 commits into from
Aug 24, 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
27 changes: 27 additions & 0 deletions pkg/telemetryquerylanguage/tqlconfig/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
//
// 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 tqlconfig // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tqlconfig"

// Config configures the TQL queries to execute against traces, metrics, and logs.
type Config struct {
Traces SignalConfig `mapstructure:"traces"`
Metrics SignalConfig `mapstructure:"metrics"`
Logs SignalConfig `mapstructure:"logs"`
}

// SignalConfig configures TQL queries to execute.
type SignalConfig struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever want to have a different config between signals?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current config allows configuring different queries per signal, but thats it so far. Haven't come across a use-case yet for the config beside defining the queries themselves.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking instead of a SignalConfig we'd have TracesConfig, MetricsConfig, and LogsConfig? At the moment all 3 would need the Queries property and would be duplicates of one another. Have anything in mind that we'd add to one but not the other?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider having each of Traces, Metrics, and Logs be an interface instead of a struct? That would be something like:

type Queryer interface {
    GetQueries() []string
}

Or does that screw up something relating to loading the configurations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe they need to be structs to interact correctly with component.ProcessorFactory

Queries []string `mapstructure:"queries"`
}
9 changes: 2 additions & 7 deletions processor/transformprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,16 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/contexts/tqlmetrics"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/contexts/tqltraces"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tql"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tqlconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/logs"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/traces"
)

type SignalConfig struct {
Queries []string `mapstructure:"queries"`
}

type Config struct {
config.ProcessorSettings `mapstructure:",squash"`

Logs SignalConfig `mapstructure:"logs"`
Traces SignalConfig `mapstructure:"traces"`
Metrics SignalConfig `mapstructure:"metrics"`
tqlconfig.Config `mapstructure:",squash"`
}

var _ config.Processor = (*Config)(nil)
Expand Down
32 changes: 18 additions & 14 deletions processor/transformprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/confmap/confmaptest"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tqlconfig"
)

func TestLoadConfig(t *testing.T) {
Expand All @@ -36,22 +38,24 @@ func TestLoadConfig(t *testing.T) {
id: config.NewComponentIDWithName(typeStr, ""),
expected: &Config{
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
Traces: SignalConfig{
Queries: []string{
`set(name, "bear") where attributes["http.path"] == "/animal"`,
`keep_keys(attributes, "http.method", "http.path")`,
Config: tqlconfig.Config{
Traces: tqlconfig.SignalConfig{
Queries: []string{
`set(name, "bear") where attributes["http.path"] == "/animal"`,
`keep_keys(attributes, "http.method", "http.path")`,
},
},
},
Metrics: SignalConfig{
Queries: []string{
`set(metric.name, "bear") where attributes["http.path"] == "/animal"`,
`keep_keys(attributes, "http.method", "http.path")`,
Metrics: tqlconfig.SignalConfig{
Queries: []string{
`set(metric.name, "bear") where attributes["http.path"] == "/animal"`,
`keep_keys(attributes, "http.method", "http.path")`,
},
},
},
Logs: SignalConfig{
Queries: []string{
`set(body, "bear") where attributes["http.path"] == "/animal"`,
`keep_keys(attributes, "http.method", "http.path")`,
Logs: tqlconfig.SignalConfig{
Queries: []string{
`set(body, "bear") where attributes["http.path"] == "/animal"`,
`keep_keys(attributes, "http.method", "http.path")`,
},
},
},
},
Expand Down
19 changes: 11 additions & 8 deletions processor/transformprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor/processorhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tqlconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/logs"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/traces"
Expand All @@ -48,14 +49,16 @@ func NewFactory() component.ProcessorFactory {
func createDefaultConfig() config.Processor {
return &Config{
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
Logs: SignalConfig{
Queries: []string{},
},
Traces: SignalConfig{
Queries: []string{},
},
Metrics: SignalConfig{
Queries: []string{},
Config: tqlconfig.Config{
Logs: tqlconfig.SignalConfig{
Queries: []string{},
},
Traces: tqlconfig.SignalConfig{
Queries: []string{},
},
Metrics: tqlconfig.SignalConfig{
Queries: []string{},
},
},
}
}
Expand Down
20 changes: 12 additions & 8 deletions processor/transformprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/telemetryquerylanguage/tqlconfig"
)

func TestFactory_Type(t *testing.T) {
Expand All @@ -38,14 +40,16 @@ func TestFactory_CreateDefaultConfig(t *testing.T) {
cfg := factory.CreateDefaultConfig()
assert.Equal(t, cfg, &Config{
ProcessorSettings: config.NewProcessorSettings(config.NewComponentID(typeStr)),
Traces: SignalConfig{
Queries: []string{},
},
Metrics: SignalConfig{
Queries: []string{},
},
Logs: SignalConfig{
Queries: []string{},
Config: tqlconfig.Config{
Traces: tqlconfig.SignalConfig{
Queries: []string{},
},
Metrics: tqlconfig.SignalConfig{
Queries: []string{},
},
Logs: tqlconfig.SignalConfig{
Queries: []string{},
},
},
})
assert.NoError(t, configtest.CheckConfigStruct(cfg))
Expand Down