Skip to content

Commit 0f260ba

Browse files
refactor: remove code analytics (#15)
1 parent 34b1814 commit 0f260ba

File tree

4 files changed

+6
-108
lines changed

4 files changed

+6
-108
lines changed

observability/analytics.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

observability/mocks/analytics.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

scan.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type codeScanner struct {
3434
bundleManager bundle.BundleManager
3535
instrumentor observability.Instrumentor
3636
errorReporter observability.ErrorReporter
37-
analytics observability.Analytics
3837
logger *zerolog.Logger
3938
}
4039

@@ -45,7 +44,6 @@ type CodeScanner interface {
4544
path string,
4645
files <-chan string,
4746
changedFiles map[string]bool,
48-
scanMetrics observability.ScanMetrics,
4947
) (*sarif.SarifResponse, bundle.Bundle, error)
5048
}
5149

@@ -54,14 +52,12 @@ func NewCodeScanner(
5452
bundleManager bundle.BundleManager,
5553
instrumentor observability.Instrumentor,
5654
errorReporter observability.ErrorReporter,
57-
analytics observability.Analytics,
5855
logger *zerolog.Logger,
5956
) *codeScanner {
6057
return &codeScanner{
6158
bundleManager: bundleManager,
6259
instrumentor: instrumentor,
6360
errorReporter: errorReporter,
64-
analytics: analytics,
6561
logger: logger,
6662
}
6763
}
@@ -73,7 +69,6 @@ func (c *codeScanner) UploadAndAnalyze(
7369
path string,
7470
files <-chan string,
7571
changedFiles map[string]bool,
76-
scanMetrics observability.ScanMetrics,
7772
) (*sarif.SarifResponse, bundle.Bundle, error) {
7873
if ctx.Err() != nil {
7974
c.logger.Info().Msg("Canceling Code scan - Code scanner received cancellation signal")
@@ -94,7 +89,6 @@ func (c *codeScanner) UploadAndAnalyze(
9489
if ctx.Err() == nil { // Only report errors that are not intentional cancellations
9590
msg := "error creating bundle..."
9691
c.errorReporter.CaptureError(errors.Wrap(err, msg), observability.ErrorReporterOptions{ErrorDiagnosticPath: path})
97-
c.analytics.TrackScan(err == nil, scanMetrics)
9892
return nil, nil, err
9993
} else {
10094
c.logger.Info().Msg("Canceling Code scan - Code scanner received cancellation signal")
@@ -103,14 +97,12 @@ func (c *codeScanner) UploadAndAnalyze(
10397
}
10498

10599
uploadedFiles := b.GetFiles()
106-
scanMetrics.SetLastScanFileCount(len(uploadedFiles))
107100

108101
b, err = c.bundleManager.Upload(span.Context(), host, b, uploadedFiles)
109102
if err != nil {
110103
if ctx.Err() != nil { // Only handle errors that are not intentional cancellations
111104
msg := "error uploading files..."
112105
c.errorReporter.CaptureError(errors.Wrap(err, msg), observability.ErrorReporterOptions{ErrorDiagnosticPath: path})
113-
c.analytics.TrackScan(err == nil, scanMetrics)
114106
return nil, b, err
115107
} else {
116108
log.Info().Msg("Canceling Code scan - Code scanner received cancellation signal")
@@ -129,6 +121,5 @@ func (c *codeScanner) UploadAndAnalyze(
129121
return nil, nil, nil
130122
}
131123

132-
c.analytics.TrackScan(err == nil, scanMetrics)
133-
return response, b, nil
124+
return response, b, err
134125
}

scan_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ package codeclient_test
1717

1818
import (
1919
"context"
20-
"github.com/rs/zerolog"
2120
"os"
2221
"path/filepath"
2322
"testing"
24-
"time"
2523

2624
"github.com/golang/mock/gomock"
25+
"github.com/rs/zerolog"
2726
"github.com/stretchr/testify/assert"
2827
"github.com/stretchr/testify/require"
2928

@@ -32,7 +31,6 @@ import (
3231
mocks2 "github.com/snyk/code-client-go/bundle/mocks"
3332
"github.com/snyk/code-client-go/deepcode"
3433
mocks3 "github.com/snyk/code-client-go/deepcode/mocks"
35-
"github.com/snyk/code-client-go/observability"
3634
"github.com/snyk/code-client-go/observability/mocks"
3735
)
3836

@@ -44,8 +42,6 @@ func Test_UploadAndAnalyze(t *testing.T) {
4442
firstDocPath: deepcode.BundleFileFrom(secondDocPath, secondDocContent),
4543
}
4644

47-
scanMetrics := observability.NewScanMetrics(time.Now(), 0)
48-
4945
logger := zerolog.Nop()
5046

5147
t.Run(
@@ -62,11 +58,10 @@ func Test_UploadAndAnalyze(t *testing.T) {
6258
mockBundleManager := mocks2.NewMockBundleManager(ctrl)
6359
mockBundleManager.EXPECT().Create(gomock.Any(), "testHost", "testRequestId", baseDir, gomock.Any(), map[string]bool{}).Return(mockBundle, nil)
6460
mockBundleManager.EXPECT().Upload(gomock.Any(), "testHost", mockBundle, files).Return(mockBundle, nil)
65-
mockAnalytics := mocks.NewMockAnalytics(ctrl)
6661

67-
codeScanner := codeclient.NewCodeScanner(mockBundleManager, mockInstrumentor, mockErrorReporter, mockAnalytics, &logger)
62+
codeScanner := codeclient.NewCodeScanner(mockBundleManager, mockInstrumentor, mockErrorReporter, &logger)
6863

69-
response, bundle, err := codeScanner.UploadAndAnalyze(context.Background(), "testHost", baseDir, docs, map[string]bool{}, scanMetrics)
64+
response, bundle, err := codeScanner.UploadAndAnalyze(context.Background(), "testHost", baseDir, docs, map[string]bool{})
7065
require.NoError(t, err)
7166
assert.Equal(t, "", bundle.GetBundleHash())
7267
assert.Equal(t, files, bundle.GetFiles())
@@ -88,12 +83,10 @@ func Test_UploadAndAnalyze(t *testing.T) {
8883
mockBundleManager := mocks2.NewMockBundleManager(ctrl)
8984
mockBundleManager.EXPECT().Create(gomock.Any(), "testHost", "testRequestId", baseDir, gomock.Any(), map[string]bool{}).Return(mockBundle, nil)
9085
mockBundleManager.EXPECT().Upload(gomock.Any(), "testHost", mockBundle, files).Return(mockBundle, nil)
91-
mockAnalytics := mocks.NewMockAnalytics(ctrl)
92-
mockAnalytics.EXPECT().TrackScan(true, gomock.AssignableToTypeOf(observability.ScanMetrics{}))
9386

94-
codeScanner := codeclient.NewCodeScanner(mockBundleManager, mockInstrumentor, mockErrorReporter, mockAnalytics, &logger)
87+
codeScanner := codeclient.NewCodeScanner(mockBundleManager, mockInstrumentor, mockErrorReporter, &logger)
9588

96-
response, bundle, err := codeScanner.UploadAndAnalyze(context.Background(), "testHost", baseDir, docs, map[string]bool{}, scanMetrics)
89+
response, bundle, err := codeScanner.UploadAndAnalyze(context.Background(), "testHost", baseDir, docs, map[string]bool{})
9790
require.NoError(t, err)
9891
assert.Equal(t, "COMPLETE", response.Status)
9992
assert.Equal(t, "testBundleHash", bundle.GetBundleHash())

0 commit comments

Comments
 (0)