Skip to content

Commit

Permalink
do not print full http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
orishavit committed Sep 12, 2024
1 parent efff59c commit cdaafb9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/node-agent/cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"github.com/otterize/network-mapper/src/node-agent/pkg/container"
"github.com/otterize/network-mapper/src/node-agent/pkg/reconcilers"
"github.com/otterize/network-mapper/src/node-agent/pkg/service"
"github.com/sirupsen/logrus"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -16,7 +17,7 @@ func main() {
criClient := service.CreateCRIClientOrDie()
containerManager := container.NewContainerManager(criClient)

service.RegisterReconcilersOrDie(
reconcilers.RegisterReconcilersOrDie(
mgr,
client,
containerManager,
Expand Down
13 changes: 7 additions & 6 deletions src/node-agent/pkg/ebpf/eventreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/otterize/intents-operator/src/shared/errors"
otrzebpf "github.com/otterize/network-mapper/src/ebpf"
"github.com/otterize/network-mapper/src/node-agent/pkg/container"
"github.com/otterize/network-mapper/src/node-agent/pkg/service"
"github.com/sirupsen/logrus"
"io"
"net/http"
Expand Down Expand Up @@ -94,10 +95,6 @@ func (e *EventReader) parseEvent(raw []byte) (otrzebpf.BpfSslEventT, []byte, err
}

func (e *EventReader) handleEvent(event otrzebpf.BpfSslEventT, data []byte) error {
// TODO: delete
fmt.Printf("\nevent: %d | %d | %d \n", event.Meta.Timestamp, event.Meta.TotalSize, event.Meta.DataSize)
fmt.Printf("raw data: %s\n", string(data))

// Try to parse the event as an HTTP message
errReq := e.handleHttpRequest(event, data)
if errReq == nil {
Expand Down Expand Up @@ -130,7 +127,9 @@ func (e *EventReader) handleHttpRequest(event otrzebpf.BpfSslEventT, data []byte
return errors.Wrap(err)
}

logrus.Debugf("Got HTTP request: %s\n", string(body))
if service.PrintHttpRequests() {
logrus.Debugf("Got HTTP request: %s\n", string(body))
}

// Handle outgoing HTTP requests
if Direction(event.Meta.Direction) == DirectionEgress {
Expand Down Expand Up @@ -158,7 +157,9 @@ func (e *EventReader) handleHttpResponse(event otrzebpf.BpfSslEventT, data []byt
return errors.Wrap(err)
}

logrus.Debugf("Got HTTP response: %s\n", string(body))
if service.PrintHttpRequests() {
logrus.Debugf("Got HTTP response: %s\n", string(body))
}

return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package service
package reconcilers

import (
"github.com/otterize/network-mapper/src/node-agent/pkg/container"
"github.com/otterize/network-mapper/src/node-agent/pkg/reconcilers"
"github.com/sirupsen/logrus"
"reflect"
crtClient "sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -14,7 +13,7 @@ func RegisterReconcilersOrDie(
client crtClient.Client,
containerManager *container.ContainerManager,
) {
ebpfReconciler, err := reconcilers.NewEBPFReconciler(
ebpfReconciler, err := NewEBPFReconciler(
client,
containerManager,
)
Expand All @@ -23,7 +22,7 @@ func RegisterReconcilersOrDie(
logrus.WithError(err).Panic("unable to create EBPF reconciler")
}

reconcilersToRegister := []reconcilers.Reconciler{
reconcilersToRegister := []Reconciler{
ebpfReconciler,
}

Expand Down
11 changes: 9 additions & 2 deletions src/node-agent/pkg/service/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
)

var (
podName string
podNamespace string
podName string
podNamespace string
printHttpRequests = false
)

func init() {
Expand All @@ -22,6 +23,8 @@ func init() {
if podNamespace == "" {
logrus.Panic("POD_NAMESPACE environment variable must be set")
}

printHttpRequests = os.Getenv("OTTERIZE_PRINT_HTTP_REQUESTS") == "true"
}

func PodName() string {
Expand All @@ -31,3 +34,7 @@ func PodName() string {
func PodNamespace() string {
return podNamespace
}

func PrintHttpRequests() bool {
return printHttpRequests
}

0 comments on commit cdaafb9

Please sign in to comment.