-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(instrumentation): Send transformed v1 data from IDEs (#5280)
* fix: send v1 instrumentation if explicitly called * chore: remove redundant log message * chore: update gaf * chore: upgrade gaf * chore: update final gaf
- Loading branch information
1 parent
45f884a
commit d33a773
Showing
5 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/snyk/go-application-framework/pkg/analytics" | ||
"github.com/snyk/go-application-framework/pkg/configuration" | ||
localworkflows "github.com/snyk/go-application-framework/pkg/local_workflows" | ||
"github.com/snyk/go-application-framework/pkg/utils" | ||
"github.com/snyk/go-application-framework/pkg/workflow" | ||
) | ||
|
||
func shallSendInstrumentation(config configuration.Configuration, instrumentor analytics.InstrumentationCollector) bool { | ||
instrumentationCommand := workflow.GetCommandFromWorkflowIdentifier(localworkflows.WORKFLOWID_REPORT_ANALYTICS) | ||
category := strings.Join(instrumentor.GetCategory(), " ") | ||
integration := config.GetString(configuration.INTEGRATION_NAME) | ||
|
||
isSnykIde := utils.IsSnykIde(integration) | ||
isReportCommand := strings.Contains(category, instrumentationCommand) | ||
|
||
if isSnykIde && !isReportCommand { | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/snyk/go-application-framework/pkg/analytics" | ||
"github.com/snyk/go-application-framework/pkg/configuration" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_shallSendInstrumentation(t *testing.T) { | ||
config := configuration.NewInMemory() | ||
instrumentor := analytics.NewInstrumentationCollector() | ||
|
||
// case: nothing configured | ||
actual := shallSendInstrumentation(config, instrumentor) | ||
assert.True(t, actual) | ||
|
||
// case: any command called from an IDE | ||
config.Set(configuration.INTEGRATION_NAME, "VS_CODE") | ||
actual = shallSendInstrumentation(config, instrumentor) | ||
assert.False(t, actual) | ||
|
||
// case: analytics report command called from an IDE | ||
instrumentor.SetCategory([]string{"analytics", "report", "inputData"}) | ||
actual = shallSendInstrumentation(config, instrumentor) | ||
assert.True(t, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters