diff --git a/cmd/dep/main.go b/cmd/dep/main.go index 85d3d812..998e7588 100644 --- a/cmd/dep/main.go +++ b/cmd/dep/main.go @@ -103,7 +103,7 @@ func main() { } if treeOutput { - deps, err := prov.GetDependenciesDAG() + deps, err := prov.GetDependenciesDAG(ctx) if err != nil { log.Error(err, "failed to get list of dependencies for provider", "provider", name) continue @@ -116,7 +116,7 @@ func main() { }) } } else { - deps, err := prov.GetDependencies() + deps, err := prov.GetDependencies(ctx) if err != nil { log.Error(err, "failed to get list of dependencies for provider", "provider", name) continue diff --git a/engine/engine.go b/engine/engine.go index e13a1320..9c192f5d 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -175,7 +175,7 @@ func (r *ruleEngine) RunRules(ctx context.Context, ruleSets []RuleSet, selectors rs.Errors[response.Rule.RuleID] = response.Err.Error() } } else if response.ConditionResponse.Matched && len(response.ConditionResponse.Incidents) > 0 { - violation, err := r.createViolation(response.ConditionResponse, response.Rule) + violation, err := r.createViolation(ctx, response.ConditionResponse, response.Rule) if err != nil { r.logger.Error(err, "unable to create violation from response") } @@ -388,7 +388,7 @@ func processRule(ctx context.Context, rule Rule, ruleCtx ConditionContext, log l } -func (r *ruleEngine) createViolation(conditionResponse ConditionResponse, rule Rule) (konveyor.Violation, error) { +func (r *ruleEngine) createViolation(ctx context.Context, conditionResponse ConditionResponse, rule Rule) (konveyor.Violation, error) { incidents := []konveyor.Incident{} fileCodeSnipCount := map[string]int{} incidentsSet := map[string]struct{}{} // Set of incidents @@ -409,7 +409,7 @@ func (r *ruleEngine) createViolation(conditionResponse ConditionResponse, rule R // Some violations may not have a location in code. limitSnip := (r.codeSnipLimit != 0 && fileCodeSnipCount[string(m.FileURI)] == r.codeSnipLimit) if !limitSnip { - codeSnip, err := r.getCodeLocation(m, rule) + codeSnip, err := r.getCodeLocation(ctx, m, rule) if err != nil || codeSnip == "" { r.logger.V(6).Error(err, "unable to get code location") } else { @@ -496,7 +496,7 @@ func (r *ruleEngine) createViolation(conditionResponse ConditionResponse, rule R }, nil } -func (r *ruleEngine) getCodeLocation(m IncidentContext, rule Rule) (codeSnip string, err error) { +func (r *ruleEngine) getCodeLocation(ctx context.Context, m IncidentContext, rule Rule) (codeSnip string, err error) { if m.CodeLocation == nil { r.logger.V(6).Info("unable to get the code snip", "URI", m.FileURI) return "", nil diff --git a/external-providers/generic-external-provider/pkg/generic/dependency.go b/external-providers/generic-external-provider/pkg/generic/dependency.go index 4a90cdb1..dc737869 100644 --- a/external-providers/generic-external-provider/pkg/generic/dependency.go +++ b/external-providers/generic-external-provider/pkg/generic/dependency.go @@ -1,6 +1,7 @@ package generic import ( + "context" "encoding/json" "fmt" "os/exec" @@ -9,7 +10,7 @@ import ( "go.lsp.dev/uri" ) -func (g *genericServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, error) { +func (g *genericServiceClient) GetDependencies(ctx context.Context) (map[uri.URI][]*provider.Dep, error) { cmdStr, isString := g.config.ProviderSpecificConfig["dependencyProviderPath"].(string) if !isString { return nil, fmt.Errorf("dependency provider path is not a string") @@ -33,6 +34,6 @@ func (g *genericServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, e return m, err } -func (p *genericServiceClient) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { +func (p *genericServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) { return nil, nil } diff --git a/external-providers/generic-external-provider/pkg/generic/provider.go b/external-providers/generic-external-provider/pkg/generic/provider.go index 32e0bf0d..d1c3e22b 100644 --- a/external-providers/generic-external-provider/pkg/generic/provider.go +++ b/external-providers/generic-external-provider/pkg/generic/provider.go @@ -110,7 +110,6 @@ func (p *genericProvider) Init(ctx context.Context, log logr.Logger, c provider. svcClient := genericServiceClient{ rpc: rpc, - ctx: ctx, cancelFunc: cancelFunc, cmd: cmd, config: c, diff --git a/external-providers/generic-external-provider/pkg/generic/service_client.go b/external-providers/generic-external-provider/pkg/generic/service_client.go index 06f4600b..ed99e98f 100644 --- a/external-providers/generic-external-provider/pkg/generic/service_client.go +++ b/external-providers/generic-external-provider/pkg/generic/service_client.go @@ -30,7 +30,7 @@ func (p *genericServiceClient) Stop() { p.cancelFunc() p.cmd.Wait() } -func (p *genericServiceClient) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { +func (p *genericServiceClient) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { var cond genericCondition err := yaml.Unmarshal(conditionInfo, &cond) if err != nil { @@ -41,11 +41,11 @@ func (p *genericServiceClient) Evaluate(cap string, conditionInfo []byte) (provi return provider.ProviderEvaluateResponse{}, fmt.Errorf("unable to get query info") } - symbols := p.GetAllSymbols(query) + symbols := p.GetAllSymbols(ctx, query) incidents := []provider.IncidentContext{} for _, s := range symbols { - references := p.GetAllReferences(s) + references := p.GetAllReferences(ctx, s) for _, ref := range references { // Look for things that are in the location loaded, //Note may need to filter out vendor at some point if strings.Contains(ref.URI, p.config.Location) { @@ -74,7 +74,7 @@ func (p *genericServiceClient) Evaluate(cap string, conditionInfo []byte) (provi }, nil } -func (p *genericServiceClient) GetAllSymbols(query string) []protocol.WorkspaceSymbol { +func (p *genericServiceClient) GetAllSymbols(ctx context.Context, query string) []protocol.WorkspaceSymbol { wsp := &protocol.WorkspaceSymbolParams{ Query: query, @@ -82,7 +82,7 @@ func (p *genericServiceClient) GetAllSymbols(query string) []protocol.WorkspaceS var refs []protocol.WorkspaceSymbol fmt.Printf("\nrpc call\n") - err := p.rpc.Call(context.TODO(), "workspace/symbol", wsp, &refs) + err := p.rpc.Call(ctx, "workspace/symbol", wsp, &refs) fmt.Printf("\nrpc called\n") if err != nil { fmt.Printf("\n\nerror: %v\n", err) @@ -91,7 +91,7 @@ func (p *genericServiceClient) GetAllSymbols(query string) []protocol.WorkspaceS return refs } -func (p *genericServiceClient) GetAllReferences(symbol protocol.WorkspaceSymbol) []protocol.Location { +func (p *genericServiceClient) GetAllReferences(ctx context.Context, symbol protocol.WorkspaceSymbol) []protocol.Location { params := &protocol.ReferenceParams{ TextDocumentPositionParams: protocol.TextDocumentPositionParams{ TextDocument: protocol.TextDocumentIdentifier{ @@ -102,7 +102,7 @@ func (p *genericServiceClient) GetAllReferences(symbol protocol.WorkspaceSymbol) } res := []protocol.Location{} - err := p.rpc.Call(p.ctx, "textDocument/references", params, &res) + err := p.rpc.Call(ctx, "textDocument/references", params, &res) if err != nil { fmt.Printf("Error rpc: %v", err) } diff --git a/parser/rule_parser_test.go b/parser/rule_parser_test.go index b9d58fcd..08337aa8 100644 --- a/parser/rule_parser_test.go +++ b/parser/rule_parser_test.go @@ -28,15 +28,15 @@ func (t testProvider) Init(ctx context.Context, log logr.Logger, config provider return nil, nil } -func (t testProvider) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { +func (t testProvider) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { return provider.ProviderEvaluateResponse{}, nil } -func (t testProvider) GetDependencies() (map[uri.URI][]*provider.Dep, error) { +func (t testProvider) GetDependencies(ctx context.Context) (map[uri.URI][]*provider.Dep, error) { return nil, nil } -func (t testProvider) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { +func (t testProvider) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) { return nil, nil } diff --git a/provider/grpc/provider.go b/provider/grpc/provider.go index eaf4db8d..e2c96483 100644 --- a/provider/grpc/provider.go +++ b/provider/grpc/provider.go @@ -41,7 +41,6 @@ func NewGRPCClient(config provider.Config, log logr.Logger) *grpcProvider { } func (g *grpcProvider) ProviderInit(ctx context.Context) error { - g.ctx = ctx for _, c := range g.config.InitConfig { s, err := g.Init(ctx, g.log, c) if err != nil { @@ -99,22 +98,21 @@ func (g *grpcProvider) Init(ctx context.Context, log logr.Logger, config provide } return &grpcServiceClient{ id: r.Id, - ctx: ctx, config: config, client: g.Client, }, nil } -func (g *grpcProvider) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { - return provider.FullResponseFromServiceClients(g.serviceClients, cap, conditionInfo) +func (g *grpcProvider) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { + return provider.FullResponseFromServiceClients(ctx, g.serviceClients, cap, conditionInfo) } -func (g *grpcProvider) GetDependencies() (map[uri.URI][]*provider.Dep, error) { - return provider.FullDepsResponse(g.serviceClients) +func (g *grpcProvider) GetDependencies(ctx context.Context) (map[uri.URI][]*provider.Dep, error) { + return provider.FullDepsResponse(ctx, g.serviceClients) } -func (g *grpcProvider) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { - return provider.FullDepDAGResponse(g.serviceClients) +func (g *grpcProvider) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) { + return provider.FullDepDAGResponse(ctx, g.serviceClients) } func (g *grpcProvider) Stop() { diff --git a/provider/grpc/service_client.go b/provider/grpc/service_client.go index 584f5815..f2bcd087 100644 --- a/provider/grpc/service_client.go +++ b/provider/grpc/service_client.go @@ -11,20 +11,19 @@ import ( type grpcServiceClient struct { id int64 - ctx context.Context config provider.InitConfig client pb.ProviderServiceClient } var _ provider.ServiceClient = &grpcServiceClient{} -func (g *grpcServiceClient) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { +func (g *grpcServiceClient) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { m := pb.EvaluateRequest{ Cap: cap, ConditionInfo: string(conditionInfo), Id: g.id, } - r, err := g.client.Evaluate(g.ctx, &m) + r, err := g.client.Evaluate(ctx, &m) if err != nil { return provider.ProviderEvaluateResponse{}, err } @@ -85,8 +84,8 @@ func (g *grpcServiceClient) Evaluate(cap string, conditionInfo []byte) (provider } // We don't have dependencies -func (g *grpcServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, error) { - d, err := g.client.GetDependencies(g.ctx, &pb.ServiceRequest{Id: g.id}) +func (g *grpcServiceClient) GetDependencies(ctx context.Context) (map[uri.URI][]*provider.Dep, error) { + d, err := g.client.GetDependencies(ctx, &pb.ServiceRequest{Id: g.id}) if err != nil { return nil, err } @@ -140,8 +139,8 @@ func recreateDAGAddedItems(items []*pb.DependencyDAGItem) []provider.DepDAGItem } // We don't have dependencies -func (g *grpcServiceClient) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { - d, err := g.client.GetDependenciesDAG(g.ctx, &pb.ServiceRequest{Id: g.id}) +func (g *grpcServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) { + d, err := g.client.GetDependenciesDAG(ctx, &pb.ServiceRequest{Id: g.id}) if err != nil { return nil, err } diff --git a/provider/internal/builtin/provider.go b/provider/internal/builtin/provider.go index 3f243299..dd9d88f7 100644 --- a/provider/internal/builtin/provider.go +++ b/provider/internal/builtin/provider.go @@ -103,14 +103,14 @@ func (p *builtinProvider) Capabilities() []provider.Capability { return capabilities } -func (p *builtinProvider) ProviderInit(context.Context) error { +func (p *builtinProvider) ProviderInit(ctx context.Context) error { // First load all the tags for all init configs. for _, c := range p.config.InitConfig { p.loadTags(c) } for _, c := range p.config.InitConfig { - client, err := p.Init(p.ctx, p.log, c) + client, err := p.Init(ctx, p.log, c) if err != nil { return nil } @@ -124,7 +124,7 @@ func (p *builtinProvider) Init(ctx context.Context, log logr.Logger, config prov if config.AnalysisMode != provider.AnalysisMode("") { p.log.V(5).Info("skipping analysis mode setting for builtin") } - return &builtintServiceClient{ + return &builtinServiceClient{ config: config, tags: p.tags, UnimplementedDependenciesComponent: provider.UnimplementedDependenciesComponent{}, @@ -157,8 +157,8 @@ func (p *builtinProvider) loadTags(config provider.InitConfig) error { return nil } -func (p *builtinProvider) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { - return provider.FullResponseFromServiceClients(p.clients, cap, conditionInfo) +func (p *builtinProvider) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { + return provider.FullResponseFromServiceClients(ctx, p.clients, cap, conditionInfo) } func (p *builtinProvider) Stop() { diff --git a/provider/internal/builtin/service_client.go b/provider/internal/builtin/service_client.go index f7a8a3d4..1ee31dce 100644 --- a/provider/internal/builtin/service_client.go +++ b/provider/internal/builtin/service_client.go @@ -1,6 +1,7 @@ package builtin import ( + "context" "fmt" "io/fs" "os" @@ -18,19 +19,19 @@ import ( "gopkg.in/yaml.v2" ) -type builtintServiceClient struct { +type builtinServiceClient struct { config provider.InitConfig tags map[string]bool provider.UnimplementedDependenciesComponent } -var _ provider.ServiceClient = &builtintServiceClient{} +var _ provider.ServiceClient = &builtinServiceClient{} -func (p *builtintServiceClient) Stop() { +func (p *builtinServiceClient) Stop() { return } -func (p *builtintServiceClient) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { +func (p *builtinServiceClient) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { var cond builtinCondition err := yaml.Unmarshal(conditionInfo, &cond) if err != nil { diff --git a/provider/internal/java/dependency.go b/provider/internal/java/dependency.go index 40563a3c..b9f3d5ec 100644 --- a/provider/internal/java/dependency.go +++ b/provider/internal/java/dependency.go @@ -3,6 +3,7 @@ package java import ( "bufio" "bytes" + "context" "fmt" "io" "io/fs" @@ -42,7 +43,7 @@ func (p *javaServiceClient) findPom() string { return f } -func (p *javaServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, error) { +func (p *javaServiceClient) GetDependencies(ctx context.Context) (map[uri.URI][]*provider.Dep, error) { if p.depsCache != nil { return p.depsCache, nil } @@ -54,12 +55,12 @@ func (p *javaServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, erro // for binaries we only find JARs embedded in archive p.discoverDepsFromJars(p.config.DependencyPath, ll) } else { - ll, err = p.GetDependenciesDAG() + ll, err = p.GetDependenciesDAG(ctx) if err != nil { - return p.GetDependencyFallback() + return p.GetDependencyFallback(ctx) } if len(ll) == 0 { - return p.GetDependencyFallback() + return p.GetDependencyFallback(ctx) } } for f, ds := range ll { @@ -94,7 +95,7 @@ func (p *javaServiceClient) getLocalRepoPath() string { return string(outb.String()) } -func (p *javaServiceClient) GetDependencyFallback() (map[uri.URI][]*provider.Dep, error) { +func (p *javaServiceClient) GetDependencyFallback(ctx context.Context) (map[uri.URI][]*provider.Dep, error) { pomDependencyQuery := "//dependencies/dependency/*" path := p.findPom() file := uri.File(path) @@ -143,7 +144,7 @@ func (p *javaServiceClient) GetDependencyFallback() (map[uri.URI][]*provider.Dep return m, nil } -func (p *javaServiceClient) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { +func (p *javaServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) { localRepoPath := p.getLocalRepoPath() path := p.findPom() diff --git a/provider/internal/java/filter.go b/provider/internal/java/filter.go index 76dc135f..771f4f66 100644 --- a/provider/internal/java/filter.go +++ b/provider/internal/java/filter.go @@ -1,6 +1,7 @@ package java import ( + "context" "strings" "github.com/konveyor/analyzer-lsp/lsp/protocol" @@ -55,10 +56,10 @@ func (p *javaServiceClient) filterTypesInheritance(symbols []protocol.WorkspaceS return incidents, nil } -func (p *javaServiceClient) filterTypeReferences(symbols []protocol.WorkspaceSymbol) ([]provider.IncidentContext, error) { +func (p *javaServiceClient) filterTypeReferences(ctx context.Context, symbols []protocol.WorkspaceSymbol) ([]provider.IncidentContext, error) { incidents := []provider.IncidentContext{} for _, symbol := range symbols { - references := p.GetAllReferences(symbol) + references := p.GetAllReferences(ctx, symbol) for _, ref := range references { incident, err := p.convertSymbolRefToIncidentContext(symbol, ref) @@ -100,11 +101,11 @@ func (p *javaServiceClient) filterMethodSymbols(symbols []protocol.WorkspaceSymb } -func (p *javaServiceClient) filterConstructorSymbols(symbols []protocol.WorkspaceSymbol) ([]provider.IncidentContext, error) { +func (p *javaServiceClient) filterConstructorSymbols(ctx context.Context, symbols []protocol.WorkspaceSymbol) ([]provider.IncidentContext, error) { incidents := []provider.IncidentContext{} for _, symbol := range symbols { - references := p.GetAllReferences(symbol) + references := p.GetAllReferences(ctx, symbol) for _, ref := range references { incident, err := p.convertSymbolRefToIncidentContext(symbol, ref) if err != nil { diff --git a/provider/internal/java/provider.go b/provider/internal/java/provider.go index c2d585f4..6b9623aa 100644 --- a/provider/internal/java/provider.go +++ b/provider/internal/java/provider.go @@ -103,8 +103,8 @@ func (p *javaProvider) Capabilities() []provider.Capability { return caps } -func (p *javaProvider) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { - return provider.FullResponseFromServiceClients(p.clients, cap, conditionInfo) +func (p *javaProvider) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { + return provider.FullResponseFromServiceClients(ctx, p.clients, cap, conditionInfo) } func symbolKindToString(symbolKind protocol.SymbolKind) string { @@ -278,7 +278,6 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide svcClient := javaServiceClient{ rpc: rpc, - ctx: ctx, cancelFunc: cancelFunc, config: config, cmd: cmd, @@ -290,7 +289,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide mvnSettingsFile: mavenSettingsFile, } - svcClient.initialization() + svcClient.initialization(ctx) err = svcClient.depInit() if err != nil { return nil, err @@ -298,10 +297,10 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide return &svcClient, returnErr } -func (p *javaProvider) GetDependencies() (map[uri.URI][]*provider.Dep, error) { - return provider.FullDepsResponse(p.clients) +func (p *javaProvider) GetDependencies(ctx context.Context) (map[uri.URI][]*provider.Dep, error) { + return provider.FullDepsResponse(ctx, p.clients) } -func (p *javaProvider) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { - return provider.FullDepDAGResponse(p.clients) +func (p *javaProvider) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) { + return provider.FullDepDAGResponse(ctx, p.clients) } diff --git a/provider/internal/java/service_client.go b/provider/internal/java/service_client.go index 092a30ec..15045196 100644 --- a/provider/internal/java/service_client.go +++ b/provider/internal/java/service_client.go @@ -38,7 +38,7 @@ type depLabelItem struct { var _ provider.ServiceClient = &javaServiceClient{} -func (p *javaServiceClient) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { +func (p *javaServiceClient) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { cond := &javaCondition{} err := yaml.Unmarshal(conditionInfo, &cond) if err != nil { @@ -49,7 +49,7 @@ func (p *javaServiceClient) Evaluate(cap string, conditionInfo []byte) (provider return provider.ProviderEvaluateResponse{}, fmt.Errorf("provided query pattern empty") } - symbols := p.GetAllSymbols(cond.Referenced.Pattern, cond.Referenced.Location) + symbols := p.GetAllSymbols(ctx, cond.Referenced.Pattern, cond.Referenced.Location) incidents := []provider.IncidentContext{} switch locationToCode[strings.ToLower(cond.Referenced.Location)] { @@ -61,7 +61,7 @@ func (p *javaServiceClient) Evaluate(cap string, conditionInfo []byte) (provider case 2: incidents, err = p.filterMethodSymbols(symbols) case 3: - incidents, err = p.filterConstructorSymbols(symbols) + incidents, err = p.filterConstructorSymbols(ctx, symbols) case 4: incidents, err = p.filterDefault(symbols) case 7: @@ -71,7 +71,7 @@ func (p *javaServiceClient) Evaluate(cap string, conditionInfo []byte) (provider case 9: incidents, err = p.filterVariableDeclaration(symbols) case 10: - incidents, err = p.filterTypeReferences(symbols) + incidents, err = p.filterTypeReferences(ctx, symbols) case 11: incidents, err = p.filterDefault(symbols) default: @@ -94,7 +94,7 @@ func (p *javaServiceClient) Evaluate(cap string, conditionInfo []byte) (provider }, nil } -func (p *javaServiceClient) GetAllSymbols(query, location string) []protocol.WorkspaceSymbol { +func (p *javaServiceClient) GetAllSymbols(ctx context.Context, query, location string) []protocol.WorkspaceSymbol { // This command will run the added bundle to the language server. The command over the wire needs too look like this. // in this case the project is hardcoded in the init of the Langauge Server above // workspace/executeCommand '{"command": "io.konveyor.tackle.ruleEntry", "arguments": {"query":"*customresourcedefinition","project": "java"}}' @@ -111,7 +111,7 @@ func (p *javaServiceClient) GetAllSymbols(query, location string) []protocol.Wor } var refs []protocol.WorkspaceSymbol - err := p.rpc.Call(p.ctx, "workspace/executeCommand", wsp, &refs) + err := p.rpc.Call(ctx, "workspace/executeCommand", wsp, &refs) if err != nil { p.log.Error(err, "unable to ask for tackle rule entry") } @@ -119,7 +119,7 @@ func (p *javaServiceClient) GetAllSymbols(query, location string) []protocol.Wor return refs } -func (p *javaServiceClient) GetAllReferences(symbol protocol.WorkspaceSymbol) []protocol.Location { +func (p *javaServiceClient) GetAllReferences(ctx context.Context, symbol protocol.WorkspaceSymbol) []protocol.Location { if strings.Contains(symbol.Location.URI, FILE_URI_PREFIX) { return []protocol.Location{ { @@ -138,7 +138,7 @@ func (p *javaServiceClient) GetAllReferences(symbol protocol.WorkspaceSymbol) [] } res := []protocol.Location{} - err := p.rpc.Call(p.ctx, "textDocument/references", params, &res) + err := p.rpc.Call(ctx, "textDocument/references", params, &res) if err != nil { fmt.Printf("Error rpc: %v", err) } @@ -150,7 +150,7 @@ func (p *javaServiceClient) Stop() { p.cmd.Wait() } -func (p *javaServiceClient) initialization() { +func (p *javaServiceClient) initialization(ctx context.Context) { absLocation, err := filepath.Abs(p.config.Location) if err != nil { p.log.Error(err, "unable to get path to analyize") @@ -199,13 +199,13 @@ func (p *javaServiceClient) initialization() { var result protocol.InitializeResult for i := 0; i < 10; i++ { - if err := p.rpc.Call(p.ctx, "initialize", params, &result); err != nil { + if err := p.rpc.Call(ctx, "initialize", params, &result); err != nil { p.log.Error(err, "initialize failed") continue } break } - if err := p.rpc.Notify(p.ctx, "initialized", &protocol.InitializedParams{}); err != nil { + if err := p.rpc.Notify(ctx, "initialized", &protocol.InitializedParams{}); err != nil { fmt.Printf("initialized failed: %v", err) p.log.Error(err, "initialize failed") } diff --git a/provider/internal/java/util.go b/provider/internal/java/util.go index b947161e..e6fea506 100644 --- a/provider/internal/java/util.go +++ b/provider/internal/java/util.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/go-logr/logr" + "github.com/konveyor/analyzer-lsp/tracing" ) const javaProjectPom = ` @@ -41,6 +42,9 @@ const javaProjectPom = ` // creates new java project and puts the java files in the tree of the project // returns path to exploded archive, path to java project, and an error when encountered func decompileJava(ctx context.Context, log logr.Logger, archivePath string) (explodedPath, projectPath string, err error) { + ctx, span := tracing.StartNewSpan(ctx, "decompile") + defer span.End() + projectPath = filepath.Join(filepath.Dir(archivePath), "java-project") err = createJavaProject(ctx, projectPath) diff --git a/provider/provider.go b/provider/provider.go index de8d7e70..0d3ec6b6 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -53,12 +53,12 @@ func init() { type UnimplementedDependenciesComponent struct{} // We don't have dependencies -func (p *UnimplementedDependenciesComponent) GetDependencies() (map[uri.URI][]*Dep, error) { +func (p *UnimplementedDependenciesComponent) GetDependencies(ctx context.Context) (map[uri.URI][]*Dep, error) { return nil, nil } // We don't have dependencies -func (p *UnimplementedDependenciesComponent) GetDependenciesDAG() (map[uri.URI][]DepDAGItem, error) { +func (p *UnimplementedDependenciesComponent) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]DepDAGItem, error) { return nil, nil } @@ -236,14 +236,14 @@ func HasCapability(caps []Capability, name string) bool { return false } -func FullResponseFromServiceClients(clients []ServiceClient, cap string, conditionInfo []byte) (ProviderEvaluateResponse, error) { +func FullResponseFromServiceClients(ctx context.Context, clients []ServiceClient, cap string, conditionInfo []byte) (ProviderEvaluateResponse, error) { fullResp := ProviderEvaluateResponse{ Matched: false, Incidents: []IncidentContext{}, TemplateContext: map[string]interface{}{}, } for _, c := range clients { - r, err := c.Evaluate(cap, conditionInfo) + r, err := c.Evaluate(ctx, cap, conditionInfo) if err != nil { return fullResp, err } @@ -258,10 +258,10 @@ func FullResponseFromServiceClients(clients []ServiceClient, cap string, conditi return fullResp, nil } -func FullDepsResponse(clients []ServiceClient) (map[uri.URI][]*Dep, error) { +func FullDepsResponse(ctx context.Context, clients []ServiceClient) (map[uri.URI][]*Dep, error) { deps := map[uri.URI][]*Dep{} for _, c := range clients { - r, err := c.GetDependencies() + r, err := c.GetDependencies(ctx) if err != nil { return nil, err } @@ -273,10 +273,10 @@ func FullDepsResponse(clients []ServiceClient) (map[uri.URI][]*Dep, error) { return deps, nil } -func FullDepDAGResponse(clients []ServiceClient) (map[uri.URI][]DepDAGItem, error) { +func FullDepDAGResponse(ctx context.Context, clients []ServiceClient) (map[uri.URI][]DepDAGItem, error) { deps := map[uri.URI][]DepDAGItem{} for _, c := range clients { - r, err := c.GetDependenciesDAG() + r, err := c.GetDependenciesDAG(ctx) if err != nil { return nil, err } @@ -310,16 +310,16 @@ type BaseClient interface { // For some period of time during POC this will be in tree, in the future we need to write something that can do this w/ external binaries type ServiceClient interface { - Evaluate(cap string, conditionInfo []byte) (ProviderEvaluateResponse, error) + Evaluate(ctx context.Context, cap string, conditionInfo []byte) (ProviderEvaluateResponse, error) Stop() // GetDependencies will get the dependencies // It is the responsibility of the provider to determine how that is done - GetDependencies() (map[uri.URI][]*Dep, error) + GetDependencies(ctx context.Context) (map[uri.URI][]*Dep, error) // GetDependencies will get the dependencies and return them as a linked list // Top level items are direct dependencies, the rest are indirect dependencies - GetDependenciesDAG() (map[uri.URI][]DepDAGItem, error) + GetDependenciesDAG(ctx context.Context) (map[uri.URI][]DepDAGItem, error) } type Dep = konveyor.Dep @@ -357,8 +357,8 @@ func (p ProviderCondition) Ignorable() bool { return p.Ignore } -func (p ProviderCondition) Evaluate(ctx context.Context, log logr.Logger, condCtx engine.ConditionContext) (engine.ConditionResponse, error) { - _, span := tracing.StartNewSpan( +func (p *ProviderCondition) Evaluate(ctx context.Context, log logr.Logger, condCtx engine.ConditionContext) (engine.ConditionResponse, error) { + ctx, span := tracing.StartNewSpan( ctx, "provider-condition", attribute.Key("cap").String(p.Capability)) defer span.End() @@ -386,7 +386,7 @@ func (p ProviderCondition) Evaluate(ctx context.Context, log logr.Logger, condCt panic(err) } span.SetAttributes(attribute.Key("condition").String(string(templatedInfo))) - resp, err := p.Client.Evaluate(p.Capability, templatedInfo) + resp, err := p.Client.Evaluate(ctx, p.Capability, templatedInfo) if err != nil { // If an error always just return the empty return engine.ConditionResponse{}, err @@ -394,7 +394,7 @@ func (p ProviderCondition) Evaluate(ctx context.Context, log logr.Logger, condCt var deps map[uri.URI][]*Dep if p.DepLabelSelector != nil { - deps, err = p.Client.GetDependencies() + deps, err = p.Client.GetDependencies(ctx) if err != nil { return engine.ConditionResponse{}, err } @@ -517,8 +517,11 @@ type DependencyCondition struct { } func (dc DependencyCondition) Evaluate(ctx context.Context, log logr.Logger, condCtx engine.ConditionContext) (engine.ConditionResponse, error) { + _, span := tracing.StartNewSpan(ctx, "dep-condition") + defer span.End() + resp := engine.ConditionResponse{} - deps, err := dc.Client.GetDependencies() + deps, err := dc.Client.GetDependencies(ctx) if err != nil { return resp, err } diff --git a/provider/provider_test.go b/provider/provider_test.go index c02ff56c..426a9d16 100644 --- a/provider/provider_test.go +++ b/provider/provider_test.go @@ -20,7 +20,7 @@ type fakeClient struct { func (c *fakeClient) Capabilities() []Capability { return nil } func (c *fakeClient) HasCapability(string) bool { return true } -func (c *fakeClient) Evaluate(string, []byte) (ProviderEvaluateResponse, error) { +func (c *fakeClient) Evaluate(context.Context, string, []byte) (ProviderEvaluateResponse, error) { return ProviderEvaluateResponse{}, nil } func (c *fakeClient) Init(context.Context, logr.Logger, InitConfig) (ServiceClient, error) { @@ -28,14 +28,14 @@ func (c *fakeClient) Init(context.Context, logr.Logger, InitConfig) (ServiceClie } func (c *fakeClient) Stop() {} -func (c *fakeClient) GetDependencies() (map[uri.URI][]*Dep, error) { +func (c *fakeClient) GetDependencies(ctx context.Context) (map[uri.URI][]*Dep, error) { m := map[uri.URI][]*Dep{ uri.URI("test"): c.dependencies, } return m, nil } -func (c *fakeClient) GetDependenciesDAG() (map[uri.URI][]DepDAGItem, error) { +func (c *fakeClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]DepDAGItem, error) { return nil, nil } diff --git a/provider/server.go b/provider/server.go index 6a250ee1..7c3071be 100644 --- a/provider/server.go +++ b/provider/server.go @@ -139,7 +139,7 @@ func (s *server) Evaluate(ctx context.Context, req *libgrpc.EvaluateRequest) (*l client := s.clients[req.Id] s.mutex.RUnlock() - r, err := client.client.Evaluate(req.Cap, []byte(req.ConditionInfo)) + r, err := client.client.Evaluate(ctx, req.Cap, []byte(req.ConditionInfo)) if err != nil { return &libgrpc.EvaluateResponse{ @@ -229,7 +229,7 @@ func (s *server) GetDependencies(ctx context.Context, in *libgrpc.ServiceRequest s.mutex.RLock() client := s.clients[in.Id] s.mutex.RUnlock() - deps, err := client.client.GetDependencies() + deps, err := client.client.GetDependencies(ctx) if err != nil { return &libgrpc.DependencyResponse{ Successful: false, @@ -297,7 +297,7 @@ func (s *server) GetDependenciesLinkedList(ctx context.Context, in *libgrpc.Serv s.mutex.RLock() client := s.clients[in.Id] s.mutex.RUnlock() - deps, err := client.client.GetDependenciesDAG() + deps, err := client.client.GetDependenciesDAG(ctx) if err != nil { return &libgrpc.DependencyDAGResponse{ Successful: false,