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

[receiver/gelfreceiver] Added Support for GELF log receiver. #33858

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ receivers:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowseventlogreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zookeeperreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gelfreceiver v0.112.0

connectors:
- gomod: go.opentelemetry.io/collector/connector/forwardconnector v0.112.0
Expand Down Expand Up @@ -496,3 +497,4 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/grpcutil => ../../internal/grpcutil
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudmonitoringreceiver => ../../receiver/googlecloudmonitoringreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status => ../../pkg/status
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gelfreceiver => ../../receiver/gelfreceiver
108 changes: 108 additions & 0 deletions pkg/stanza/operator/input/gelfinternal/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"fmt"
"net"

"go.opentelemetry.io/collector/component"

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

const (
operatorType = "gelf_input"
defaultReaders = 1
defaultProcessors = 1
defaultUDPMaxQueueLength = 100
defaultListenAddress = "127.0.0.1:31250"
defaultProtocol = "udp"
MaxUDPSize = 64 * 1024
)

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

// NewConfig creates a new UDP input config with default values
func NewConfig() *Config {
return NewConfigWithID(operatorType)
}

// NewConfigWithID creates a new UDP input config with default values
func NewConfigWithID(operatorID string) *Config {
return &Config{
InputConfig: helper.NewInputConfig(operatorID, operatorType),
BaseConfig: BaseConfig{
ListenAddress: string(defaultListenAddress),
Protocol: string(defaultProtocol),
AsyncReaders: defaultReaders,
AsyncProcessors: defaultProcessors,
UDPMaxQueueLength: defaultUDPMaxQueueLength,
},
}
}

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

// BaseConfig is the details configuration of a udp input operator.
type BaseConfig struct {
ListenAddress string `mapstructure:"listen_address,omitempty"`
Protocol string `mapstructure:"protocol,omitempty"`
AsyncReaders int `mapstructure:"async_readers,omitempty"`
AsyncProcessors int `mapstructure:"async_processors,omitempty"`
UDPMaxQueueLength int `mapstructure:"udp_max_queue_length,omitempty"`
EnableShortAndFullMessage bool `mapstructure:"enable_short_and_full_message,omitempty"`
EnableGELFRawMessage bool `mapstructure:"enable_gelf_raw_message,omitempty"`
}

// Build will build a udp input operator.
func (c Config) Build(set component.TelemetrySettings) (operator.Operator, error) {
inputOperator, err := c.InputConfig.Build(set)
if err != nil {
return nil, err
}

if c.ListenAddress == "" {
return nil, fmt.Errorf("missing required parameter 'listen_address'")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("missing required parameter 'listen_address'")
return nil, errors.New("missing required parameter 'listen_address'")

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure but if you check ../udp/config.go, they are using fmt...I didn't wanted to diverge from it, let me know your thoughts.

}

if _, _, err := net.SplitHostPort(c.ListenAddress); err != nil {
return nil, fmt.Errorf("invalid listen_address: %w", err)
}

if c.Protocol != "udp" {
return nil, fmt.Errorf("supported protocols - udp, invalid protocol: %s", c.Protocol)
}
if c.AsyncReaders < 1 {
return nil, fmt.Errorf("invalid async_reader: %d", c.AsyncReaders)
}
if c.AsyncProcessors < 1 {
return nil, fmt.Errorf("invalid async_processors: %d", c.AsyncProcessors)
}
if c.UDPMaxQueueLength <= 0 || c.UDPMaxQueueLength > 65535 {
return nil, fmt.Errorf("expecting queue length greater than 0 and less than 65535, invalid udp_max_queue_length: %d", c.UDPMaxQueueLength)
}

udpInput := &Input{
InputOperator: inputOperator,
address: c.ListenAddress,
protocol: c.Protocol,
udpMessageQueue: make(chan UDPMessage, c.UDPMaxQueueLength),
buffer: make(map[string]*MapGelfMessage),
lastBuffer: make(map[string]*MapGelfMessage),
asyncReaders: c.AsyncReaders,
asyncProcessors: c.AsyncProcessors,
enableShortAndFullMessage: c.EnableShortAndFullMessage,
enableGELFRawMessage: c.EnableGELFRawMessage,
}

return udpInput, nil
}
Loading