Skip to content

Commit

Permalink
fixed lint and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kumari-anupam committed Mar 6, 2024
1 parent c2a4b26 commit 941c87f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@938f6e2f7550e542bd78f3b9e8812665db109e02 # @v1.1.0
make bin/protoc bin/goreleaser
bash ./dev/run-kind-registry.sh
make ebpf generate
make generate
./bin/goreleaser release --snapshot --rm-dist
make push-local-images
cp dist/tarianctl_linux_amd64/tarianctl ./bin/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@938f6e2f7550e542bd78f3b9e8812665db109e02 # @v1.1.0
make bin/protoc bin/goreleaser
bash ./dev/run-kind-registry.sh
make ebpf generate
make generate
./bin/goreleaser release --snapshot --rm-dist
make push-local-images
cp dist/tarianctl_linux_amd64/tarianctl ./bin/
Expand Down
1 change: 1 addition & 0 deletions cmd/tarian-node-agent/cmd/mount_debugfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// https://man7.org/linux/man-pages/man2/statfs.2.html
const DebugFSMagic = 0x64626720

// DebugFSRoot is the location of the DebugFS filesystem
const DebugFSRoot = "/sys/kernel/debug"

func isDebugFsMounted() bool {
Expand Down
12 changes: 6 additions & 6 deletions pkg/nodeagent/capture_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

"github.com/aquasecurity/libbpfgo"
"github.com/intelops/tarian-detector/pkg/detector"
"github.com/intelops/tarian-detector/tarian"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -52,9 +51,6 @@ type CaptureExec struct {
ctx context.Context
eventsChan chan ExecEvent // Channel for sending captured execution events
shouldClose bool // Flag indicating whether the capture should be closed
bpfModule *libbpfgo.Module
bpfProg *libbpfgo.BPFProg
bpfRingBuffer *libbpfgo.RingBuffer
nodeName string // The name of the node where the capture is running
logger *logrus.Logger // Logger instance for logging
eventsDetectorChan chan map[string]any
Expand Down Expand Up @@ -106,7 +102,7 @@ func (c *CaptureExec) Start() error {
}
watcher.Start()

err = c.GetTarianDetectorEbpfEvents()
err = c.getTarianDetectorEbpfEvents()
if err != nil {
return fmt.Errorf("CaptureExec.Start: failed to get tarian detector events: %w", err)
}
Expand Down Expand Up @@ -172,7 +168,11 @@ func (c *CaptureExec) GetEventsChannel() chan ExecEvent {
return c.eventsChan
}

func (c *CaptureExec) GetTarianDetectorEbpfEvents() error {
// getTarianDetectorEbpfEvents retrieves Tarian detector EBPF events.
//
// No parameters.
// Returns an error.
func (c *CaptureExec) getTarianDetectorEbpfEvents() error {
tarianEbpfModule, err := tarian.GetModule()
if err != nil {
fmt.Println("error while get tarian ebpf module: ", err)
Expand Down
12 changes: 8 additions & 4 deletions pkg/nodeagent/nodeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func NewNodeAgent(logger *logrus.Logger, clusterAgentAddress string) (*NodeAgent

eventsDetector, err := integrateTarianDetector(logger)
if err != nil {
fmt.Errorf("error while integrate tarian detector: %v", err)
logger.Errorf("error while integrate tarian detector: %v", err)
cancel()
return nil, fmt.Errorf("error while integrate tarian-detector: %w", err)
}

Expand Down Expand Up @@ -427,13 +428,13 @@ func (n *NodeAgent) RegisterViolationsAsNewConstraint(violation *ProcessViolatio
func integrateTarianDetector(logger *logrus.Logger) (*detector.EventsDetector, error) {
tarianEbpfModule, err := tarian.GetModule()
if err != nil {
logger.Error("error while get tarian ebpf module: %v", err)
logger.Errorf("error while get tarian ebpf module: %v", err)
return nil, fmt.Errorf("error while get tarian-detector ebpf module: %w", err)
}

tarianDetector, err := tarianEbpfModule.Prepare()
if err != nil {
logger.Error("error while prepare tarian detector: %v", err)
logger.Errorf("error while prepare tarian detector: %v", err)
return nil, fmt.Errorf("error while prepare tarian-detector: %w", err)
}

Expand Down Expand Up @@ -464,7 +465,7 @@ func (n *NodeAgent) loopTarianDetectorReadEvents(ctx context.Context) error {
for {
event, err := n.eventsDetector.ReadAsInterface()
if err != nil {
n.logger.Errorf("tarian-detector: error while read event: %w", err)
n.logger.Errorf("tarian-detector: error while read event: %v", err)
continue
}

Expand All @@ -488,6 +489,9 @@ func (n *NodeAgent) loopTarianDetectorReadEvents(ctx context.Context) error {
return ctx.Err()
}

// SendDetectionEventToClusterAgent sends a detection event to the cluster agent.
//
// It takes two parameters: detectionDataType of type string, and detectionData of type string.
func (n *NodeAgent) SendDetectionEventToClusterAgent(detectionDataType, detectionData string) {
req := tarianpb.IngestEventRequest{
Event: &tarianpb.Event{
Expand Down
4 changes: 4 additions & 0 deletions pkg/server/ingestion_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (iw *IngestionWorker) Start() {
}

buf, err := json.Marshal(event)
if err != nil {
iw.logger.WithError(err).Error("marshaling error: error while processing event")
continue
}

event.ServerTimestamp = timestamppb.Now()
logrus.Info(">> DEBUG IngestionWorker", "event", string(buf))
Expand Down

0 comments on commit 941c87f

Please sign in to comment.