Skip to content

Commit

Permalink
[chore] Expose namedpipe config on all platforms (open-telemetry#29857)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski committed Dec 13, 2023
1 parent 173909f commit 95d75a6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 32 deletions.
41 changes: 41 additions & 0 deletions pkg/stanza/operator/input/namedpipe/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package namedpipe // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/namedpipe"

import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/split"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/trim"
)

const (
operatorType = "namedpipe"
DefaultMaxLogSize = 1024 * 1024
)

func NewConfig() *Config {
return NewConfigWithID(operatorType)
}

// NewConfig creates a new stdin input config with default values
func NewConfigWithID(operatorID string) *Config {
return &Config{
InputConfig: helper.NewInputConfig(operatorID, operatorType),
}
}

// Config is the configuration of a stdin input operator.
type Config struct {
helper.InputConfig `mapstructure:",squash"`
BaseConfig `mapstructure:",squash"`
}

type BaseConfig struct {
Path string `mapstructure:"path"`
Permissions uint32 `mapstructure:"mode"`
Encoding string `mapstructure:"encoding"`
SplitConfig split.Config `mapstructure:"multiline,omitempty"`
TrimConfig trim.Config `mapstructure:",squash"`
MaxLogSize int `mapstructure:"max_log_size"`
}
32 changes: 0 additions & 32 deletions pkg/stanza/operator/input/namedpipe/namedpipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,13 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/decode"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/split"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/trim"
)

const (
operatorType = "namedpipe"
DefaultMaxLogSize = 1024 * 1024
)

func init() {
operator.Register(operatorType, func() operator.Builder { return NewConfig() })
}

func NewConfig() *Config {
return NewConfigWithID(operatorType)
}

// NewConfig creates a new stdin input config with default values
func NewConfigWithID(operatorID string) *Config {
return &Config{
InputConfig: helper.NewInputConfig(operatorID, operatorType),
}
}

// Config is the configuration of a stdin input operator.
type Config struct {
helper.InputConfig `mapstructure:",squash"`
BaseConfig `mapstructure:",squash"`
}

type BaseConfig struct {
Path string `mapstructure:"path"`
Permissions uint32 `mapstructure:"mode"`
Encoding string `mapstructure:"encoding"`
SplitConfig split.Config `mapstructure:"multiline,omitempty"`
TrimConfig trim.Config `mapstructure:",squash"`
MaxLogSize int `mapstructure:"max_log_size"`
}

// Build will build a namedpipe input operator.
func (c *Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
inputOperator, err := c.InputConfig.Build(logger)
Expand Down
18 changes: 18 additions & 0 deletions pkg/stanza/operator/input/namedpipe/namedpipe_nonlinux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build !linux
// +build !linux

package namedpipe // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/namedpipe"

import (
"errors"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"go.uber.org/zap"
)

func (c *Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
return nil, errors.New("namedpipe input operator is only supported on linux")
}
3 changes: 3 additions & 0 deletions receiver/namedpipereceiver/namedpipe_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:build linux
// +build linux

package namedpipereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/namedpipereceiver"

import (
Expand Down

0 comments on commit 95d75a6

Please sign in to comment.