Skip to content

Commit

Permalink
run fix-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
leoparente committed Dec 18, 2024
1 parent e97f0ed commit 4ecfd05
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 33 deletions.
16 changes: 8 additions & 8 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"github.com/netboxlabs/orb-agent/agent/version"
)

var (
ErrMqttConnection = errors.New("failed to connect to a broker")
)
var ErrMqttConnection = errors.New("failed to connect to a broker")

type Agent interface {
Start(ctx context.Context, cancelFunc context.CancelFunc) error
Expand Down Expand Up @@ -69,10 +67,12 @@ type orbAgent struct {
configManager config.ConfigManager
}

const retryRequestDuration = time.Second
const retryRequestFixedTime = 15
const retryDurationIncrPerAttempts = 10
const retryMaxAttempts = 4
const (
retryRequestDuration = time.Second
retryRequestFixedTime = 15
retryDurationIncrPerAttempts = 10
retryMaxAttempts = 4
)

type GroupInfo struct {
Name string
Expand All @@ -97,7 +97,6 @@ func New(logger *zap.Logger, c config.Config) (Agent, error) {
}

func (a *orbAgent) managePolicies() error {

if a.config.OrbAgent.Policies == nil {
return errors.New("no policies specified")
}
Expand Down Expand Up @@ -222,6 +221,7 @@ func (a *orbAgent) logoffWithHeartbeat(ctx context.Context) {
}
}
}

func (a *orbAgent) Stop(ctx context.Context) {
a.logger.Info("routine call for stop agent", zap.Any("routine", ctx.Value("routine")))
if a.rpcFromCancelFunc != nil {
Expand Down
1 change: 0 additions & 1 deletion agent/agent_prof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
)

func Test_orbAgent_startBackends(t *testing.T) {

type args struct {
agentCtx context.Context
}
Expand Down
4 changes: 2 additions & 2 deletions agent/backend/devicediscovery/device_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (d *deviceDiscoveryBackend) SetCommsClient(agentID string, client *mqtt.Cli
d.mqttClient = client
otelBaseTopic := strings.Replace(baseTopic, "?", "otlp", 1)
d.otlpMetricsTopic = fmt.Sprintf("%s/m/%c", otelBaseTopic, agentID[0])

}

func (d *deviceDiscoveryBackend) Version() (string, error) {
var info Info
err := d.request("status", &info, http.MethodGet, http.NoBody, "application/json", VersionTimeout)
Expand All @@ -103,6 +103,7 @@ func (d *deviceDiscoveryBackend) Version() (string, error) {
}
return info.Version, nil
}

func (d *deviceDiscoveryBackend) Start(ctx context.Context, cancelFunc context.CancelFunc) error {
d.startTime = time.Now()
d.cancelFunc = cancelFunc
Expand Down Expand Up @@ -192,7 +193,6 @@ func (d *deviceDiscoveryBackend) Start(ctx context.Context, cancelFunc context.C
}

return nil

}

func (d *deviceDiscoveryBackend) Stop(ctx context.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions agent/backend/networkdiscovery/network_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (d *networkDiscoveryBackend) SetCommsClient(agentID string, client *mqtt.Cl
d.mqttClient = client
otelBaseTopic := strings.Replace(baseTopic, "?", "otlp", 1)
d.otlpMetricsTopic = fmt.Sprintf("%s/m/%c", otelBaseTopic, agentID[0])

}

func (d *networkDiscoveryBackend) Version() (string, error) {
var info Info
err := d.request("status", &info, http.MethodGet, http.NoBody, "application/json", VersionTimeout)
Expand All @@ -103,6 +103,7 @@ func (d *networkDiscoveryBackend) Version() (string, error) {
}
return info.Version, nil
}

func (d *networkDiscoveryBackend) Start(ctx context.Context, cancelFunc context.CancelFunc) error {
d.startTime = time.Now()
d.cancelFunc = cancelFunc
Expand Down Expand Up @@ -192,7 +193,6 @@ func (d *networkDiscoveryBackend) Start(ctx context.Context, cancelFunc context.
}

return nil

}

func (d *networkDiscoveryBackend) Stop(ctx context.Context) error {
Expand Down
1 change: 0 additions & 1 deletion agent/backend/otel/exporter_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ service:
if _, ok := expectedStruct.Processors["transform/policy_data"]; !ok {
t.Error("missing required attributes/policy_data processor", err)
}

})
}
}
14 changes: 8 additions & 6 deletions agent/backend/otel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ import (

var _ backend.Backend = (*openTelemetryBackend)(nil)

const DefaultPath = "otelcol-contrib"
const DefaultHost = "localhost"
const DefaultPort = 4317
const (
DefaultPath = "otelcol-contrib"
DefaultHost = "localhost"
DefaultPort = 4317
)

type openTelemetryBackend struct {
logger *zap.Logger
startTime time.Time

//policies
// policies
policyRepo policies.PolicyRepo
policyConfigDirectory string
agentTags map[string]string
Expand Down Expand Up @@ -64,7 +66,8 @@ type openTelemetryBackend struct {

// Configure initializes the backend with the given configuration
func (o *openTelemetryBackend) Configure(logger *zap.Logger, repo policies.PolicyRepo,
config map[string]interface{}, common config.BackendCommons) error {
config map[string]interface{}, common config.BackendCommons,
) error {
o.logger = logger
o.logger.Info("configuring OpenTelemetry backend")
o.policyRepo = repo
Expand Down Expand Up @@ -135,7 +138,6 @@ func (o *openTelemetryBackend) Version() (string, error) {
o.logger.Info("running opentelemetry-contrib version", zap.String("version", versionOutput))

return versionOutput, nil

}

func (o *openTelemetryBackend) Start(ctx context.Context, cancelFunc context.CancelFunc) (err error) {
Expand Down
3 changes: 2 additions & 1 deletion agent/backend/otel/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"os"

"github.com/go-cmd/cmd"
"github.com/netboxlabs/orb-agent/agent/policies"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"

"github.com/netboxlabs/orb-agent/agent/policies"
)

const tempFileNamePattern = "otel-%s-config.yml"
Expand Down
2 changes: 0 additions & 2 deletions agent/backend/pktvisor/pktvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func (p *pktvisorBackend) Version() (string, error) {
}

func (p *pktvisorBackend) Start(ctx context.Context, cancelFunc context.CancelFunc) error {

// this should record the start time whether it's successful or not
// because it is used by the automatic restart system for last attempt
p.startTime = time.Now()
Expand Down Expand Up @@ -319,7 +318,6 @@ func (p *pktvisorBackend) GetCapabilities() (map[string]interface{}, error) {
}

func (p *pktvisorBackend) FullReset(ctx context.Context) error {

// force a stop, which stops scrape as well. if proc is dead, it no ops.
if state, _, _ := p.getProcRunningStatus(); state == backend.Running {
if err := p.Stop(ctx); err != nil {
Expand Down
1 change: 0 additions & 1 deletion agent/backend/pktvisor/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func (p *pktvisorBackend) ApplyPolicy(data policies.PolicyData, updatePolicy bool) error {

if updatePolicy {
// To update a policy it's necessary first remove it and then apply a new version
if err := p.RemovePolicy(data); err != nil {
Expand Down
1 change: 0 additions & 1 deletion agent/heartbeats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const HeartbeatFreq = 50 * time.Second
const RestartTimeMin = 5 * time.Minute

func (a *orbAgent) sendSingleHeartbeat(ctx context.Context, t time.Time, agentsState fleet.State) {

if a.heartbeatsTopic == "" {
a.logger.Debug("heartbeat topic not yet set, skipping")
return
Expand Down
17 changes: 13 additions & 4 deletions agent/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,41 @@ type agentLoggerError struct {
a *orbAgent
}

var _ mqtt.Logger = (*agentLoggerDebug)(nil)
var _ mqtt.Logger = (*agentLoggerWarn)(nil)
var _ mqtt.Logger = (*agentLoggerCritical)(nil)
var _ mqtt.Logger = (*agentLoggerError)(nil)
var (
_ mqtt.Logger = (*agentLoggerDebug)(nil)
_ mqtt.Logger = (*agentLoggerWarn)(nil)
_ mqtt.Logger = (*agentLoggerCritical)(nil)
_ mqtt.Logger = (*agentLoggerError)(nil)
)

func (a *agentLoggerWarn) Println(v ...interface{}) {
a.a.logger.Warn("WARN mqtt log", zap.Any("payload", v))
}

func (a *agentLoggerWarn) Printf(format string, v ...interface{}) {
a.a.logger.Warn("WARN mqtt log", zap.Any("payload", v))
}

func (a *agentLoggerDebug) Println(v ...interface{}) {
a.a.logger.Debug("DEBUG mqtt log", zap.Any("payload", v))
}

func (a *agentLoggerDebug) Printf(format string, v ...interface{}) {
a.a.logger.Debug("DEBUG mqtt log", zap.Any("payload", v))
}

func (a *agentLoggerCritical) Println(v ...interface{}) {
a.a.logger.Error("CRITICAL mqtt log", zap.Any("payload", v))
}

func (a *agentLoggerCritical) Printf(format string, v ...interface{}) {
a.a.logger.Error("CRITICAL mqtt log", zap.Any("payload", v))
}

func (a *agentLoggerError) Println(v ...interface{}) {
a.a.logger.Error("ERROR mqtt log", zap.Any("payload", v))
}

func (a *agentLoggerError) Printf(format string, v ...interface{}) {
a.a.logger.Error("ERROR mqtt log", zap.Any("payload", v))
}
2 changes: 1 addition & 1 deletion cmd/e2e_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Test_main(t *testing.T) {

go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
select {
case <-sigs:
logger.Warn("stop signal received stopping agent")
Expand Down
3 changes: 0 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func Version(_ *cobra.Command, _ []string) {
}

func Run(_ *cobra.Command, _ []string) {

initConfig()

// configuration
Expand Down Expand Up @@ -120,7 +119,6 @@ func Run(_ *cobra.Command, _ []string) {
}

func mergeOrError(path string) {

v := viper.New()
if len(path) > 0 {
v.SetConfigFile(path)
Expand Down Expand Up @@ -186,7 +184,6 @@ func initConfig() {
}

func main() {

rootCmd := &cobra.Command{
Use: "orb-agent",
}
Expand Down

0 comments on commit 4ecfd05

Please sign in to comment.