Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-bradley committed Jun 13, 2023
1 parent 61ef95c commit f759c9b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/cmd/opampsupervisor"
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/cmd/otelcontribcol"
schedule:
Expand Down
4 changes: 2 additions & 2 deletions cmd/opampsupervisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ require (
github.com/knadh/koanf v1.5.0
github.com/oklog/ulid/v2 v2.1.0
github.com/open-telemetry/opamp-go v0.6.0
go.uber.org/atomic v1.7.0
go.uber.org/zap v1.17.0
go.uber.org/zap v1.24.0
)

require (
Expand All @@ -20,6 +19,7 @@ require (
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.8.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions cmd/opampsupervisor/go.sum

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

3 changes: 2 additions & 1 deletion cmd/opampsupervisor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
"os"
"os/signal"

"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor/supervisor"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor/supervisor"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions cmd/opampsupervisor/supervisor/commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"fmt"
"os"
"os/exec"
"sync/atomic"
"syscall"
"time"

"go.uber.org/atomic"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor/supervisor/config"
Expand All @@ -50,7 +50,7 @@ func NewCommander(logger *zap.Logger, cfg *config.Agent, args ...string) (*Comma
logger: logger,
cfg: cfg,
args: args,
running: atomic.NewInt64(0),
running: &atomic.Int64{},
}, nil
}

Expand Down Expand Up @@ -103,7 +103,7 @@ func (c *Commander) watch() {
// cmd.Wait returns an exec.ExitError when the Collector exits unsuccessfully or stops
// after receiving a signal. The Commander caller will handle these cases, so we filter
// them out here.
if _, ok := err.(*exec.ExitError); err != nil && !ok {
if ok := errors.Is(err, &exec.ExitError{}); err != nil && !ok {
c.logger.Error("An error occurred while watching the agent process", zap.Error(err))
}

Expand Down
26 changes: 16 additions & 10 deletions cmd/opampsupervisor/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"runtime"
"sort"
"sync/atomic"
"time"

"github.com/cenkalti/backoff/v4"
Expand All @@ -34,7 +35,6 @@ import (
"github.com/open-telemetry/opamp-go/client"
"github.com/open-telemetry/opamp-go/client/types"
"github.com/open-telemetry/opamp-go/protobufs"
"go.uber.org/atomic"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor/supervisor/commander"
Expand Down Expand Up @@ -72,14 +72,14 @@ type Supervisor struct {
// TODO: store this persistently so that when starting we can compose the effective
// config correctly.
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21078
agentConfigOwnMetricsSection atomic.Value
agentConfigOwnMetricsSection *atomic.Value

// agentHealthCheckEndpoint is the endpoint the Collector's health check extension
// will listen on for health check requests from the Supervisor.
agentHealthCheckEndpoint string

// Final effective config of the Collector.
effectiveConfig atomic.Value
effectiveConfig *atomic.Value

// Location of the effective config file.
effectiveConfigFilePath string
Expand All @@ -96,9 +96,11 @@ type Supervisor struct {

func NewSupervisor(logger *zap.Logger, configFile string) (*Supervisor, error) {
s := &Supervisor{
logger: logger,
hasNewConfig: make(chan struct{}, 1),
effectiveConfigFilePath: "effective.yaml",
logger: logger,
hasNewConfig: make(chan struct{}, 1),
effectiveConfigFilePath: "effective.yaml",
agentConfigOwnMetricsSection: &atomic.Value{},
effectiveConfig: &atomic.Value{},
}

if err := s.loadConfig(configFile); err != nil {
Expand All @@ -123,7 +125,7 @@ func NewSupervisor(logger *zap.Logger, configFile string) (*Supervisor, error) {

s.loadAgentEffectiveConfig()

if err := s.startOpAMP(); err != nil {
if err = s.startOpAMP(); err != nil {
return nil, fmt.Errorf("cannot start OpAMP client: %w", err)
}

Expand Down Expand Up @@ -160,6 +162,7 @@ func (s *Supervisor) loadConfig(configFile string) error {
}

// TODO: Implement bootstrapping https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/21071
// nolint: unparam
func (s *Supervisor) getBootstrapInfo() (err error) {
s.agentVersion = "1.0.0"

Expand Down Expand Up @@ -475,7 +478,7 @@ func (s *Supervisor) startAgent() {
err := s.commander.Start(context.Background())
if err != nil {
s.logger.Error("Cannot start the agent", zap.Error(err))
err := s.opampClient.SetHealth(&protobufs.AgentHealth{Healthy: false, LastError: fmt.Sprintf("Cannot start the agent: %v", err)})
err = s.opampClient.SetHealth(&protobufs.AgentHealth{Healthy: false, LastError: fmt.Sprintf("Cannot start the agent: %v", err)})

if err != nil {
s.logger.Error("Failed to report OpAMP client health", zap.Error(err))
Expand Down Expand Up @@ -678,7 +681,10 @@ func (s *Supervisor) onMessage(ctx context.Context, msg *types.MessageData) {
zap.String("old_id", s.instanceID.String()),
zap.String("new_id", newInstanceID.String()))
s.instanceID = newInstanceID
s.opampClient.SetAgentDescription(s.createAgentDescription())
err = s.opampClient.SetAgentDescription(s.createAgentDescription())
if err != nil {
s.logger.Error("Failed to send agent description to OpAMP server")
}

configChanged = true
}
Expand All @@ -699,7 +705,7 @@ func (s *Supervisor) onMessage(ctx context.Context, msg *types.MessageData) {
}

func (s *Supervisor) findRandomPort() (int, error) {
l, err := net.Listen("tcp", ":0")
l, err := net.Listen("tcp", "localhost:0")

if err != nil {
return 0, err
Expand Down
1 change: 1 addition & 0 deletions versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module-sets:
- github.com/open-telemetry/opentelemetry-collector-contrib
- github.com/open-telemetry/opentelemetry-collector-contrib/cmd/configschema
- github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen
- github.com/open-telemetry/opentelemetry-collector-contrib/cmd/opampsupervisor
- github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen
- github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provider/s3provider
- github.com/open-telemetry/opentelemetry-collector-contrib/connector/countconnector
Expand Down

0 comments on commit f759c9b

Please sign in to comment.