-
Notifications
You must be signed in to change notification settings - Fork 43
/
client.go
61 lines (52 loc) · 1.37 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package opamp
import (
"context"
"fmt"
"sync"
"time"
"github.com/SigNoz/signoz-otel-collector/signozcol"
"go.opentelemetry.io/collector/otelcol"
"go.uber.org/zap"
)
type Client interface {
Start(ctx context.Context) error
Stop(ctx context.Context) error
Error() <-chan error
}
type baseClient struct {
err chan error
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 {
return c.err
}
// ensureRunning checks if the collector is running
// and sends an error to the error channel if it is not
// running
//
// The error channel is used to signal the main function
// to shutdown the service
//
// The collector may stop running unexpectedly. This can
// 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() {
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 && !c.isReloading {
c.err <- fmt.Errorf("collector stopped unexpectedly")
}
}
}
}