From d997fc6713055eaf7952c3f0650497caccb415b5 Mon Sep 17 00:00:00 2001 From: Pranav Gaikwad Date: Fri, 21 Jun 2024 13:11:18 -0400 Subject: [PATCH 1/7] :sparkles: configure builtin provider internally Signed-off-by: Pranav Gaikwad --- Makefile | 2 +- cmd/analyzer/main.go | 33 +- cmd/dep/main.go | 2 +- demo-output.yaml | 30 +- .../pkg/dotnet/provider.go | 19 +- .../pkg/generic_external_provider/provider.go | 8 +- .../generic/service_client_test.go | 2 +- .../pylsp/service_client_test.go | 2 +- .../service_client_test.go | 2 +- .../pkg/java_external_provider/provider.go | 30 +- .../pkg/yq_provider/provider.go | 14 +- parser/rule_parser_test.go | 8 +- provider/grpc/provider.go | 33 +- provider/internal/builtin/provider.go | 24 +- provider/internal/grpc/library.pb.go | 521 +++++++++--------- provider/internal/grpc/library.proto | 1 + provider/internal/grpc/library_grpc.pb.go | 2 +- provider/provider.go | 8 +- provider/provider_test.go | 4 +- provider/server.go | 13 +- provider_container_settings.json | 2 +- provider_local_external_images.json | 2 +- provider_pod_local_settings.json | 2 +- 23 files changed, 428 insertions(+), 336 deletions(-) diff --git a/Makefile b/Makefile index 28b87bd9..13355d3a 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ run-external-providers-pod: podman build -f demo-local.Dockerfile -t localhost/testing:latest run-demo-image: - podman run --entrypoint /usr/local/bin/konveyor-analyzer --pod=analyzer -v $(PWD)/demo-dep-output.yaml:/analyzer-lsp/demo-dep-output.yaml:Z -v $(PWD)/demo-output.yaml:/analyzer-lsp/output.yaml:Z localhost/testing:latest --output-file=/analyzer-lsp/output.yaml --dep-output-file=/analyzer-lsp/demo-dep-output.yaml + podman run --entrypoint /usr/local/bin/konveyor-analyzer --pod=analyzer -v test-data:/analyzer-lsp/examples$(MOUNT_OPT) -v $(PWD)/demo-dep-output.yaml:/analyzer-lsp/demo-dep-output.yaml:Z -v $(PWD)/demo-output.yaml:/analyzer-lsp/output.yaml:Z localhost/testing:latest --output-file=/analyzer-lsp/output.yaml --dep-output-file=/analyzer-lsp/demo-dep-output.yaml stop-external-providers-pod: stop-external-providers podman pod kill analyzer diff --git a/cmd/analyzer/main.go b/cmd/analyzer/main.go index c7de70f8..a5aee3ce 100644 --- a/cmd/analyzer/main.go +++ b/cmd/analyzer/main.go @@ -128,6 +128,7 @@ func AnalysisCmd() *cobra.Command { } providers := map[string]provider.InternalProviderClient{} + builtinConfigs := []provider.InitConfig{} providerLocations := []string{} for _, config := range configs { config.ContextLines = contextLines @@ -140,6 +141,9 @@ func AnalysisCmd() *cobra.Command { for _, i := range config.InitConfig { i.AnalysisMode = provider.AnalysisMode(analysisMode) inits = append(inits, i) + builtinConfigs = append(builtinConfigs, provider.InitConfig{ + Location: i.Location, + }) } config.InitConfig = inits } @@ -205,14 +209,31 @@ func AnalysisCmd() *cobra.Command { } // Now that we have all the providers, we need to start them. for name, provider := range needProviders { - initCtx, initSpan := tracing.StartNewSpan(ctx, "init", - attribute.Key("provider").String(name)) - err := provider.ProviderInit(initCtx) - if err != nil { - errLog.Error(err, "unable to init the providers", "provider", name) + switch name { + // other providers can return additional configs for the builtin provider + // therefore, we initiate builtin provider separately at the end + case "builtin": + continue + default: + initCtx, initSpan := tracing.StartNewSpan(ctx, "init", + attribute.Key("provider").String(name)) + additionalBuiltinConfs, err := provider.ProviderInit(initCtx, nil) + if err != nil { + errLog.Error(err, "unable to init the providers", "provider", name) + os.Exit(1) + } + if additionalBuiltinConfs != nil { + builtinConfigs = append(builtinConfigs, additionalBuiltinConfs...) + } + initSpan.End() + } + } + + if builtinClient, ok := needProviders["builtin"]; ok { + if _, err = builtinClient.ProviderInit(ctx, builtinConfigs); err != nil { + errLog.Error(err, "unable to init builtin provider") os.Exit(1) } - initSpan.End() } wg := &sync.WaitGroup{} diff --git a/cmd/dep/main.go b/cmd/dep/main.go index 67615589..beb985a3 100644 --- a/cmd/dep/main.go +++ b/cmd/dep/main.go @@ -90,7 +90,7 @@ func DependencyCmd() *cobra.Command { time.Sleep(5 * time.Second) - err = prov.ProviderInit(ctx) + _, err = prov.ProviderInit(ctx, nil) b, _ := json.Marshal(config) if err != nil { errLog.Error(err, "unable to init the providers", "provider", config.Name, "the-error-is", err, "config", string(b)) diff --git a/demo-output.yaml b/demo-output.yaml index bdbbe45a..9d0873a3 100644 --- a/demo-output.yaml +++ b/demo-output.yaml @@ -201,6 +201,14 @@ data: dependency innerText: "\n\t\t\torg.springframework\n\t\t\tspring-webmvc\n\t\t\t${spring-framework.version}\n\t\t" matchingXML: org.springframeworkspring-webmvc${spring-framework.version} + - uri: file:///examples/java-project/pom.xml + message: io.javaoperatorsdk.operatorsample0.0.0 + codeSnip: "11 http://www.konveyor.io\n12 \n13 \n14 UTF-8\n15 \n16 \n17 \n18 \n19 \n20 io.javaoperatorsdk.operator\n21 sample\n22 0.0.0\n23 \n24 \n25 \n26 \n27 \n28 \n29 \n" + lineNumber: 20 + variables: + data: dependency + innerText: "\n io.javaoperatorsdk.operator\n sample\n 0.0.0\n " + matchingXML: io.javaoperatorsdk.operatorsample0.0.0 - uri: file:///examples/java/dummy/pom.xml message: |- javaxjavaee-api