Skip to content

Commit

Permalink
[extension/awsproxy] add support for shutdown test (#31756)
Browse files Browse the repository at this point in the history
**Description:**
Change the lifecycle of the extension so that the creation of the AWS
client happens in the Start method, which helps with supporting
component lifecycle.

**Link to tracking Issue:**
Relates to #27849
  • Loading branch information
atoulme committed Apr 10, 2024
1 parent 77cf7f3 commit 13b2b03
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 13 deletions.
27 changes: 27 additions & 0 deletions .chloggen/awsproxy_lifecycle.yaml
@@ -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: awsproxyextension

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Make awsproxy extension more resilient by initiating the AWS client during Start.

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

# (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: []
22 changes: 12 additions & 10 deletions extension/awsproxy/extension.go
Expand Up @@ -24,7 +24,13 @@ type xrayProxy struct {

var _ extension.Extension = (*xrayProxy)(nil)

func (x xrayProxy) Start(_ context.Context, _ component.Host) error {
func (x *xrayProxy) Start(_ context.Context, _ component.Host) error {
srv, err := proxy.NewServer(&x.config.ProxyConfig, x.settings.Logger)

if err != nil {
return err
}
x.server = srv
go func() {
if err := x.server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) && err != nil {
x.settings.ReportStatus(component.NewFatalErrorEvent(err))
Expand All @@ -34,21 +40,17 @@ func (x xrayProxy) Start(_ context.Context, _ component.Host) error {
return nil
}

func (x xrayProxy) Shutdown(ctx context.Context) error {
return x.server.Shutdown(ctx)
func (x *xrayProxy) Shutdown(ctx context.Context) error {
if x.server != nil {
return x.server.Shutdown(ctx)
}
return nil
}

func newXrayProxy(config *Config, telemetrySettings component.TelemetrySettings) (extension.Extension, error) {
srv, err := proxy.NewServer(&config.ProxyConfig, telemetrySettings.Logger)

if err != nil {
return nil, err
}

p := &xrayProxy{
config: config,
logger: telemetrySettings.Logger,
server: srv,
settings: telemetrySettings,
}

Expand Down
6 changes: 5 additions & 1 deletion extension/awsproxy/extension_test.go
Expand Up @@ -4,6 +4,7 @@
package awsproxy

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -14,7 +15,7 @@ import (
)

func TestInvalidEndpoint(t *testing.T) {
_, err := newXrayProxy(
x, err := newXrayProxy(
&Config{
ProxyConfig: proxy.Config{
TCPAddrConfig: confignet.TCPAddrConfig{
Expand All @@ -24,5 +25,8 @@ func TestInvalidEndpoint(t *testing.T) {
},
componenttest.NewNopTelemetrySettings(),
)
assert.NoError(t, err)
err = x.Start(context.Background(), componenttest.NewNopHost())
defer assert.NoError(t, x.Shutdown(context.Background()))
assert.Error(t, err)
}
30 changes: 30 additions & 0 deletions extension/awsproxy/generated_component_test.go

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

2 changes: 0 additions & 2 deletions extension/awsproxy/metadata.yaml
Expand Up @@ -9,7 +9,5 @@ status:
codeowners:
active: [Aneurysm9, mxiamxia]

# TODO: Update the extension to make the tests pass
tests:
skip_lifecycle: true
skip_shutdown: true

0 comments on commit 13b2b03

Please sign in to comment.