Skip to content

Commit

Permalink
✨ use default maven index, stop providers before exiting in dependenc…
Browse files Browse the repository at this point in the history
…y cli (#286)

Closes #300 

- Uses default maven index in the image to classify open-source deps
- Improves dependency CLI a little by stopping the providers and
removing unnecessy output to stdout
- Disables Jaeger by default, as it requires users to run it via
entrypoint command when running outside CI test

---------

Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad authored Aug 30, 2023
1 parent 40129ff commit e1dd9f9
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 105 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ WORKDIR /analyzer-lsp

EXPOSE 16686

ENTRYPOINT ["sh", "-c", "all-in-one-linux & sleep 5 && konveyor-analyzer"]
ENTRYPOINT ["sh", "-c", "all-in-one-linux &> /dev/null & sleep 5 && konveyor-analyzer"]
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ go run cmd/analyzer/main.go
CLI Options:

```sh
--analysis-mode string Can be full or source-only to tell the providers what to analyze. If full, source code and all dependencies will be analyzed, if source-only, only the source code will be. This can be given on a per provider basis, but this flag will override those.
--provider-settings string path to the provider settings (default "provider_settings.json")
--rules stringArray filename or directory containing rule files (default [rule-example.yaml])
--output-file string filepath to to store rule violations (default "output.yaml")
--label-selector string an expression to select rules based on labels
--enable-jaeger enable tracer exports to jaeger endpoint
--error-on-violation exit with 3 if any violation are found will also print violations to console
--jaeger-endpoint string jaeger endpoint to collect tracing data (default "http://localhost:14268/api/traces")
--no-dependency-rules Disable dependency analysis rules
--limit-incidents int Set this to the limit incidents that a given rule can give. zero means no limit (default 1500)
--limit-code-snips int limit the number code snippets that are retrieved for a file while evaluating a rule, 0 means no limit (default 20)
--verbose int level for logging output (default 9)
Flags:
--analysis-mode string select one of full or source-only to tell the providers what to analyize. This can be given on a per provider setting, but this flag will override
--context-lines int When violation occurs, A part of source code is added to the output, So this flag configures the number of source code lines to be printed to the output. (default 10)
--dep-label-selector string an expression to select dependencies based on labels. This will filter out the violations from these dependencies as well these dependencies when matching dependency conditions
--enable-jaeger enable tracer exports to jaeger endpoint (default true)
--error-on-violation exit with 3 if any violation are found will also print violations to console
-h, --help help for analyze
--jaeger-endpoint string jaeger endpoint to collect tracing data (default "http://localhost:14268/api/traces")
--label-selector string an expression to select rules based on labels
--limit-code-snips int limit the number code snippets that are retrieved for a file while evaluating a rule, 0 means no limit (default 20)
--limit-incidents int Set this to the limit incidents that a given rule can give, zero means no limit (default 1500)
--no-dependency-rules Disable dependency analysis rules
--output-file string filepath to to store rule violations (default "output.yaml")
--provider-settings string path to the provider settings (default "provider_settings.json")
--rules stringArray filename or directory containing rule files (default [rule-example.yaml])
--verbose int level for logging output (default 9)
```
* See [label selector](./docs/labels.md#label-selector) for more info on `--label-selector` option.
Expand Down
2 changes: 1 addition & 1 deletion cmd/analyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func init() {
rootCmd.Flags().StringVar(&labelSelector, "label-selector", "", "an expression to select rules based on labels")
rootCmd.Flags().StringVar(&depLabelSelector, "dep-label-selector", "", "an expression to select dependencies based on labels. This will filter out the violations from these dependencies as well these dependencies when matching dependency conditions")
rootCmd.Flags().IntVar(&logLevel, "verbose", 9, "level for logging output")
rootCmd.Flags().BoolVar(&enableJaeger, "enable-jaeger", true, "enable tracer exports to jaeger endpoint")
rootCmd.Flags().BoolVar(&enableJaeger, "enable-jaeger", false, "enable tracer exports to jaeger endpoint")
rootCmd.Flags().StringVar(&jaegerEndpoint, "jaeger-endpoint", "http://localhost:14268/api/traces", "jaeger endpoint to collect tracing data")
rootCmd.Flags().IntVar(&limitIncidents, "limit-incidents", 1500, "Set this to the limit incidents that a given rule can give, zero means no limit")
rootCmd.Flags().IntVar(&limitCodeSnips, "limit-code-snips", 20, "limit the number code snippets that are retrieved for a file while evaluating a rule, 0 means no limit")
Expand Down
27 changes: 18 additions & 9 deletions cmd/dep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func main() {
os.Exit(1)
}

var labelSelector *labels.LabelSelector[*konveyor.Dep]
if depLabelSelector != "" {
labelSelector, err = labels.NewLabelSelector[*konveyor.Dep](depLabelSelector)
if err != nil {
log.Error(err, "invalid label selector")
os.Exit(1)
}
}

ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()

Expand Down Expand Up @@ -114,14 +123,11 @@ func main() {
}
for u, ds := range deps {
newDeps := ds
if depLabelSelector != "" {
l, err := labels.NewLabelSelector[*konveyor.Dep](depLabelSelector)
if labelSelector != nil {
newDeps, err = labelSelector.MatchList(ds)
if err != nil {
panic(err)
}
newDeps, err = l.MatchList(ds)
if err != nil {
panic(err)
log.Error(err, "error matching label selector on deps")
continue
}
}
depsFlat = append(depsFlat, konveyor.DepsFlatItem{
Expand All @@ -133,6 +139,11 @@ func main() {
}
}

// stop providers before exiting
for _, prov := range providers {
prov.Stop()
}

if depsFlat == nil && depsTree == nil {
log.Info("failed to get dependencies from all given providers")
os.Exit(1)
Expand Down Expand Up @@ -162,8 +173,6 @@ func main() {
}
}

fmt.Printf("%s", string(b))

err = os.WriteFile(outputFile, b, 0644)
if err != nil {
log.Error(err, "failed to write dependencies to output file", "file", outputFile)
Expand Down
Loading

0 comments on commit e1dd9f9

Please sign in to comment.