Skip to content

Commit

Permalink
Merge branch 'main' into fix/vcenter-tls
Browse files Browse the repository at this point in the history
  • Loading branch information
dehaansa authored Dec 3, 2024
2 parents f2c57e4 + 705cc64 commit 7da745e
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 26 deletions.
27 changes: 27 additions & 0 deletions .chloggen/opamp_supervisor_env_vars.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: cmd/opampsupervisor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Support environment variable expansion in the OpAMP supervisor config.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36269]

# (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]
6 changes: 5 additions & 1 deletion cmd/opampsupervisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.22.0

require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/go-viper/mapstructure/v2 v2.2.1
github.com/google/uuid v1.6.0
github.com/knadh/koanf/maps v0.1.1
github.com/knadh/koanf/parsers/yaml v0.1.0
Expand All @@ -15,6 +14,9 @@ require (
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/collector/config/configopaque v1.20.1-0.20241202231142-b9ff1bc54c99
go.opentelemetry.io/collector/config/configtls v1.20.1-0.20241202231142-b9ff1bc54c99
go.opentelemetry.io/collector/confmap v1.20.1-0.20241202231142-b9ff1bc54c99
go.opentelemetry.io/collector/confmap/provider/envprovider v1.20.1-0.20241202231142-b9ff1bc54c99
go.opentelemetry.io/collector/confmap/provider/fileprovider v1.20.1-0.20241202231142-b9ff1bc54c99
go.opentelemetry.io/collector/semconv v0.114.1-0.20241202231142-b9ff1bc54c99
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
Expand All @@ -26,8 +28,10 @@ require (
require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down
8 changes: 8 additions & 0 deletions cmd/opampsupervisor/go.sum

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

51 changes: 27 additions & 24 deletions cmd/opampsupervisor/supervisor/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package config

import (
"context"
"errors"
"fmt"
"net/http"
Expand All @@ -13,19 +14,18 @@ import (
"runtime"
"time"

"github.com/go-viper/mapstructure/v2"
"github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/v2"
"github.com/open-telemetry/opamp-go/protobufs"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/provider/envprovider"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
"go.uber.org/zap/zapcore"
)

// Supervisor is the Supervisor config file format.
type Supervisor struct {
Server OpAMPServer
Agent Agent
Server OpAMPServer `mapstructure:"server"`
Agent Agent `mapstructure:"agent"`
Capabilities Capabilities `mapstructure:"capabilities"`
Storage Storage `mapstructure:"storage"`
Telemetry Telemetry `mapstructure:"telemetry"`
Expand All @@ -37,26 +37,29 @@ func Load(configFile string) (Supervisor, error) {
return Supervisor{}, errors.New("path to config file cannot be empty")
}

k := koanf.New("::")
if err := k.Load(file.Provider(configFile), yaml.Parser()); err != nil {
return Supervisor{}, err
resolverSettings := confmap.ResolverSettings{
URIs: []string{configFile},
ProviderFactories: []confmap.ProviderFactory{
fileprovider.NewFactory(),
envprovider.NewFactory(),
},
ConverterFactories: []confmap.ConverterFactory{},
DefaultScheme: "env",
}

cfg := DefaultSupervisor()
resolver, err := confmap.NewResolver(resolverSettings)
if err != nil {
return Supervisor{}, err
}

decodeConf := koanf.UnmarshalConf{
Tag: "mapstructure",
DecoderConfig: &mapstructure.DecoderConfig{
DecodeHook: mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc()),
Result: &cfg,
WeaklyTypedInput: true,
ErrorUnused: true,
},
conf, err := resolver.Resolve(context.Background())
if err != nil {
return Supervisor{}, err
}

if err := k.UnmarshalWithConf("", &cfg, decodeConf); err != nil {
return Supervisor{}, fmt.Errorf("cannot parse %s: %w", configFile, err)
cfg := DefaultSupervisor()
if err = conf.Unmarshal(&cfg); err != nil {
return Supervisor{}, err
}

if err := cfg.Validate(); err != nil {
Expand Down Expand Up @@ -129,8 +132,8 @@ func (c Capabilities) SupportedCapabilities() protobufs.AgentCapabilities {
}

type OpAMPServer struct {
Endpoint string
Headers http.Header
Endpoint string `mapstructure:"endpoint"`
Headers http.Header `mapstructure:"headers"`
TLSSetting configtls.ClientConfig `mapstructure:"tls,omitempty"`
}

Expand Down Expand Up @@ -159,7 +162,7 @@ func (o OpAMPServer) Validate() error {
}

type Agent struct {
Executable string
Executable string `mapstructure:"executable"`
OrphanDetectionInterval time.Duration `mapstructure:"orphan_detection_interval"`
Description AgentDescription `mapstructure:"description"`
ConfigApplyTimeout time.Duration `mapstructure:"config_apply_timeout"`
Expand Down
Loading

0 comments on commit 7da745e

Please sign in to comment.