Skip to content

Commit

Permalink
Upgrade Contrib to v0.103.0 (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
okankoAMZ authored Aug 5, 2024
1 parent dab6b24 commit f9beaec
Show file tree
Hide file tree
Showing 47 changed files with 3,896 additions and 3,866 deletions.
39 changes: 16 additions & 23 deletions cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"flag"
"fmt"
"io"
"log"
"net/http"
_ "net/http/pprof" // Comment this line to disable pprof endpoint.
Expand All @@ -30,8 +29,8 @@ import (
"github.com/influxdata/wlog"
"github.com/kardianos/service"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/otelcol"
"go.uber.org/zap"

configaws "github.com/aws/amazon-cloudwatch-agent/cfg/aws"
"github.com/aws/amazon-cloudwatch-agent/cfg/envconfig"
Expand Down Expand Up @@ -242,7 +241,6 @@ func runAgent(ctx context.Context,
c := config.NewConfig()
c.OutputFilters = outputFilters
c.InputFilters = inputFilters

err = loadTomlConfigIntoAgent(c)
if err != nil {
return err
Expand Down Expand Up @@ -289,7 +287,6 @@ func runAgent(ctx context.Context,
testWaitDuration := time.Duration(*fTestWait) * time.Second
return ag.Test(ctx, testWaitDuration)
}

if *fPidfile != "" {
f, err := os.OpenFile(*fPidfile, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
Expand All @@ -307,7 +304,6 @@ func runAgent(ctx context.Context,
}()
}
}

if len(c.Inputs) != 0 && len(c.Outputs) != 0 {
log.Println("creating new logs agent")
logAgent := logs.NewLogAgent(c)
Expand All @@ -323,9 +319,11 @@ func runAgent(ctx context.Context,
}
}
// Else start OTEL and rely on adapter package to start the logfile plugin.

yamlConfigPath := *fOtelConfig
provider, err := configprovider.Get(yamlConfigPath)
level := cwaLogger.ConvertToAtomicLevel(wlog.LogLevel())
logger, loggerOptions := cwaLogger.NewLogger(writer, level)
providerSettings := configprovider.GetSettings(yamlConfigPath, logger)
provider, err := otelcol.NewConfigProvider(providerSettings)
if err != nil {
log.Printf("E! Error while initializing config provider: %v\n", err)
return err
Expand All @@ -341,31 +339,28 @@ func runAgent(ctx context.Context,
if err != nil {
return err
}

useragent.Get().SetComponents(cfg, c)

params := getCollectorParams(factories, provider, writer)

_ = featuregate.GlobalRegistry().Set("exporter.xray.allowDot", true)
params := getCollectorParams(factories, providerSettings, loggerOptions)
cmd := otelcol.NewCommand(params)

// Noticed that args of parent process get passed here to otel collector which causes failures complaining about
// unrecognized args. So below change overwrites the args. Need to investigate this further as I dont think the config
// path below here is actually used and it still respects what was set in the settings above.
e := []string{"--config=" + yamlConfigPath + " --feature-gates=exporter.xray.allowDot"}
// *************************************************************************************************
// ⚠️ WARNING ⚠️
// Noticed that args of parent process get passed here to otel collector which causes failures
// complaining about unrecognized args. So below change overwrites the args.
// The config path below here is actually used that was set in the settings above.
// docs: https://github.com/open-telemetry/opentelemetry-collector/blob/93cbae436ae61b832279dbbb18a0d99214b7d305/otelcol/command.go#L63
// *************************************************************************************************
e := []string{"--config=" + yamlConfigPath}
cmd.SetArgs(e)

return cmd.Execute()
}

func getCollectorParams(factories otelcol.Factories, provider otelcol.ConfigProvider, writer io.Writer) otelcol.CollectorSettings {
level := cwaLogger.ConvertToAtomicLevel(wlog.LogLevel())
loggingOptions := cwaLogger.NewLoggerOptions(writer, level)
func getCollectorParams(factories otelcol.Factories, providerSettings otelcol.ConfigProviderSettings, loggingOptions []zap.Option) otelcol.CollectorSettings {
return otelcol.CollectorSettings{
Factories: func() (otelcol.Factories, error) {
return factories, nil
},
ConfigProvider: provider,
ConfigProviderSettings: providerSettings,
// build info is essential for populating the user agent string in otel contrib upstream exporters, like the EMF exporter
BuildInfo: component.BuildInfo{
Command: "CWAgent",
Expand Down Expand Up @@ -427,7 +422,6 @@ func (p *program) Stop(_ service.Service) error {
func main() {
flag.Parse()
args := flag.Args()

sectionFilters, inputFilters, outputFilters := []string{}, []string{}, []string{}
if *fSectionFilters != "" {
sectionFilters = strings.Split(":"+strings.TrimSpace(*fSectionFilters)+":", ":")
Expand All @@ -448,7 +442,6 @@ func main() {
}

logger.SetupLogging(logger.LogConfig{})

if *pprofAddr != "" {
go func() {
pprofHostPort := *pprofAddr
Expand Down
16 changes: 9 additions & 7 deletions cmd/amazon-cloudwatch-agent/amazon-cloudwatch-agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (

func Test_getCollectorParams(t *testing.T) {
type args struct {
factories otelcol.Factories
provider otelcol.ConfigProvider
factories otelcol.Factories
providerSettings otelcol.ConfigProviderSettings
}

_, loggerOptions := logger.NewLogger(os.Stderr, zap.NewAtomicLevelAt(zapcore.InfoLevel))
tests := []struct {
name string
args args
Expand All @@ -30,28 +32,28 @@ func Test_getCollectorParams(t *testing.T) {
{
name: "BuildInfoIsSet",
args: args{
factories: otelcol.Factories{},
provider: nil,
factories: otelcol.Factories{},
providerSettings: otelcol.ConfigProviderSettings{},
},
want: otelcol.CollectorSettings{
Factories: func() (otelcol.Factories, error) {
return otelcol.Factories{}, nil
},
ConfigProvider: nil,
ConfigProviderSettings: otelcol.ConfigProviderSettings{},
BuildInfo: component.BuildInfo{
Command: "CWAgent",
Description: "CloudWatch Agent",
Version: "Unknown",
},
LoggingOptions: logger.NewLoggerOptions(os.Stderr, zap.NewAtomicLevelAt(zapcore.InfoLevel)),
LoggingOptions: loggerOptions,
},
},
}
for _, tt := range tests {
logger.SetLevel(zap.NewAtomicLevelAt(zapcore.InfoLevel))
wlog.SetLevel(wlog.INFO)
t.Run(tt.name, func(t *testing.T) {
got := getCollectorParams(tt.args.factories, tt.args.provider, os.Stderr)
got := getCollectorParams(tt.args.factories, tt.args.providerSettings, tt.want.LoggingOptions)
if deep.Equal(got, tt.want) != nil {
t.Errorf("getCollectorParams() = %v, want %v", got, tt.want)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/agenthealth/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestLoadConfig(t *testing.T) {
cfg := NewFactory().CreateDefaultConfig()
sub, err := conf.Sub(testCase.id.String())
require.NoError(t, err)
require.NoError(t, component.UnmarshalConfig(sub, cfg))
require.NoError(t, sub.Unmarshal(cfg))

assert.NoError(t, component.ValidateConfig(cfg))
assert.Equal(t, testCase.want, cfg)
Expand Down
Loading

0 comments on commit f9beaec

Please sign in to comment.