From 7a8af915517a70562729f076f78a3fb6ca4cf31e Mon Sep 17 00:00:00 2001 From: Ryan Fitzpatrick Date: Thu, 27 Jan 2022 11:09:29 -0500 Subject: [PATCH] provide informative unsupported monitor error on windows (#1150) --- CHANGELOG.md | 4 ++ .../receiver/smartagentreceiver/config.go | 19 ++++++++- .../smartagentreceiver/config_windows_test.go | 42 +++++++++++++++++++ .../testdata/collectd_apache.yaml | 16 +++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 internal/receiver/smartagentreceiver/config_windows_test.go create mode 100644 internal/receiver/smartagentreceiver/testdata/collectd_apache.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 658d1ec4c92..818d09d6cb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### 🧰 Bug fixes 🧰 + +- Provide informative unsupported monitor error on Windows for Smart Agent receiver [#1150](https://github.com/signalfx/splunk-otel-collector/pull/1150) + ## v0.42.0 This Splunk OpenTelemetry Collector release includes changes from the [opentelemetry-collector v0.42.0](https://github.com/open-telemetry/opentelemetry-collector/releases/tag/v0.42.0) and the [opentelemetry-collector-contrib v0.42.0](https://github.com/open-telemetry/opentelemetry-collector-contrib/releases/tag/v0.42.0) releases. diff --git a/internal/receiver/smartagentreceiver/config.go b/internal/receiver/smartagentreceiver/config.go index ddfc25ee8d8..e81f0813e24 100644 --- a/internal/receiver/smartagentreceiver/config.go +++ b/internal/receiver/smartagentreceiver/config.go @@ -18,6 +18,7 @@ import ( "fmt" "net" "reflect" + "runtime" "strconv" "github.com/signalfx/defaults" @@ -31,9 +32,20 @@ import ( const defaultIntervalSeconds = 10 -var _ config.Unmarshallable = (*Config)(nil) +var ( + _ config.Unmarshallable = (*Config)(nil) -var errDimensionClientValue = fmt.Errorf("dimensionClients must be an array of compatible exporter names") + errDimensionClientValue = fmt.Errorf("dimensionClients must be an array of compatible exporter names") + nonWindowsMonitors = map[string]bool{ + "collectd/activemq": true, "collectd/apache": true, "collectd/cassandra": true, "collectd/chrony": true, + "collectd/cpu": true, "collectd/cpufreq": true, "collectd/custom": true, "collectd/df": true, "collectd/disk": true, + "collectd/genericjmx": true, "collectd/hadoop": true, "collectd/kafka": true, "collectd/kafka_consumer": true, + "collectd/kafka_producer": true, "collectd/load": true, "collectd/memcached": true, "collectd/memory": true, + "collectd/mysql": true, "collectd/netinterface": true, "collectd/nginx": true, "collectd/php-fpm": true, + "collectd/postgresql": true, "collectd/processes": true, "collectd/protocols": true, + "collectd/signalfx-metadata": true, "collectd/statsd": true, "collectd/uptime": true, "collectd/vmem": true, + } +) type Config struct { monitorConfig saconfig.MonitorCustomConfig @@ -91,6 +103,9 @@ func (cfg *Config) Unmarshal(componentParser *config.Map) error { // The values are always pointers to an actual custom config. var customMonitorConfig saconfig.MonitorCustomConfig if customMonitorConfig, ok = monitors.ConfigTemplates[monitorType]; !ok { + if unsupported := nonWindowsMonitors[monitorType]; runtime.GOOS == "windows" && unsupported { + return fmt.Errorf("smart agent monitor type %q is not supported on windows platforms", monitorType) + } return fmt.Errorf("no known monitor type %q", monitorType) } monitorConfigType := reflect.TypeOf(customMonitorConfig).Elem() diff --git a/internal/receiver/smartagentreceiver/config_windows_test.go b/internal/receiver/smartagentreceiver/config_windows_test.go new file mode 100644 index 00000000000..b8db945a947 --- /dev/null +++ b/internal/receiver/smartagentreceiver/config_windows_test.go @@ -0,0 +1,42 @@ +// Copyright OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//go:build windows +// +build windows + +package smartagentreceiver + +import ( + "path" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component/componenttest" + "go.opentelemetry.io/collector/service/servicetest" +) + +func TestLoadUnsupportedCollectdMonitorOnWindows(t *testing.T) { + factories, err := componenttest.NopFactories() + assert.Nil(t, err) + + factory := NewFactory() + factories.Receivers[typeStr] = factory + cfg, err := servicetest.LoadConfig( + path.Join(".", "testdata", "collectd_apache.yaml"), factories, + ) + require.Error(t, err) + require.EqualError(t, err, + `error reading receivers configuration for "smartagent/collectd/apache": smart agent monitor type "collectd/apache" is not supported on windows platforms`) + require.Nil(t, cfg) +} diff --git a/internal/receiver/smartagentreceiver/testdata/collectd_apache.yaml b/internal/receiver/smartagentreceiver/testdata/collectd_apache.yaml new file mode 100644 index 00000000000..63cdafc4600 --- /dev/null +++ b/internal/receiver/smartagentreceiver/testdata/collectd_apache.yaml @@ -0,0 +1,16 @@ +receivers: + smartagent/collectd/apache: + type: collectd/apache + +processors: + nop: + +exporters: + nop: + +service: + pipelines: + metrics: + receivers: [smartagent/collectd/apache] + processors: [nop] + exporters: [nop]