@@ -16,7 +16,6 @@ import (
1616 "github.com/gitpod-io/gitpod/agent-smith/pkg/classifier"
1717 "github.com/gitpod-io/gitpod/agent-smith/pkg/common"
1818 "github.com/gitpod-io/gitpod/common-go/log"
19- "github.com/prometheus/client_golang/prometheus"
2019)
2120
2221// FileDetector discovers suspicious files on the node
@@ -39,21 +38,15 @@ type fileDetector struct {
3938 mu sync.RWMutex
4039 fs chan File
4140
42- config FilesystemScanningConfig
41+ config FileScanningConfig
4342 classifier classifier.FileClassifier
4443 lastScanTime time.Time
4544
46- // Metrics
47- filesScannedTotal prometheus.Counter
48- filesFoundTotal prometheus.Counter
49- scanDurationSeconds prometheus.Histogram
50- droppedFilesTotal prometheus.Counter
51-
5245 startOnce sync.Once
5346}
5447
55- // FilesystemScanningConfig holds configuration for filesystem scanning
56- type FilesystemScanningConfig struct {
48+ // FileScanningConfig holds configuration for file scanning
49+ type FileScanningConfig struct {
5750 Enabled bool
5851 ScanInterval time.Duration
5952 MaxFileSize int64
@@ -62,10 +55,10 @@ type FilesystemScanningConfig struct {
6255
6356var _ FileDetector = & fileDetector {}
6457
65- // NewfileDetector creates a new filesystem detector
66- func NewfileDetector (config FilesystemScanningConfig , fsClassifier classifier.FileClassifier ) (* fileDetector , error ) {
58+ // NewfileDetector creates a new file detector
59+ func NewfileDetector (config FileScanningConfig , fsClassifier classifier.FileClassifier ) (* fileDetector , error ) {
6760 if ! config .Enabled {
68- return nil , fmt .Errorf ("filesystem scanning is disabled" )
61+ return nil , fmt .Errorf ("file scanning is disabled" )
6962 }
7063
7164 // Set defaults
@@ -83,47 +76,9 @@ func NewfileDetector(config FilesystemScanningConfig, fsClassifier classifier.Fi
8376 config : config ,
8477 classifier : fsClassifier ,
8578 lastScanTime : time.Time {}, // Zero time means never scanned
86- filesScannedTotal : prometheus .NewCounter (prometheus.CounterOpts {
87- Namespace : "gitpod" ,
88- Subsystem : "agent_smith_filesystem_detector" ,
89- Name : "files_scanned_total" ,
90- Help : "total number of files scanned for signatures" ,
91- }),
92- filesFoundTotal : prometheus .NewCounter (prometheus.CounterOpts {
93- Namespace : "gitpod" ,
94- Subsystem : "agent_smith_filesystem_detector" ,
95- Name : "files_found_total" ,
96- Help : "total number of files found for signature matching" ,
97- }),
98- scanDurationSeconds : prometheus .NewHistogram (prometheus.HistogramOpts {
99- Namespace : "gitpod" ,
100- Subsystem : "agent_smith_filesystem_detector" ,
101- Name : "scan_duration_seconds" ,
102- Help : "time taken to scan workspace filesystems" ,
103- }),
104- droppedFilesTotal : prometheus .NewCounter (prometheus.CounterOpts {
105- Namespace : "gitpod" ,
106- Subsystem : "agent_smith_filesystem_detector" ,
107- Name : "dropped_files_total" ,
108- Help : "total number of files dropped due to backpressure" ,
109- }),
11079 }, nil
11180}
11281
113- func (det * fileDetector ) Describe (d chan <- * prometheus.Desc ) {
114- det .filesScannedTotal .Describe (d )
115- det .filesFoundTotal .Describe (d )
116- det .scanDurationSeconds .Describe (d )
117- det .droppedFilesTotal .Describe (d )
118- }
119-
120- func (det * fileDetector ) Collect (m chan <- prometheus.Metric ) {
121- det .filesScannedTotal .Collect (m )
122- det .filesFoundTotal .Collect (m )
123- det .scanDurationSeconds .Collect (m )
124- det .droppedFilesTotal .Collect (m )
125- }
126-
12782func (det * fileDetector ) start (ctx context.Context ) {
12883 fs := make (chan File , 100 )
12984 go func () {
@@ -159,11 +114,6 @@ func (det *fileDetector) start(ctx context.Context) {
159114}
160115
161116func (det * fileDetector ) scanWorkspaces (files chan <- File ) {
162- start := time .Now ()
163- defer func () {
164- det .scanDurationSeconds .Observe (time .Since (start ).Seconds ())
165- }()
166-
167117 // Get filesystem signatures to know what files to look for
168118 filesystemSignatures := det .GetFileSignatures ()
169119 if len (filesystemSignatures ) == 0 {
@@ -263,9 +213,6 @@ func (det *fileDetector) scanWorkspaceDirectory(wsDir WorkspaceDirectory, signat
263213 continue
264214 }
265215
266- det .filesScannedTotal .Inc ()
267- det .filesFoundTotal .Inc ()
268-
269216 file := File {
270217 Path : filePath ,
271218 Workspace : workspace ,
@@ -280,7 +227,6 @@ func (det *fileDetector) scanWorkspaceDirectory(wsDir WorkspaceDirectory, signat
280227 case files <- file :
281228 log .Infof ("File sent to channel: %s" , filePath )
282229 default :
283- det .droppedFilesTotal .Inc ()
284230 log .Warnf ("File dropped (channel full): %s" , filePath )
285231 }
286232 }
0 commit comments