-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add integration test for syslog
Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
- Loading branch information
Dominik Rosiek
committed
Oct 13, 2023
1 parent
cc38768
commit fc40519
Showing
9 changed files
with
358 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: bug_fix | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: syslog | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: add integration tests and fix related bugs | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [21245] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
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
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,72 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package datareceivers // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/datareceivers" | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/receiver" | ||
"go.opentelemetry.io/collector/receiver/receivertest" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/tcp" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed" | ||
) | ||
|
||
// SyslogDataReceiver implements Syslog format receiver. | ||
type SyslogDataReceiver struct { | ||
testbed.DataReceiverBase | ||
receiver receiver.Logs | ||
protocol string | ||
} | ||
|
||
// Ensure SyslogDataReceiver implements LogDataReceiver. | ||
var _ testbed.DataReceiver = (*SyslogDataReceiver)(nil) | ||
|
||
// NewSyslogDataReceiver creates a new SyslogDataReceiver that will listen on the | ||
// specified port after Start is called. | ||
func NewSyslogDataReceiver(protocol string, port int) *SyslogDataReceiver { | ||
return &SyslogDataReceiver{DataReceiverBase: testbed.DataReceiverBase{Port: port}, protocol: protocol} | ||
} | ||
|
||
// Start the receiver. | ||
func (cr *SyslogDataReceiver) Start(_ consumer.Traces, _ consumer.Metrics, lc consumer.Logs) error { | ||
factory := syslogreceiver.NewFactory() | ||
addr := fmt.Sprintf("127.0.0.1:%d", cr.Port) | ||
cfg := factory.CreateDefaultConfig().(*syslogreceiver.SysLogConfig) | ||
cfg.InputConfig.TCP = &tcp.BaseConfig{ | ||
ListenAddress: addr, | ||
} | ||
cfg.InputConfig.Protocol = cr.protocol | ||
|
||
set := receivertest.NewNopCreateSettings() | ||
var err error | ||
cr.receiver, err = factory.CreateLogsReceiver(context.Background(), set, cfg, lc) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return cr.receiver.Start(context.Background(), componenttest.NewNopHost()) | ||
} | ||
|
||
// Stop the receiver. | ||
func (cr *SyslogDataReceiver) Stop() error { | ||
return cr.receiver.Shutdown(context.Background()) | ||
} | ||
|
||
// GenConfigYAMLStr returns receiver config for the agent. | ||
func (cr *SyslogDataReceiver) GenConfigYAMLStr() string { | ||
// Note that this generates an receiver config for agent. | ||
return fmt.Sprintf(` | ||
syslog: | ||
endpoint: "127.0.0.1:%d"`, cr.Port) | ||
} | ||
|
||
// ProtocolName returns protocol name as it is specified in Collector config. | ||
func (cr *SyslogDataReceiver) ProtocolName() string { | ||
return "tcp" | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.