Skip to content

Commit

Permalink
👻 update doc, demo output
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed Aug 24, 2023
1 parent 0650ecc commit daca080
Show file tree
Hide file tree
Showing 9 changed files with 157 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
35 changes: 24 additions & 11 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 @@ -87,6 +96,7 @@ func main() {

var depsFlat []konveyor.DepsFlatItem
var depsTree []konveyor.DepsTreeItem
var provErr error
for name, prov := range providers {
if !provider.HasCapability(prov.Capabilities(), "dependency") {
log.Info("provider does not have dependency capability", "provider", name)
Expand All @@ -97,6 +107,7 @@ func main() {
deps, err := prov.GetDependenciesDAG()
if err != nil {
log.Error(err, "failed to get list of dependencies for provider", "provider", name)
provErr = fmt.Errorf("%w", provErr)
continue
}
for u, ds := range deps {
Expand All @@ -110,18 +121,17 @@ func main() {
deps, err := prov.GetDependencies()
if err != nil {
log.Error(err, "failed to get list of dependencies for provider", "provider", name)
provErr = fmt.Errorf("%w", provErr)
continue
}
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")
provErr = fmt.Errorf("%w", provErr)
continue
}
}
depsFlat = append(depsFlat, konveyor.DepsFlatItem{
Expand All @@ -133,8 +143,13 @@ func main() {
}
}

if depsFlat == nil && depsTree == nil {
log.Info("failed to get dependencies from all given providers")
// stop providers before exiting
for _, prov := range providers {
prov.Stop()
}

if provErr != nil {
log.Error(provErr, "failed running dependency analysis")
os.Exit(1)
}

Expand Down Expand Up @@ -162,8 +177,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 daca080

Please sign in to comment.