Skip to content

Commit 4ae0c41

Browse files
feat: send delta scan information to analytics [IDE-528] (#621)
1 parent 87a072a commit 4ae0c41

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

domain/ide/workspace/folder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ func sendAnalytics(data *snyk.ScanData) {
405405
ic.SetTargetId(targetId)
406406

407407
ic.AddExtension("device_id", c.DeviceID())
408+
ic.AddExtension("is_delta_scan", data.IsDeltaScan)
408409

409410
//Populate the runtime attribute of the analytics event
410411
ua := util.GetUserAgent(gafConfig, config.Version)

domain/ide/workspace/folder_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ package workspace
1919
import (
2020
"context"
2121
"errors"
22-
"github.com/snyk/snyk-ls/domain/snyk/persistence"
2322
"path/filepath"
2423
"sync"
2524
"testing"
2625
"time"
2726

27+
"github.com/snyk/snyk-ls/domain/snyk/persistence"
28+
2829
"github.com/golang/mock/gomock"
2930
"github.com/google/uuid"
3031
"github.com/puzpuzpuz/xsync/v3"

domain/snyk/scan_result_processor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type ScanData struct {
2929
DurationMs time.Duration
3030
TimestampFinished time.Time
3131
Path string
32+
IsDeltaScan bool
3233
}
3334

3435
type ScanResultProcessor = func(scanData ScanData)

domain/snyk/scanner.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ func (sc *DelegatingConcurrentScanner) Scan(
272272
TimestampFinished: time.Now().UTC(),
273273
Path: folderPath,
274274
}
275+
276+
// in case of delta scans, we add additional fields
277+
if deltaScanner, ok := s.(types.DeltaScanner); ok {
278+
data.IsDeltaScan = deltaScanner.DeltaScanningEnabled()
279+
}
280+
275281
processResults(data)
276282
logger.Info().Msgf("Scanning %s with %T: COMPLETE found %v issues", path, s, len(foundIssues))
277283
}(scanner)

infrastructure/code/code.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import (
4848
"github.com/snyk/snyk-ls/internal/uri"
4949
)
5050

51+
var _ types.DeltaScanner = (*Scanner)(nil)
52+
5153
type ScanStatus struct {
5254
// finished channel is closed once the scan has finished
5355
finished chan bool
@@ -92,6 +94,10 @@ type Scanner struct {
9294
scanPersister persistence.ScanSnapshotPersister
9395
}
9496

97+
func (sc *Scanner) DeltaScanningEnabled() bool {
98+
return sc.c.IsDeltaFindingsEnabled()
99+
}
100+
95101
func New(bundleUploader *BundleUploader, apiClient snyk_api.SnykApiClient, reporter codeClientObservability.ErrorReporter, learnService learn.Service, notifier notification.Notifier, codeScanner codeClient.CodeScanner, scanPersister persistence.ScanSnapshotPersister) *Scanner {
96102
sc := &Scanner{
97103
BundleUploader: bundleUploader,

internal/types/delta.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* © 2024 Snyk Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package types
18+
19+
type DeltaScanner interface {
20+
DeltaScanningEnabled() bool
21+
}

0 commit comments

Comments
 (0)