Skip to content

Commit ec97a2a

Browse files
kylos101ona-agent
andcommitted
refactor(agent-smith): remove unused filesystem scanning configuration options
- Remove WorkspaceDepth: No longer needed with signature-driven scanning - Remove MaxFilesPerScan: File count naturally limited by signature patterns - Keep MaxFileSize: Still useful to avoid scanning overly large files - Update example configuration to reflect simplified options - Update all tests to remove references to removed fields - Cleaner, more focused configuration for signature-driven approach Co-authored-by: Ona <[email protected]>
1 parent 3c1cd53 commit ec97a2a

File tree

5 files changed

+31
-70
lines changed

5 files changed

+31
-70
lines changed

components/ee/agent-smith/example-config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"enabled": true,
5858
"scanInterval": "5m",
5959
"maxFileSize": 1024,
60-
"workspaceDepth": 3,
61-
"maxFilesPerScan": 200
60+
"workingArea": "/var/gitpod/workspaces"
6261
}
6362
}

components/ee/agent-smith/pkg/agent/agent.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,10 @@ func NewAgentSmith(cfg config.Config) (*Smith, error) {
143143
if cfg.FilesystemScanning != nil && cfg.FilesystemScanning.Enabled {
144144
// Create filesystem detector config
145145
fsConfig := detector.FilesystemScanningConfig{
146-
Enabled: cfg.FilesystemScanning.Enabled,
147-
ScanInterval: cfg.FilesystemScanning.ScanInterval,
148-
MaxFileSize: cfg.FilesystemScanning.MaxFileSize,
149-
WorkspaceDepth: cfg.FilesystemScanning.WorkspaceDepth,
150-
MaxFilesPerScan: cfg.FilesystemScanning.MaxFilesPerScan,
151-
WorkingArea: cfg.FilesystemScanning.WorkingArea,
146+
Enabled: cfg.FilesystemScanning.Enabled,
147+
ScanInterval: cfg.FilesystemScanning.ScanInterval,
148+
MaxFileSize: cfg.FilesystemScanning.MaxFileSize,
149+
WorkingArea: cfg.FilesystemScanning.WorkingArea,
152150
}
153151

154152
filesystemDetec, err = detector.NewFilesystemDetector(fsConfig)

components/ee/agent-smith/pkg/config/config.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,10 @@ type WorkspaceManagerConfig struct {
193193

194194
// FilesystemScanning configures filesystem signature scanning
195195
type FilesystemScanning struct {
196-
Enabled bool `json:"enabled"`
197-
ScanInterval time.Duration `json:"scanInterval"`
198-
MaxFileSize int64 `json:"maxFileSize"`
199-
WorkspaceDepth int `json:"workspaceDepth"`
200-
MaxFilesPerScan int `json:"maxFilesPerScan"`
201-
WorkingArea string `json:"workingArea"`
196+
Enabled bool `json:"enabled"`
197+
ScanInterval time.Duration `json:"scanInterval"`
198+
MaxFileSize int64 `json:"maxFileSize"`
199+
WorkingArea string `json:"workingArea"`
202200
}
203201

204202
// Slackwebhooks holds slack notification configuration for different levels of penalty severity

components/ee/agent-smith/pkg/detector/filesystem.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ type FilesystemDetector struct {
5555

5656
// FilesystemScanningConfig holds configuration for filesystem scanning
5757
type FilesystemScanningConfig struct {
58-
Enabled bool
59-
ScanInterval time.Duration
60-
MaxFileSize int64
61-
WorkspaceDepth int
62-
MaxFilesPerScan int
63-
WorkingArea string
58+
Enabled bool
59+
ScanInterval time.Duration
60+
MaxFileSize int64
61+
WorkingArea string
6462
}
6563

6664
var _ FileDetector = &FilesystemDetector{}
@@ -78,12 +76,6 @@ func NewFilesystemDetector(config FilesystemScanningConfig) (*FilesystemDetector
7876
if config.MaxFileSize == 0 {
7977
config.MaxFileSize = 1024 // 1KB default
8078
}
81-
if config.WorkspaceDepth == 0 {
82-
config.WorkspaceDepth = 3
83-
}
84-
if config.MaxFilesPerScan == 0 {
85-
config.MaxFilesPerScan = 200
86-
}
8779
if config.WorkingArea == "" {
8880
return nil, fmt.Errorf("workingArea must be specified")
8981
}
@@ -260,8 +252,6 @@ type WorkspaceDirectory struct {
260252
}
261253

262254
func (det *FilesystemDetector) scanWorkspaceDirectory(wsDir WorkspaceDirectory, signatures []FilesystemSignature, files chan<- File) {
263-
fileCount := 0
264-
265255
// Create a minimal workspace object for this directory
266256
workspace := &common.Workspace{
267257
InstanceID: wsDir.InstanceID,
@@ -271,23 +261,11 @@ func (det *FilesystemDetector) scanWorkspaceDirectory(wsDir WorkspaceDirectory,
271261

272262
// For each signature, check if any of its target files exist
273263
for _, sig := range signatures {
274-
if fileCount >= det.config.MaxFilesPerScan {
275-
break
276-
}
277-
278264
for _, pattern := range sig.Filenames {
279-
if fileCount >= det.config.MaxFilesPerScan {
280-
break
281-
}
282-
283265
// Find files matching the pattern
284266
matchingFiles := det.findMatchingFiles(wsDir.Path, pattern)
285267

286268
for _, filePath := range matchingFiles {
287-
if fileCount >= det.config.MaxFilesPerScan {
288-
break
289-
}
290-
291269
// Check if file exists and get its info
292270
info, err := os.Stat(filePath)
293271
if err != nil {
@@ -307,7 +285,6 @@ func (det *FilesystemDetector) scanWorkspaceDirectory(wsDir WorkspaceDirectory,
307285

308286
det.filesScannedTotal.Inc()
309287
det.filesFoundTotal.Inc()
310-
fileCount++
311288

312289
file := File{
313290
Path: filePath,

components/ee/agent-smith/pkg/detector/filesystem_test.go

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ func TestFilesystemDetector_Config_Defaults(t *testing.T) {
2626
WorkingArea: "/tmp/test-workspaces",
2727
},
2828
expectedConfig: FilesystemScanningConfig{
29-
Enabled: true,
30-
ScanInterval: 5 * time.Minute,
31-
MaxFileSize: 1024,
32-
WorkspaceDepth: 3,
33-
MaxFilesPerScan: 200,
34-
WorkingArea: "/tmp/test-workspaces",
29+
Enabled: true,
30+
ScanInterval: 5 * time.Minute,
31+
MaxFileSize: 1024,
32+
WorkingArea: "/tmp/test-workspaces",
3533
},
3634
},
3735
{
@@ -43,31 +41,25 @@ func TestFilesystemDetector_Config_Defaults(t *testing.T) {
4341
WorkingArea: "/tmp/test-workspaces",
4442
},
4543
expectedConfig: FilesystemScanningConfig{
46-
Enabled: true,
47-
ScanInterval: 10 * time.Minute,
48-
MaxFileSize: 2048,
49-
WorkspaceDepth: 3,
50-
MaxFilesPerScan: 200,
51-
WorkingArea: "/tmp/test-workspaces",
44+
Enabled: true,
45+
ScanInterval: 10 * time.Minute,
46+
MaxFileSize: 2048,
47+
WorkingArea: "/tmp/test-workspaces",
5248
},
5349
},
5450
{
5551
name: "all custom values",
5652
inputConfig: FilesystemScanningConfig{
57-
Enabled: true,
58-
ScanInterval: 2 * time.Minute,
59-
MaxFileSize: 512,
60-
WorkspaceDepth: 2,
61-
MaxFilesPerScan: 100,
62-
WorkingArea: "/tmp/test-workspaces",
53+
Enabled: true,
54+
ScanInterval: 2 * time.Minute,
55+
MaxFileSize: 512,
56+
WorkingArea: "/tmp/test-workspaces",
6357
},
6458
expectedConfig: FilesystemScanningConfig{
65-
Enabled: true,
66-
ScanInterval: 2 * time.Minute,
67-
MaxFileSize: 512,
68-
WorkspaceDepth: 2,
69-
MaxFilesPerScan: 100,
70-
WorkingArea: "/tmp/test-workspaces",
59+
Enabled: true,
60+
ScanInterval: 2 * time.Minute,
61+
MaxFileSize: 512,
62+
WorkingArea: "/tmp/test-workspaces",
7163
},
7264
},
7365
}
@@ -85,11 +77,8 @@ func TestFilesystemDetector_Config_Defaults(t *testing.T) {
8577
if detector.config.MaxFileSize != tt.expectedConfig.MaxFileSize {
8678
t.Errorf("MaxFileSize = %v, expected %v", detector.config.MaxFileSize, tt.expectedConfig.MaxFileSize)
8779
}
88-
if detector.config.WorkspaceDepth != tt.expectedConfig.WorkspaceDepth {
89-
t.Errorf("WorkspaceDepth = %v, expected %v", detector.config.WorkspaceDepth, tt.expectedConfig.WorkspaceDepth)
90-
}
91-
if detector.config.MaxFilesPerScan != tt.expectedConfig.MaxFilesPerScan {
92-
t.Errorf("MaxFilesPerScan = %v, expected %v", detector.config.MaxFilesPerScan, tt.expectedConfig.MaxFilesPerScan)
80+
if detector.config.WorkingArea != tt.expectedConfig.WorkingArea {
81+
t.Errorf("WorkingArea = %v, expected %v", detector.config.WorkingArea, tt.expectedConfig.WorkingArea)
9382
}
9483
})
9584
}

0 commit comments

Comments
 (0)