Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove code analytics #15

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions observability/analytics.go

This file was deleted.

47 changes: 0 additions & 47 deletions observability/mocks/analytics.go

This file was deleted.

11 changes: 1 addition & 10 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type codeScanner struct {
bundleManager bundle.BundleManager
instrumentor observability.Instrumentor
errorReporter observability.ErrorReporter
analytics observability.Analytics
logger *zerolog.Logger
}

Expand All @@ -45,7 +44,6 @@ type CodeScanner interface {
path string,
files <-chan string,
changedFiles map[string]bool,
scanMetrics observability.ScanMetrics,
) (*sarif.SarifResponse, bundle.Bundle, error)
}

Expand All @@ -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,
}
}
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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
}
17 changes: 5 additions & 12 deletions scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
)

Expand All @@ -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(
Expand All @@ -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())
Expand All @@ -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())
Expand Down
Loading