-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
BharatKJain
wants to merge
11
commits into
open-telemetry:main
Choose a base branch
from
BharatKJain:gelf-receiver-operator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c5fcf42
Added: gelf-receiver init code
BharatKJain 682d179
Updated: GELF receiver code
BharatKJain b101d65
Updated: GELF code with async-handling
BharatKJain 986db9e
Fixed: go mod changes
BharatKJain 41e0463
removed comments
BharatKJain 8eb1579
Added: tests and minor-fix
BharatKJain 885e2d4
Added: docs and minor-fix
BharatKJain 046f1b1
Updated: go.mod, docs.go and builder-config versions
BharatKJain f04bfc4
Rebase Changes
BharatKJain ef3b178
Updated: go mod tidy
BharatKJain 2a7dfa9
Added: log-formatting changes
BharatKJain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'") | ||
} | ||
|
||
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.