Skip to content

Commit

Permalink
all exporter tests are passing now need to test this on ec2
Browse files Browse the repository at this point in the history
  • Loading branch information
Paramadon committed Dec 10, 2024
1 parent 0a96c0c commit cb1f3df
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
18 changes: 16 additions & 2 deletions exporter/awscloudwatchlogsexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func init() {
type mockPusher struct {
mock.Mock
}
type mockHost struct {
component.Host
}

func (m *mockHost) GetExtensions() map[component.ID]component.Component {
return nil
}

func (p *mockPusher) AddLogEntry(_ *cwlogs.Event) error {
args := p.Called(nil)
Expand Down Expand Up @@ -509,7 +516,14 @@ func TestNewExporterWithoutRegionErr(t *testing.T) {
factory := NewFactory()
expCfg := factory.CreateDefaultConfig().(*Config)
expCfg.MaxRetries = 0
expCfg.Region = "" // Ensure the region is not set

exp, err := newCwLogsExporter(expCfg, exportertest.NewNopSettings())
assert.Nil(t, exp)
assert.Error(t, err)
assert.NoError(t, err) // The exporter creation should not fail
assert.NotNil(t, exp) // The exporter should be created

// Now try to start the exporter
err = exp.Start(context.Background(), &mockHost{})
assert.Error(t, err) // The start should fail due to missing region
assert.Contains(t, err.Error(), "NoAwsRegion")
}
29 changes: 17 additions & 12 deletions exporter/awsxrayexporter/awsxray.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,10 @@ func newTracesExporter(
typeLog := zap.String("type", set.ID.Type().String())
nameLog := zap.String("name", set.ID.String())
logger := set.Logger
awsConfig, session, err := awsutil.GetAWSConfigSession(logger, cn, &cfg.AWSSessionSettings)
if err != nil {
return nil, err
}
xrayClient := awsxray.NewXRayClient(logger, awsConfig, set.BuildInfo, session)
sender := telemetry.NewNopSender()
if cfg.TelemetryConfig.Enabled {
opts := telemetry.ToOptions(cfg.TelemetryConfig, session, &cfg.AWSSessionSettings)
opts = append(opts, telemetry.WithLogger(set.Logger))
sender = registry.Register(set.ID, cfg.TelemetryConfig, xrayClient, opts...)
}

var xrayClient awsxray.XRayClient
var sender telemetry.Sender = telemetry.NewNopSender()

return exporterhelper.NewTracesExporter(
context.TODO(),
set,
Expand Down Expand Up @@ -99,7 +92,19 @@ func newTracesExporter(
}
return err
},
exporterhelper.WithStart(func(_ context.Context, host component.Host) error {
exporterhelper.WithStart(func(ctx context.Context, host component.Host) error {
awsConfig, session, err := awsutil.GetAWSConfigSession(logger, cn, &cfg.AWSSessionSettings)
if err != nil {
return err
}
xrayClient = awsxray.NewXRayClient(logger, awsConfig, set.BuildInfo, session)

if cfg.TelemetryConfig.Enabled {
opts := telemetry.ToOptions(cfg.TelemetryConfig, session, &cfg.AWSSessionSettings)
opts = append(opts, telemetry.WithLogger(set.Logger))
sender = registry.Register(set.ID, cfg.TelemetryConfig, xrayClient, opts...)
}

sender.Start()
if cfg.MiddlewareID != nil {
awsmiddleware.TryConfigure(logger, host, *cfg.MiddlewareID, awsmiddleware.SDKv1(xrayClient.Handlers()))
Expand Down
13 changes: 12 additions & 1 deletion exporter/awsxrayexporter/awsxray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,27 @@ func BenchmarkForTracesExporter(b *testing.B) {
}
}

type mockHost struct {
component.Host
}

func (m *mockHost) GetExtensions() map[component.ID]component.Component {
return nil
}

func initializeTracesExporter(t testing.TB, exporterConfig *Config, registry telemetry.Registry) exporter.Traces {
t.Helper()
mconn := new(awsutil.Conn)
traceExporter, err := newTracesExporter(exporterConfig, exportertest.NewNopSettings(), mconn, registry)
if err != nil {
panic(err)
}
err = traceExporter.Start(context.Background(), &mockHost{})
if err != nil {
panic(err)
}
return traceExporter
}

func generateConfig(t testing.TB) *Config {
t.Setenv("AWS_ACCESS_KEY_ID", "AKIASSWVJUY4PZXXXXXX")
t.Setenv("AWS_SECRET_ACCESS_KEY", "XYrudg2H87u+ADAAq19Wqx3D41a09RsTXXXXXXXX")
Expand Down

0 comments on commit cb1f3df

Please sign in to comment.