Skip to content

Commit

Permalink
Fix extensions to enable unparam (#1504)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Aug 5, 2020
1 parent 38453fd commit 8b55cb6
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 51 deletions.
4 changes: 2 additions & 2 deletions extension/fluentbitextension/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func constructArgs(tcpEndpoint string) []string {
}
}

func (pm *processManager) Start(ctx context.Context, host component.Host) error {
func (pm *processManager) Start(ctx context.Context, _ component.Host) error {
childCtx, cancel := context.WithCancel(ctx)
pm.cancel = cancel

Expand All @@ -84,7 +84,7 @@ func (pm *processManager) Start(ctx context.Context, host component.Host) error
}

// Shutdown is invoked during service shutdown.
func (pm *processManager) Shutdown(ctx context.Context) error {
func (pm *processManager) Shutdown(context.Context) error {
pm.cancel()
t := time.NewTimer(5 * time.Second)

Expand Down
6 changes: 4 additions & 2 deletions extension/fluentbitextension/process_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package fluentbitextension

import "os/exec"
import (
"os/exec"
)

func applyOSSpecificCmdModifications(cmd *exec.Cmd) {}
func applyOSSpecificCmdModifications(_ *exec.Cmd) {}
2 changes: 1 addition & 1 deletion extension/healthcheckextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (f *Factory) CreateExtension(_ context.Context, params component.ExtensionC
return nil, errors.New("only a single instance can be created per process")
}

return newServer(*config, params.Logger)
return newServer(*config, params.Logger), nil
}

// See comment in CreateExtension how these are used.
Expand Down
6 changes: 3 additions & 3 deletions extension/healthcheckextension/healthcheckextension.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type healthCheckExtension struct {

var _ component.PipelineWatcher = (*healthCheckExtension)(nil)

func (hc *healthCheckExtension) Start(ctx context.Context, host component.Host) error {
func (hc *healthCheckExtension) Start(_ context.Context, host component.Host) error {

hc.logger.Info("Starting health_check extension", zap.Any("config", hc.config))

Expand Down Expand Up @@ -74,7 +74,7 @@ func (hc *healthCheckExtension) NotReady() error {
return nil
}

func newServer(config Config, logger *zap.Logger) (*healthCheckExtension, error) {
func newServer(config Config, logger *zap.Logger) *healthCheckExtension {
hc := &healthCheckExtension{
config: config,
logger: logger,
Expand All @@ -84,5 +84,5 @@ func newServer(config Config, logger *zap.Logger) (*healthCheckExtension, error)

hc.state.SetLogger(logger)

return hc, nil
return hc
}
15 changes: 5 additions & 10 deletions extension/healthcheckextension/healthcheckextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func TestHealthCheckExtensionUsage(t *testing.T) {
Port: testutil.GetAvailablePort(t),
}

hcExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
hcExt := newServer(config, zap.NewNop())
require.NotNil(t, hcExt)

require.NoError(t, hcExt.Start(context.Background(), componenttest.NewNopHost()))
Expand Down Expand Up @@ -84,8 +83,7 @@ func TestHealthCheckExtensionPortAlreadyInUse(t *testing.T) {
config := Config{
Port: uint16(port),
}
hcExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
hcExt := newServer(config, zap.NewNop())
require.NotNil(t, hcExt)

// Health check will report port already in use in a goroutine, use the error waiting
Expand All @@ -103,8 +101,7 @@ func TestHealthCheckMultipleStarts(t *testing.T) {
Port: testutil.GetAvailablePort(t),
}

hcExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
hcExt := newServer(config, zap.NewNop())
require.NotNil(t, hcExt)

mh := componenttest.NewErrorWaitingHost()
Expand All @@ -125,8 +122,7 @@ func TestHealthCheckMultipleShutdowns(t *testing.T) {
Port: testutil.GetAvailablePort(t),
}

hcExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
hcExt := newServer(config, zap.NewNop())
require.NotNil(t, hcExt)

require.NoError(t, hcExt.Start(context.Background(), componenttest.NewNopHost()))
Expand All @@ -139,8 +135,7 @@ func TestHealthCheckShutdownWithoutStart(t *testing.T) {
Port: testutil.GetAvailablePort(t),
}

hcExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
hcExt := newServer(config, zap.NewNop())
require.NotNil(t, hcExt)

require.NoError(t, hcExt.Shutdown(context.Background()))
Expand Down
2 changes: 1 addition & 1 deletion extension/pprofextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (f *Factory) CreateExtension(_ context.Context, params component.ExtensionC
return nil, errors.New("only a single instance can be created per process")
}

return newServer(*config, params.Logger)
return newServer(*config, params.Logger), nil
}

// See comment in CreateExtension how these are used.
Expand Down
8 changes: 3 additions & 5 deletions extension/pprofextension/pprofextension.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type pprofExtension struct {
server http.Server
}

func (p *pprofExtension) Start(ctx context.Context, host component.Host) error {
func (p *pprofExtension) Start(_ context.Context, host component.Host) error {
// Start the listener here so we can have earlier failure if port is
// already in use.
ln, err := net.Listen("tcp", p.config.Endpoint)
Expand Down Expand Up @@ -71,11 +71,9 @@ func (p *pprofExtension) Shutdown(context.Context) error {
return p.server.Close()
}

func newServer(config Config, logger *zap.Logger) (*pprofExtension, error) {
p := &pprofExtension{
func newServer(config Config, logger *zap.Logger) *pprofExtension {
return &pprofExtension{
config: config,
logger: logger,
}

return p, nil
}
15 changes: 5 additions & 10 deletions extension/pprofextension/pprofextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func TestPerformanceProfilerExtensionUsage(t *testing.T) {
MutexProfileFraction: 5,
}

pprofExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
pprofExt := newServer(config, zap.NewNop())
require.NotNil(t, pprofExt)

require.NoError(t, pprofExt.Start(context.Background(), componenttest.NewNopHost()))
Expand Down Expand Up @@ -65,8 +64,7 @@ func TestPerformanceProfilerExtensionPortAlreadyInUse(t *testing.T) {
config := Config{
Endpoint: endpoint,
}
pprofExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
pprofExt := newServer(config, zap.NewNop())
require.NotNil(t, pprofExt)

require.Error(t, pprofExt.Start(context.Background(), componenttest.NewNopHost()))
Expand All @@ -77,8 +75,7 @@ func TestPerformanceProfilerMultipleStarts(t *testing.T) {
Endpoint: testutil.GetAvailableLocalAddress(t),
}

pprofExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
pprofExt := newServer(config, zap.NewNop())
require.NotNil(t, pprofExt)

require.NoError(t, pprofExt.Start(context.Background(), componenttest.NewNopHost()))
Expand All @@ -93,8 +90,7 @@ func TestPerformanceProfilerMultipleShutdowns(t *testing.T) {
Endpoint: testutil.GetAvailableLocalAddress(t),
}

pprofExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
pprofExt := newServer(config, zap.NewNop())
require.NotNil(t, pprofExt)

require.NoError(t, pprofExt.Start(context.Background(), componenttest.NewNopHost()))
Expand All @@ -107,8 +103,7 @@ func TestPerformanceProfilerShutdownWithoutStart(t *testing.T) {
Endpoint: testutil.GetAvailableLocalAddress(t),
}

pprofExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
pprofExt := newServer(config, zap.NewNop())
require.NotNil(t, pprofExt)

require.NoError(t, pprofExt.Shutdown(context.Background()))
Expand Down
4 changes: 2 additions & 2 deletions extension/zpagesextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (f *Factory) CreateDefaultConfig() configmodels.Extension {
}

// CreateExtension creates the extension based on this config.
func (f *Factory) CreateExtension(ctx context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.ServiceExtension, error) {
func (f *Factory) CreateExtension(_ context.Context, params component.ExtensionCreateParams, cfg configmodels.Extension) (component.ServiceExtension, error) {
config := cfg.(*Config)
if config.Endpoint == "" {
return nil, errors.New("\"endpoint\" is required when using the \"zpages\" extension")
Expand All @@ -66,7 +66,7 @@ func (f *Factory) CreateExtension(ctx context.Context, params component.Extensio
return nil, errors.New("only a single instance can be created per process")
}

return newServer(*config, params.Logger)
return newServer(*config, params.Logger), nil
}

// See comment in CreateExtension how these are used.
Expand Down
8 changes: 3 additions & 5 deletions extension/zpagesextension/zpagesextension.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type zpagesExtension struct {
server http.Server
}

func (zpe *zpagesExtension) Start(ctx context.Context, host component.Host) error {
func (zpe *zpagesExtension) Start(_ context.Context, host component.Host) error {
zPagesMux := http.NewServeMux()
zpages.Handle(zPagesMux, "/debug")

Expand Down Expand Up @@ -67,11 +67,9 @@ func (zpe *zpagesExtension) Shutdown(context.Context) error {
return zpe.server.Close()
}

func newServer(config Config, logger *zap.Logger) (*zpagesExtension, error) {
zpe := &zpagesExtension{
func newServer(config Config, logger *zap.Logger) *zpagesExtension {
return &zpagesExtension{
config: config,
logger: logger,
}

return zpe, nil
}
15 changes: 5 additions & 10 deletions extension/zpagesextension/zpagesextension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ func TestZPagesExtensionUsage(t *testing.T) {
Endpoint: testutil.GetAvailableLocalAddress(t),
}

zpagesExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
zpagesExt := newServer(config, zap.NewNop())
require.NotNil(t, zpagesExt)

require.NoError(t, zpagesExt.Start(context.Background(), componenttest.NewNopHost()))
Expand Down Expand Up @@ -63,8 +62,7 @@ func TestZPagesExtensionPortAlreadyInUse(t *testing.T) {
config := Config{
Endpoint: endpoint,
}
zpagesExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
zpagesExt := newServer(config, zap.NewNop())
require.NotNil(t, zpagesExt)

require.Error(t, zpagesExt.Start(context.Background(), componenttest.NewNopHost()))
Expand All @@ -75,8 +73,7 @@ func TestZPagesMultipleStarts(t *testing.T) {
Endpoint: testutil.GetAvailableLocalAddress(t),
}

zpagesExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
zpagesExt := newServer(config, zap.NewNop())
require.NotNil(t, zpagesExt)

require.NoError(t, zpagesExt.Start(context.Background(), componenttest.NewNopHost()))
Expand All @@ -91,8 +88,7 @@ func TestZPagesMultipleShutdowns(t *testing.T) {
Endpoint: testutil.GetAvailableLocalAddress(t),
}

zpagesExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
zpagesExt := newServer(config, zap.NewNop())
require.NotNil(t, zpagesExt)

require.NoError(t, zpagesExt.Start(context.Background(), componenttest.NewNopHost()))
Expand All @@ -105,8 +101,7 @@ func TestZPagesShutdownWithoutStart(t *testing.T) {
Endpoint: testutil.GetAvailableLocalAddress(t),
}

zpagesExt, err := newServer(config, zap.NewNop())
require.NoError(t, err)
zpagesExt := newServer(config, zap.NewNop())
require.NotNil(t, zpagesExt)

require.NoError(t, zpagesExt.Shutdown(context.Background()))
Expand Down

0 comments on commit 8b55cb6

Please sign in to comment.