Skip to content

Commit

Permalink
[receiver/sshcheck] try to enable Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Feb 17, 2024
1 parent d903019 commit 991f821
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 47 deletions.
27 changes: 27 additions & 0 deletions .chloggen/try_windows_sshcheckreceiver.yaml
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: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: sshcheckreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for running this receiver on Windows

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [30650]

# (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, api]
3 changes: 1 addition & 2 deletions receiver/sshcheckreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ var (
errMissingUsername = errors.New(`"username" not specified in config`)
errMissingPasswordAndKeyFile = errors.New(`either "password" or "key_file" is required`)

errConfigNotSSHCheck = errors.New("config was not a SSH check receiver config")
errWindowsUnsupported = errors.New(metadata.Type.String() + " is unsupported on Windows.")
errConfigNotSSHCheck = errors.New("config was not a SSH check receiver config")
)

type Config struct {
Expand Down
4 changes: 0 additions & 4 deletions receiver/sshcheckreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ func createDefaultConfig() component.Config {
}

func createMetricsReceiver(_ context.Context, params receiver.CreateSettings, rConf component.Config, consumer consumer.Metrics) (receiver.Metrics, error) {
// return error if sshcheckreceiver on Windows
if !supportedOS() {
return nil, errWindowsUnsupported
}

cfg, ok := rConf.(*Config)
if !ok {
Expand Down
17 changes: 0 additions & 17 deletions receiver/sshcheckreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (
)

func TestNewFactory(t *testing.T) {
if !supportedOS() {
t.Skip("Skip tests if not running on one of: [linux, darwin, freebsd, openbsd]")
}
t.Parallel()
testCases := []struct {
desc string
Expand Down Expand Up @@ -85,17 +82,3 @@ func TestNewFactory(t *testing.T) {
t.Run(tc.desc, tc.testFunc)
}
}

func TestWindowsReceiverUnsupported(t *testing.T) {
if supportedOS() {
t.Skip("Skip test if not running windows.")
}
factory := NewFactory()
_, err := factory.CreateMetricsReceiver(
context.Background(),
receivertest.NewNopCreateSettings(),
nil,
consumertest.NewNop(),
)
require.ErrorIs(t, err, errWindowsUnsupported)
}
8 changes: 0 additions & 8 deletions receiver/sshcheckreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package sshcheckreceiver // import "github.com/open-telemetry/opentelemetry-coll
import (
"context"
"errors"
"runtime"
"time"

"go.opentelemetry.io/collector/component"
Expand All @@ -30,9 +29,6 @@ type sshcheckScraper struct {
// start starts the scraper by creating a new SSH Client on the scraper
func (s *sshcheckScraper) start(_ context.Context, host component.Host) error {
var err error
if !supportedOS() {
return errWindowsUnsupported
}
s.Client, err = s.Config.ToClient(host, s.settings)
return err
}
Expand Down Expand Up @@ -136,7 +132,3 @@ func newScraper(conf *Config, settings receiver.CreateSettings) *sshcheckScraper
mb: metadata.NewMetricsBuilder(conf.MetricsBuilderConfig, settings),
}
}

func supportedOS() bool {
return !(runtime.GOOS == "windows")
}
16 changes: 0 additions & 16 deletions receiver/sshcheckreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ func handleChannels(chans <-chan ssh.NewChannel) {
}

func TestScraper(t *testing.T) {
if !supportedOS() {
t.Skip("Skip tests if not running on one of: [linux, darwin, freebsd, openbsd]")
}
endpoint := setupSSHServer(t)
require.NotEmpty(t, endpoint)

Expand Down Expand Up @@ -184,9 +181,6 @@ func TestScraper(t *testing.T) {
}

func TestScraperPropagatesResourceAttributes(t *testing.T) {
if !supportedOS() {
t.Skip("Skip tests if not running on one of: [linux, darwin, freebsd, openbsd]")
}
endpoint := setupSSHServer(t)
require.NotEmpty(t, endpoint)

Expand Down Expand Up @@ -220,9 +214,6 @@ func TestScraperPropagatesResourceAttributes(t *testing.T) {
}

func TestScraperDoesNotErrForSSHErr(t *testing.T) {
if !supportedOS() {
t.Skip("Skip tests if not running on one of: [linux, darwin, freebsd, openbsd]")
}
endpoint := setupSSHServer(t)
require.NotEmpty(t, endpoint)

Expand All @@ -244,9 +235,6 @@ func TestScraperDoesNotErrForSSHErr(t *testing.T) {
}

func TestTimeout(t *testing.T) {
if !supportedOS() {
t.Skip("Skip tests if not running on one of: [linux, darwin, freebsd, openbsd]")
}
testCases := []struct {
name string
deadline time.Time
Expand Down Expand Up @@ -284,10 +272,6 @@ func TestCancellation(t *testing.T) {
settings := receivertest.NewNopCreateSettings()

scrpr := newScraper(cfg, settings)
if !supportedOS() {
require.Error(t, scrpr.start(context.Background(), componenttest.NewNopHost()), "should err starting scraper")
return
}
require.NoError(t, scrpr.start(context.Background(), componenttest.NewNopHost()), "failed starting scraper")

ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 991f821

Please sign in to comment.