diff --git a/observability/analytics.go b/observability/analytics.go deleted file mode 100644 index a19559d7..00000000 --- a/observability/analytics.go +++ /dev/null @@ -1,39 +0,0 @@ -package observability - -import "time" - -// Analytics exposes different metric tracking functions. -// -//go:generate mockgen -destination=mocks/analytics.go -source=analytics.go -package mocks -type Analytics interface { - TrackScan(bool, ScanMetrics) -} - -// ScanMetrics contains various metrics about the Snyk Code scan. -type ScanMetrics struct { - lastScanStartTime time.Time - lastScanFileCount int -} - -// NewScanMetrics is used to create a ScanMetrics object. -func NewScanMetrics(lastScanStartTime time.Time, lastScanFileCount int) ScanMetrics { - return ScanMetrics{ - lastScanStartTime: lastScanStartTime, - lastScanFileCount: lastScanFileCount, - } -} - -// GetDuration computes the duration since the last time a scan starter. -func (s ScanMetrics) GetDuration() time.Duration { - return time.Since(s.lastScanStartTime) -} - -// GetLastScanFileCount returns the count of files since the last scan. -func (s ScanMetrics) GetLastScanFileCount() int { - return s.lastScanFileCount -} - -// SetLastScanFileCount sets the count of files since the last scan. -func (s *ScanMetrics) SetLastScanFileCount(lastScanFileCount int) { - s.lastScanFileCount = lastScanFileCount -} diff --git a/observability/mocks/analytics.go b/observability/mocks/analytics.go deleted file mode 100644 index d2d4963a..00000000 --- a/observability/mocks/analytics.go +++ /dev/null @@ -1,47 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: analytics.go - -// Package mocks is a generated GoMock package. -package mocks - -import ( - reflect "reflect" - - gomock "github.com/golang/mock/gomock" - observability "github.com/snyk/code-client-go/observability" -) - -// MockAnalytics is a mock of Analytics interface. -type MockAnalytics struct { - ctrl *gomock.Controller - recorder *MockAnalyticsMockRecorder -} - -// MockAnalyticsMockRecorder is the mock recorder for MockAnalytics. -type MockAnalyticsMockRecorder struct { - mock *MockAnalytics -} - -// NewMockAnalytics creates a new mock instance. -func NewMockAnalytics(ctrl *gomock.Controller) *MockAnalytics { - mock := &MockAnalytics{ctrl: ctrl} - mock.recorder = &MockAnalyticsMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockAnalytics) EXPECT() *MockAnalyticsMockRecorder { - return m.recorder -} - -// TrackScan mocks base method. -func (m *MockAnalytics) TrackScan(arg0 bool, arg1 observability.ScanMetrics) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "TrackScan", arg0, arg1) -} - -// TrackScan indicates an expected call of TrackScan. -func (mr *MockAnalyticsMockRecorder) TrackScan(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TrackScan", reflect.TypeOf((*MockAnalytics)(nil).TrackScan), arg0, arg1) -} diff --git a/scan.go b/scan.go index 7adce84b..8ce49522 100644 --- a/scan.go +++ b/scan.go @@ -34,7 +34,6 @@ type codeScanner struct { bundleManager bundle.BundleManager instrumentor observability.Instrumentor errorReporter observability.ErrorReporter - analytics observability.Analytics logger *zerolog.Logger } @@ -45,7 +44,6 @@ type CodeScanner interface { path string, files <-chan string, changedFiles map[string]bool, - scanMetrics observability.ScanMetrics, ) (*sarif.SarifResponse, bundle.Bundle, error) } @@ -54,14 +52,12 @@ func NewCodeScanner( bundleManager bundle.BundleManager, instrumentor observability.Instrumentor, errorReporter observability.ErrorReporter, - analytics observability.Analytics, logger *zerolog.Logger, ) *codeScanner { return &codeScanner{ bundleManager: bundleManager, instrumentor: instrumentor, errorReporter: errorReporter, - analytics: analytics, logger: logger, } } @@ -73,7 +69,6 @@ func (c *codeScanner) UploadAndAnalyze( path string, files <-chan string, changedFiles map[string]bool, - scanMetrics observability.ScanMetrics, ) (*sarif.SarifResponse, bundle.Bundle, error) { if ctx.Err() != nil { c.logger.Info().Msg("Canceling Code scan - Code scanner received cancellation signal") @@ -94,7 +89,6 @@ func (c *codeScanner) UploadAndAnalyze( if ctx.Err() == nil { // Only report errors that are not intentional cancellations msg := "error creating bundle..." c.errorReporter.CaptureError(errors.Wrap(err, msg), observability.ErrorReporterOptions{ErrorDiagnosticPath: path}) - c.analytics.TrackScan(err == nil, scanMetrics) return nil, nil, err } else { c.logger.Info().Msg("Canceling Code scan - Code scanner received cancellation signal") @@ -103,14 +97,12 @@ func (c *codeScanner) UploadAndAnalyze( } uploadedFiles := b.GetFiles() - scanMetrics.SetLastScanFileCount(len(uploadedFiles)) b, err = c.bundleManager.Upload(span.Context(), host, b, uploadedFiles) if err != nil { if ctx.Err() != nil { // Only handle errors that are not intentional cancellations msg := "error uploading files..." c.errorReporter.CaptureError(errors.Wrap(err, msg), observability.ErrorReporterOptions{ErrorDiagnosticPath: path}) - c.analytics.TrackScan(err == nil, scanMetrics) return nil, b, err } else { log.Info().Msg("Canceling Code scan - Code scanner received cancellation signal") @@ -129,6 +121,5 @@ func (c *codeScanner) UploadAndAnalyze( return nil, nil, nil } - c.analytics.TrackScan(err == nil, scanMetrics) - return response, b, nil + return response, b, err } diff --git a/scan_test.go b/scan_test.go index c9ae3009..a335675e 100644 --- a/scan_test.go +++ b/scan_test.go @@ -17,13 +17,12 @@ package codeclient_test import ( "context" - "github.com/rs/zerolog" "os" "path/filepath" "testing" - "time" "github.com/golang/mock/gomock" + "github.com/rs/zerolog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -32,7 +31,6 @@ import ( mocks2 "github.com/snyk/code-client-go/bundle/mocks" "github.com/snyk/code-client-go/deepcode" mocks3 "github.com/snyk/code-client-go/deepcode/mocks" - "github.com/snyk/code-client-go/observability" "github.com/snyk/code-client-go/observability/mocks" ) @@ -44,8 +42,6 @@ func Test_UploadAndAnalyze(t *testing.T) { firstDocPath: deepcode.BundleFileFrom(secondDocPath, secondDocContent), } - scanMetrics := observability.NewScanMetrics(time.Now(), 0) - logger := zerolog.Nop() t.Run( @@ -62,11 +58,10 @@ func Test_UploadAndAnalyze(t *testing.T) { mockBundleManager := mocks2.NewMockBundleManager(ctrl) mockBundleManager.EXPECT().Create(gomock.Any(), "testHost", "testRequestId", baseDir, gomock.Any(), map[string]bool{}).Return(mockBundle, nil) mockBundleManager.EXPECT().Upload(gomock.Any(), "testHost", mockBundle, files).Return(mockBundle, nil) - mockAnalytics := mocks.NewMockAnalytics(ctrl) - codeScanner := codeclient.NewCodeScanner(mockBundleManager, mockInstrumentor, mockErrorReporter, mockAnalytics, &logger) + codeScanner := codeclient.NewCodeScanner(mockBundleManager, mockInstrumentor, mockErrorReporter, &logger) - response, bundle, err := codeScanner.UploadAndAnalyze(context.Background(), "testHost", baseDir, docs, map[string]bool{}, scanMetrics) + response, bundle, err := codeScanner.UploadAndAnalyze(context.Background(), "testHost", baseDir, docs, map[string]bool{}) require.NoError(t, err) assert.Equal(t, "", bundle.GetBundleHash()) assert.Equal(t, files, bundle.GetFiles()) @@ -88,12 +83,10 @@ func Test_UploadAndAnalyze(t *testing.T) { mockBundleManager := mocks2.NewMockBundleManager(ctrl) mockBundleManager.EXPECT().Create(gomock.Any(), "testHost", "testRequestId", baseDir, gomock.Any(), map[string]bool{}).Return(mockBundle, nil) mockBundleManager.EXPECT().Upload(gomock.Any(), "testHost", mockBundle, files).Return(mockBundle, nil) - mockAnalytics := mocks.NewMockAnalytics(ctrl) - mockAnalytics.EXPECT().TrackScan(true, gomock.AssignableToTypeOf(observability.ScanMetrics{})) - codeScanner := codeclient.NewCodeScanner(mockBundleManager, mockInstrumentor, mockErrorReporter, mockAnalytics, &logger) + codeScanner := codeclient.NewCodeScanner(mockBundleManager, mockInstrumentor, mockErrorReporter, &logger) - response, bundle, err := codeScanner.UploadAndAnalyze(context.Background(), "testHost", baseDir, docs, map[string]bool{}, scanMetrics) + response, bundle, err := codeScanner.UploadAndAnalyze(context.Background(), "testHost", baseDir, docs, map[string]bool{}) require.NoError(t, err) assert.Equal(t, "COMPLETE", response.Status) assert.Equal(t, "testBundleHash", bundle.GetBundleHash())