Skip to content

Commit

Permalink
[receiver/sshcheck] enable Windows (#30648)
Browse files Browse the repository at this point in the history
Removes the checks forbidding to use sshcheckreceiver on Windows.

Fixes #30650

Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
atoulme and codeboten authored Apr 29, 2024
1 parent 9bd1201 commit 06c970d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 51 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]
1 change: 0 additions & 1 deletion receiver/sshcheckreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
| Status | |
| ------------- |-----------|
| Stability | [alpha]: metrics |
| Unsupported Platforms | windows |
| Distributions | [contrib] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fsshcheck%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fsshcheck) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fsshcheck%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fsshcheck) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@nslaughter](https://www.github.com/nslaughter), [@codeboten](https://www.github.com/codeboten) |
Expand Down
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)
}
1 change: 0 additions & 1 deletion receiver/sshcheckreceiver/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion receiver/sshcheckreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ status:
distributions: [contrib]
codeowners:
active: [nslaughter, codeboten]
unsupported_platforms: [windows]

resource_attributes:
ssh.endpoint:
Expand Down
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")
}
17 changes: 0 additions & 17 deletions receiver/sshcheckreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,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]")
}

s, err := newSSHServer("tcp", "127.0.0.1:0")
require.NoError(t, err)
endpoint := s.runSSHServer(t)
Expand Down Expand Up @@ -212,9 +208,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]")
}
s, err := newSSHServer("tcp", "127.0.0.1:0")
require.NoError(t, err)
endpoint := s.runSSHServer(t)
Expand Down Expand Up @@ -251,9 +244,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]")
}
s, err := newSSHServer("tcp", "127.0.0.1:0")
require.NoError(t, err)
endpoint := s.runSSHServer(t)
Expand All @@ -278,9 +268,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 @@ -318,10 +305,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 06c970d

Please sign in to comment.