From f6c046e8595729aa06e5c9197f65d2f5e74ba07a Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Wed, 14 Apr 2021 11:14:09 +0200 Subject: [PATCH] Correctly map `dragonfly` value to `DRAGONFLYBSD` Relates to open-telemetry/opentelemetry-specification#1572 --- .../internal/system/metadata.go | 11 +++++++- .../internal/system/metadata_test.go | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 processor/resourcedetectionprocessor/internal/system/metadata_test.go diff --git a/processor/resourcedetectionprocessor/internal/system/metadata.go b/processor/resourcedetectionprocessor/internal/system/metadata.go index d7d275d67395..5e8fca4a7ff9 100644 --- a/processor/resourcedetectionprocessor/internal/system/metadata.go +++ b/processor/resourcedetectionprocessor/internal/system/metadata.go @@ -31,8 +31,17 @@ type systemMetadata interface { type systemMetadataImpl struct{} +// goosToOSType maps a runtime.GOOS-like value to os.type style. +func goosToOSType(goos string) string { + switch goos { + case "dragonfly": + return "DRAGONFLYBSD" + } + return strings.ToUpper(goos) +} + func (*systemMetadataImpl) OSType() (string, error) { - return strings.ToUpper(runtime.GOOS), nil + return goosToOSType(runtime.GOOS), nil } func (*systemMetadataImpl) FQDN() (string, error) { diff --git a/processor/resourcedetectionprocessor/internal/system/metadata_test.go b/processor/resourcedetectionprocessor/internal/system/metadata_test.go new file mode 100644 index 000000000000..aaef0ed0596c --- /dev/null +++ b/processor/resourcedetectionprocessor/internal/system/metadata_test.go @@ -0,0 +1,28 @@ +// Copyright The 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. + +package system + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGOOSToOsType(t *testing.T) { + assert.Equal(t, "DARWIN", goosToOSType("darwin")) + assert.Equal(t, "LINUX", goosToOSType("linux")) + assert.Equal(t, "WINDOWS", goosToOSType("windows")) + assert.Equal(t, "DRAGONFLYBSD", goosToOSType("dragonfly")) +}