Skip to content

Commit

Permalink
fix: opamp client ensureRunning: ignore non-running collector if relo…
Browse files Browse the repository at this point in the history
…ading (#242)
  • Loading branch information
raj-k-singh authored Dec 11, 2023
1 parent 1fe5faa commit 029dd3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions opamp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package opamp
import (
"context"
"fmt"
"sync"
"time"

"github.com/SigNoz/signoz-otel-collector/signozcol"
Expand All @@ -23,10 +24,13 @@ type baseClient struct {
stopped chan bool
coll *signozcol.WrappedCollector
logger *zap.Logger

reloadMux sync.Mutex
isReloading bool
}

// Error returns the error channel
func (c baseClient) Error() <-chan error {
func (c *baseClient) Error() <-chan error {
return c.err
}

Expand All @@ -41,15 +45,15 @@ func (c baseClient) Error() <-chan error {
// happen if a component reports a fatal error or some other
// async error occurs
// See https://github.com/open-telemetry/opentelemetry-collector/blob/8d425480b0dd1270b408582d9e21dd644299cd7e/service/host.go#L34-L39
func (c baseClient) ensureRunning() {
func (c *baseClient) ensureRunning() {
c.logger.Info("Ensuring collector is running")
for {
select {
case <-c.stopped:
c.logger.Info("Collector is stopped")
return
case <-time.After(c.coll.PollInterval):
if c.coll.GetState() == otelcol.StateClosed {
if c.coll.GetState() == otelcol.StateClosed && !c.isReloading {
c.err <- fmt.Errorf("collector stopped unexpectedly")
}
}
Expand Down
7 changes: 7 additions & 0 deletions opamp/server_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ func (s *serverClient) onRemoteConfigHandler(ctx context.Context, remoteConfig *

// reload is the callback function that is called when the agent configuration file changes
func (s *serverClient) reload(contents []byte) error {
s.reloadMux.Lock()
s.isReloading = true
defer func() {
s.isReloading = false
s.reloadMux.Unlock()
}()

collectorConfigPath := s.configManager.agentConfig.path
rollbackPath := fmt.Sprintf("%s.rollback", collectorConfigPath)

Expand Down

0 comments on commit 029dd3b

Please sign in to comment.