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

apply tshark ip filter and compression options to the tshark insatnce #452

Merged
merged 2 commits into from
Jun 21, 2024
Merged
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
11 changes: 3 additions & 8 deletions e2e/tshark/tshark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func TestTshark(t *testing.T) {
require.NoError(t, err, "error getting S3 (minio) configs")

var (
filename = target.K8sName() + instance.TsharkCaptureFileExtension
filename = target.K8sName() + instance.TsharkCaptureFileExtension + ".tar.gz" // compressed file extension
keyPrefix = "tshark/" + scope
fileKey = filepath.Join(keyPrefix, filename)
)

err = target.EnableTsharkCollector(
instance.TsharkCollectorConfig{
VolumeSize: "10Gi",
VolumeSize: "4Gi",
S3AccessKey: minioConf.AccessKeyID,
S3SecretKey: minioConf.SecretAccessKey,
S3Region: s3Location,
Expand All @@ -72,19 +72,14 @@ func TestTshark(t *testing.T) {
S3KeyPrefix: keyPrefix,
S3Endpoint: minioConf.Endpoint,
UploadInterval: 1 * time.Second, // for sake of the test we keep this short
CompressFiles: true,
},
)
require.NoError(t, err, "error enabling tshark collector")

err = target.Commit()
require.NoError(t, err, "error committing instance")

t.Cleanup(func() {
if err := kn.CleanUp(ctx); err != nil {
t.Logf("error cleaning up knuu: %v", err)
}
})

// Test logic

t.Log("starting target instance")
Expand Down
8 changes: 8 additions & 0 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ type TsharkCollectorConfig struct {

// UploadInterval is the interval at which the tshark collector will upload the pcap file to the s3 server
UploadInterval time.Duration

// IpFilter is the ip filter to use for the tshark collector
// it trace the incoming/outgoing traffic from/to the specific ip
// If not set, it will trace all the traffic
IpFilter string

// CompressFiles is the flag to compress the pcap files before pushing them to s3
CompressFiles bool
}

// SecurityContext represents the security settings for a container
Expand Down
6 changes: 5 additions & 1 deletion pkg/instance/tshark.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

const (
tsharkCollectorName = "tshark-collector"
tsharkCollectorImage = "ghcr.io/celestiaorg/tshark-s3:pr-11"
tsharkCollectorImage = "ghcr.io/celestiaorg/tshark-s3:pr-17"
tsharkCollectorCPU = "100m"
tsharkCollectorMemory = "250Mi"
tsharkCollectorVolumePath = "/tshark"
Expand All @@ -23,6 +23,8 @@ const (
envStorageEndpoint = "STORAGE_ENDPOINT"
envCaptureFileName = "CAPTURE_FILE_NAME"
envUploadInterval = "UPLOAD_INTERVAL"
envCompressFiles = "COMPRESS_FILES"
envIpFilter = "IP_FILTER"
)

func (i *Instance) createTsharkCollectorInstance(ctx context.Context) (*Instance, error) {
Expand Down Expand Up @@ -60,6 +62,8 @@ func (i *Instance) createTsharkCollectorInstance(ctx context.Context) (*Instance
envStorageEndpoint: i.tsharkCollectorConfig.S3Endpoint,
envUploadInterval: fmt.Sprintf("%d", int64(i.tsharkCollectorConfig.UploadInterval.Seconds())),
envCreateBucket: fmt.Sprintf("%t", i.tsharkCollectorConfig.CreateBucket),
envCompressFiles: fmt.Sprintf("%t", i.tsharkCollectorConfig.CompressFiles),
envIpFilter: i.tsharkCollectorConfig.IpFilter,
}

for key, value := range envVars {
Expand Down
Loading