Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: remove unused variables #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions checks/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ var (

// ConnectionsCheck collects statistics about live TCP and UDP connections.
type ConnectionsCheck struct {
// Local network tracer
useLocalTracer bool
localTracer *tracer.Tracer
localTracerErr error

Expand Down Expand Up @@ -74,7 +72,7 @@ func (c *ConnectionsCheck) Endpoint() string { return "/api/v1/connections" }
// See agent.proto for the schema of the message and models.
func (c *ConnectionsCheck) Run(cfg *config.AgentConfig, groupID int32, currentTime time.Time) (*CheckResult, error) {
// If local tracer failed to initialize, so we shouldn't be doing any checks
if c.useLocalTracer && c.localTracer == nil {
if c.localTracer == nil {
return nil, fmt.Errorf("cannot run connections check when tracer is not initialized. Set STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting")
}

Expand Down Expand Up @@ -209,30 +207,26 @@ func (c *ConnectionsCheck) Run(cfg *config.AgentConfig, groupID int32, currentTi
}

func (c *ConnectionsCheck) getConnections() (*network.Connections, error) {
if c.useLocalTracer { // If local tracer is set up, use that
if c.localTracer == nil {
return nil, fmt.Errorf("using local network tracer, but no tracer was initialized")
}
// we always use the same client-ID to get connections from the tracer
cs, err := c.localTracer.GetActiveConnections("process-agent")
if c.localTracer == nil {
return nil, fmt.Errorf("the tracer was not initialized")
}
// we always use the same client-ID to get connections from the tracer
cs, err := c.localTracer.GetActiveConnections("process-agent")

if len(c.initialConnections) == 0 {
c.initialConnections = map[connKey]interface{}{}
for _, conn := range cs.Conns {
c.initialConnections[getConnectionKey(conn)] = nil
}
} else {
for _, conn := range cs.Conns {
if _, ok := c.initialConnections[getConnectionKey(conn)]; (!ok) && conn.InitialTCPSeq.Seq == 0 && conn.InitialTCPSeq.Ack_seq == 0 && conn.Direction != network.NONE {
log.Debugf("Got new connection without initial handshake: %v", conn)
}
c.initialConnections[getConnectionKey(conn)] = nil
if len(c.initialConnections) == 0 {
c.initialConnections = map[connKey]interface{}{}
for _, conn := range cs.Conns {
c.initialConnections[getConnectionKey(conn)] = nil
}
} else {
for _, conn := range cs.Conns {
if _, ok := c.initialConnections[getConnectionKey(conn)]; (!ok) && conn.InitialTCPSeq.Seq == 0 && conn.InitialTCPSeq.Ack_seq == 0 && conn.Direction != network.NONE {
log.Debugf("Got new connection without initial handshake: %v", conn)
}
c.initialConnections[getConnectionKey(conn)] = nil
}
return cs, err
}

return nil, fmt.Errorf("remote ConnectionTracker is not supported")
return cs, err
}

var logShortLivingNoticeOnce = &sync.Once{}
Expand Down
2 changes: 0 additions & 2 deletions checks/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, _ *model.SystemInfo) error {

log.Info("starting network tracer locally")
// todo!: remove this is not needed. We always have a local tracer and we put this variable always to `true`!
c.useLocalTracer = true

// Checking whether the current kernel version is supported by the tracer
if isSupported, reason := tracer.IsTracerSupportedByOS(nil); !isSupported {
Expand Down
1 change: 0 additions & 1 deletion config/yaml_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
// available in Agent versions >= 6
type YamlAgentConfig struct {
APIKey string `yaml:"api_key"`
Site string `yaml:"site"` // todo!: this is not used (?)
StsURL string `yaml:"sts_url"`
SkipKubeletTLSVerify bool `yaml:"skip_kubelet_tls_verify"`
SkipSSLValidation bool `yaml:"skip_ssl_validation"`
Expand Down