Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update otelcol deps to 0.67.0 #2358

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cmd/otelcol/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/provider/envprovider"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/otelcol"
"go.uber.org/zap"

"github.com/signalfx/splunk-otel-collector/internal/components"
Expand Down Expand Up @@ -74,8 +74,8 @@ func main() {

envProvider := envprovider.New()
fileProvider := fileprovider.New()
serviceConfigProvider, err := service.NewConfigProvider(
service.ConfigProviderSettings{
serviceConfigProvider, err := otelcol.NewConfigProvider(
otelcol.ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
URIs: collectorSettings.ResolverURIs(),
Providers: map[string]confmap.Provider{
Expand All @@ -100,7 +100,7 @@ func main() {
log.Fatal(err)
}

serviceSettings := service.CollectorSettings{
serviceSettings := otelcol.CollectorSettings{
BuildInfo: info,
Factories: factories,
ConfigProvider: serviceConfigProvider,
Expand All @@ -112,8 +112,8 @@ func main() {
}
}

func runInteractive(settings service.CollectorSettings) error {
cmd := service.NewCommand(settings)
func runInteractive(settings otelcol.CollectorSettings) error {
cmd := otelcol.NewCommand(settings)
if err := cmd.Execute(); err != nil {
return fmt.Errorf("application run finished with error: %w", err)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/otelcol/main_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

package main

import "go.opentelemetry.io/collector/service"
import (
"go.opentelemetry.io/collector/otelcol"
)

func run(params service.CollectorSettings) error {
func run(params otelcol.CollectorSettings) error {
return runInteractive(params)
}
8 changes: 4 additions & 4 deletions cmd/otelcol/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"fmt"
"os"

"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/otelcol"
"golang.org/x/sys/windows/svc"
)

func run(params service.CollectorSettings) error {
func run(params otelcol.CollectorSettings) error {
if useInteractiveMode, err := checkUseInteractiveMode(); err != nil {
return err
} else if useInteractiveMode {
Expand All @@ -52,9 +52,9 @@ func checkUseInteractiveMode() (bool, error) {
}
}

func runService(params service.CollectorSettings) error {
func runService(params otelcol.CollectorSettings) error {
// do not need to supply service name when startup is invoked through Service Control Manager directly
if err := svc.Run("", service.NewSvcHandler(params)); err != nil {
if err := svc.Run("", otelcol.NewSvcHandler(params)); err != nil {
return fmt.Errorf("failed to start service: %w", err)
}

Expand Down
270 changes: 143 additions & 127 deletions go.mod

Large diffs are not rendered by default.

562 changes: 288 additions & 274 deletions go.sum

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions internal/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/windowsperfcountersreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinreceiver"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/loggingexporter"
"go.opentelemetry.io/collector/exporter/otlpexporter"
"go.opentelemetry.io/collector/exporter/otlphttpexporter"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/extension/ballastextension"
"go.opentelemetry.io/collector/extension/zpagesextension"
"go.opentelemetry.io/collector/processor/batchprocessor"
"go.opentelemetry.io/collector/processor/memorylimiterprocessor"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/otlpreceiver"
"go.uber.org/multierr"

Expand All @@ -96,7 +99,7 @@ import (

func Get() (component.Factories, error) {
var errs []error
extensions, err := component.MakeExtensionFactoryMap(
extensions, err := extension.MakeFactoryMap(
ecsobserver.NewFactory(),
ecstaskobserver.NewFactory(),
dockerobserver.NewFactory(),
Expand All @@ -114,7 +117,7 @@ func Get() (component.Factories, error) {
errs = append(errs, err)
}

receivers, err := component.MakeReceiverFactoryMap(
receivers, err := receiver.MakeFactoryMap(
azureeventhubreceiver.NewFactory(),
carbonreceiver.NewFactory(),
cloudfoundryreceiver.NewFactory(),
Expand Down Expand Up @@ -154,7 +157,7 @@ func Get() (component.Factories, error) {
errs = append(errs, err)
}

exporters, err := component.MakeExporterFactoryMap(
exporters, err := exporter.MakeFactoryMap(
fileexporter.NewFactory(),
kafkaexporter.NewFactory(),
loggingexporter.NewFactory(),
Expand Down
65 changes: 65 additions & 0 deletions internal/configconverter/overwrite_properties.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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.

// Taken from https://github.com/open-telemetry/opentelemetry-collector/blob/v0.66.0/confmap/converter/overwritepropertiesconverter/properties.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find, nice reuse

// to prevent breaking changes.
// "Deprecated: [v0.63.0] this converter will not be supported anymore because of dot separation limitation.
// See https://github.com/open-telemetry/opentelemetry-collector/issues/6294 for more details."
package configconverter

import (
"bytes"
"context"
"strings"

"github.com/knadh/koanf/maps"
"github.com/magiconair/properties"
"go.opentelemetry.io/collector/confmap"
)

type converter struct {
properties []string
}

func NewOverwritePropertiesConverter(properties []string) confmap.Converter {
return &converter{properties: properties}
}

func (c *converter) Convert(_ context.Context, conf *confmap.Conf) error {
if len(c.properties) == 0 {
return nil
}

b := &bytes.Buffer{}
for _, property := range c.properties {
property = strings.TrimSpace(property)
b.WriteString(property)
b.WriteString("\n")
}

var props *properties.Properties
var err error
if props, err = properties.Load(b.Bytes(), properties.UTF8); err != nil {
return err
}

// Create a map manually instead of using properties.Map() to not expand the env vars.
parsed := make(map[string]interface{}, props.Len())
for _, key := range props.Keys() {
value, _ := props.Get(key)
parsed[key] = value
}
prop := maps.Unflatten(parsed, ".")
return conf.Merge(confmap.NewFromStringMap(prop))
}
58 changes: 58 additions & 0 deletions internal/configconverter/overwrite_properties_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.

// Taken from https://github.com/open-telemetry/opentelemetry-collector/blob/v0.66.0/confmap/converter/overwritepropertiesconverter/properties_test.go
// to prevent breaking changes.
package configconverter

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/confmap"
)

func TestOverwritePropertiesConverter_Empty(t *testing.T) {
pmp := NewOverwritePropertiesConverter(nil)
conf := confmap.NewFromStringMap(map[string]interface{}{"foo": "bar"})
assert.NoError(t, pmp.Convert(context.Background(), conf))
assert.Equal(t, map[string]interface{}{"foo": "bar"}, conf.ToStringMap())
}

func TestOverwritePropertiesConverter(t *testing.T) {
props := []string{
"processors.batch.timeout=2s",
"processors.batch/foo.timeout=3s",
"receivers.otlp.protocols.grpc.endpoint=localhost:1818",
"exporters.kafka.brokers=foo:9200,foo2:9200",
}

pmp := NewOverwritePropertiesConverter(props)
conf := confmap.New()
require.NoError(t, pmp.Convert(context.Background(), conf))
keys := conf.AllKeys()
assert.Len(t, keys, 4)
assert.Equal(t, "2s", conf.Get("processors::batch::timeout"))
assert.Equal(t, "3s", conf.Get("processors::batch/foo::timeout"))
assert.Equal(t, "foo:9200,foo2:9200", conf.Get("exporters::kafka::brokers"))
assert.Equal(t, "localhost:1818", conf.Get("receivers::otlp::protocols::grpc::endpoint"))
}

func TestOverwritePropertiesConverter_InvalidProperty(t *testing.T) {
pmp := NewOverwritePropertiesConverter([]string{"=2s"})
conf := confmap.New()
assert.Error(t, pmp.Convert(context.Background(), conf))
}
Loading