-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wire up the components with main (#59)
- Loading branch information
1 parent
e251846
commit 24cf1da
Showing
16 changed files
with
402 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
server_endpoint: ws://127.0.0.1:4320/v1/opamp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package featuregate | ||
|
||
import ( | ||
"strings" | ||
|
||
flag "github.com/spf13/pflag" | ||
"go.opentelemetry.io/collector/featuregate" | ||
|
||
"go.uber.org/multierr" | ||
) | ||
|
||
// NewFlag returns a flag.Value that directly applies feature gate statuses to a Registry. | ||
func NewFlag(reg *featuregate.Registry) flag.Value { | ||
return &flagValue{reg: reg} | ||
} | ||
|
||
// flagValue implements the flag.Value interface and directly applies feature gate statuses to a Registry. | ||
type flagValue struct { | ||
reg *featuregate.Registry | ||
} | ||
|
||
func (f *flagValue) String() string { | ||
var ids []string | ||
f.reg.VisitAll(func(g *featuregate.Gate) { | ||
id := g.ID() | ||
if !g.IsEnabled() { | ||
id = "-" + id | ||
} | ||
ids = append(ids, id) | ||
}) | ||
return strings.Join(ids, ",") | ||
} | ||
|
||
func (f *flagValue) Set(s string) error { | ||
if s == "" { | ||
return nil | ||
} | ||
|
||
var errs error | ||
ids := strings.Split(s, ",") | ||
for i := range ids { | ||
id := ids[i] | ||
val := true | ||
switch id[0] { | ||
case '-': | ||
id = id[1:] | ||
val = false | ||
case '+': | ||
id = id[1:] | ||
} | ||
errs = multierr.Append(errs, f.reg.Set(id, val)) | ||
} | ||
return errs | ||
} | ||
|
||
func (f *flagValue) Type() string { | ||
return "featuregate" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,57 @@ | ||
package opamp | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"fmt" | ||
"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() error | ||
Error() <-chan error | ||
} | ||
|
||
type baseClient struct { | ||
err chan error | ||
stopped chan bool | ||
coll *signozcol.WrappedCollector | ||
logger *zap.Logger | ||
} | ||
|
||
// 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.err <- fmt.Errorf("collector stopped unexpectedly") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.