Skip to content

Commit

Permalink
provide informative unsupported monitor error on windows (open-teleme…
Browse files Browse the repository at this point in the history
  • Loading branch information
rmfitzpatrick authored Jan 27, 2022
1 parent c6ce50c commit 7a8af91
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 17 additions & 2 deletions internal/receiver/smartagentreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"net"
"reflect"
"runtime"
"strconv"

"github.com/signalfx/defaults"
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
42 changes: 42 additions & 0 deletions internal/receiver/smartagentreceiver/config_windows_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
16 changes: 16 additions & 0 deletions internal/receiver/smartagentreceiver/testdata/collectd_apache.yaml
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 7a8af91

Please sign in to comment.