From 58d4fc95b0513d0b50eaad8ad04badeb8894a5e2 Mon Sep 17 00:00:00 2001 From: PeterSchafer <101886095+PeterSchafer@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:03:29 +0200 Subject: [PATCH] fix: Sending instrumentation data from VS and IntelliJ (#5287) * fix: Send all instrumentation data from report workflow * chore: update gaf * chore: update gaf * chore: update final gaf version --- cliv2/cmd/cliv2/instrumentation.go | 2 +- cliv2/cmd/cliv2/instrumentation_test.go | 2 +- cliv2/cmd/cliv2/main.go | 14 +++----------- cliv2/go.mod | 2 +- cliv2/go.sum | 4 ++-- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/cliv2/cmd/cliv2/instrumentation.go b/cliv2/cmd/cliv2/instrumentation.go index a95caf0c60..cb77cfca5a 100644 --- a/cliv2/cmd/cliv2/instrumentation.go +++ b/cliv2/cmd/cliv2/instrumentation.go @@ -18,7 +18,7 @@ func shallSendInstrumentation(config configuration.Configuration, instrumentor a isSnykIde := utils.IsSnykIde(integration) isReportCommand := strings.Contains(category, instrumentationCommand) - if isSnykIde && !isReportCommand { + if isSnykIde || isReportCommand { return false } diff --git a/cliv2/cmd/cliv2/instrumentation_test.go b/cliv2/cmd/cliv2/instrumentation_test.go index 1949f6f800..5c13df3973 100644 --- a/cliv2/cmd/cliv2/instrumentation_test.go +++ b/cliv2/cmd/cliv2/instrumentation_test.go @@ -24,5 +24,5 @@ func Test_shallSendInstrumentation(t *testing.T) { // case: analytics report command called from an IDE instrumentor.SetCategory([]string{"analytics", "report", "inputData"}) actual = shallSendInstrumentation(config, instrumentor) - assert.True(t, actual) + assert.False(t, actual) } diff --git a/cliv2/cmd/cliv2/main.go b/cliv2/cmd/cliv2/main.go index a62a64f792..7d77995ebb 100644 --- a/cliv2/cmd/cliv2/main.go +++ b/cliv2/cmd/cliv2/main.go @@ -255,7 +255,7 @@ func sendAnalytics(analytics analytics.Analytics, debugLogger *zerolog.Logger) { func sendInstrumentation(eng workflow.Engine, instrumentor analytics.InstrumentationCollector, logger *zerolog.Logger) { // Avoid duplicate data to be sent for IDE integrations that use the CLI if !shallSendInstrumentation(eng.GetConfiguration(), instrumentor) { - logger.Print("Called from IDE, not sending instrumentation") + logger.Print("This CLI call is not instrumented!") return } @@ -266,21 +266,13 @@ func sendInstrumentation(eng workflow.Engine, instrumentor analytics.Instrumenta } v2InstrumentationData := utils.ValueOf(json.Marshal(data)) - logger.Trace().Msgf("Instrumentation: %v", string(v2InstrumentationData)) - - inputData := workflow.NewData( - workflow.NewTypeIdentifier(localworkflows.WORKFLOWID_REPORT_ANALYTICS, "reportAnalytics"), - "application/json", - v2InstrumentationData, - ) - localConfiguration := globalConfiguration.Clone() // the report analytics workflow needs --experimental to run // we pass the flag here so that we report at every interaction localConfiguration.Set(configuration.FLAG_EXPERIMENTAL, true) - _, err = eng.InvokeWithInputAndConfig( + localConfiguration.Set("inputData", string(v2InstrumentationData)) + _, err = eng.InvokeWithConfig( localworkflows.WORKFLOWID_REPORT_ANALYTICS, - []workflow.Data{inputData}, localConfiguration, ) diff --git a/cliv2/go.mod b/cliv2/go.mod index 755d43361f..9638401a1b 100644 --- a/cliv2/go.mod +++ b/cliv2/go.mod @@ -15,7 +15,7 @@ require ( github.com/snyk/cli-extension-sbom v0.0.0-20240523084359-a2830fadb001 github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1 github.com/snyk/error-catalog-golang-public v0.0.0-20240527112826-2b77438d25f1 - github.com/snyk/go-application-framework v0.0.0-20240603174251-84f6ded78c8f + github.com/snyk/go-application-framework v0.0.0-20240605102342-67b064c1e417 github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 github.com/snyk/snyk-iac-capture v0.6.5 github.com/snyk/snyk-ls v0.0.0-20240603144138-b7b4b7626a10 diff --git a/cliv2/go.sum b/cliv2/go.sum index f3e1569bee..17180437b1 100644 --- a/cliv2/go.sum +++ b/cliv2/go.sum @@ -731,8 +731,8 @@ github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1 h1:9RKY9NdX5DrJ github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM= github.com/snyk/error-catalog-golang-public v0.0.0-20240527112826-2b77438d25f1 h1:49X/bTeiWdi+DrkTbTSw5BePpQ6LiucIt++/Z+MB95U= github.com/snyk/error-catalog-golang-public v0.0.0-20240527112826-2b77438d25f1/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4= -github.com/snyk/go-application-framework v0.0.0-20240603174251-84f6ded78c8f h1:GucVC2OeSXfWVkHxZJ2xFRl2uXWk2YDl0SsF45HZt/Y= -github.com/snyk/go-application-framework v0.0.0-20240603174251-84f6ded78c8f/go.mod h1:1T6hnPUgT0lJPO0g3VjwvW0fCKDcgst8bgXs+wCfmW8= +github.com/snyk/go-application-framework v0.0.0-20240605102342-67b064c1e417 h1:piXelZOB/V+kfUGouG/nm6F2YKNCXH993bC0YqtW+gc= +github.com/snyk/go-application-framework v0.0.0-20240605102342-67b064c1e417/go.mod h1:1T6hnPUgT0lJPO0g3VjwvW0fCKDcgst8bgXs+wCfmW8= github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk= github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg= github.com/snyk/policy-engine v0.30.11 h1:wUy5LMar2vccMbNM62MSBRdjAQAhAbIm7aNXXO+g2tk=