Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Share maven cache between analyze and dep, use JVM max setting #105

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
)

var (
// TODO (pgaikwad): this assumes that the $USER in container is always root, it may not be the case in future
M2Dir = path.Join("/", "root", ".m2")
// application source path inside the container
SourceMountPath = path.Join(InputPath, "source")
// analyzer config files
Expand Down Expand Up @@ -55,6 +57,7 @@ type analyzeCommand struct {
output string
mode string
rules []string
jaegerEndpoint string

// tempDirs list of temporary dirs created, used for cleanup
tempDirs []string
Expand Down Expand Up @@ -151,6 +154,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
analyzeCommand.Flags().StringVar(&analyzeCmd.mavenSettingsFile, "maven-settings", "", "path to a custom maven settings file to use")
analyzeCommand.Flags().StringVarP(&analyzeCmd.mode, "mode", "m", string(provider.FullAnalysisMode), "analysis mode. Must be one of 'full' or 'source-only'")
analyzeCommand.Flags().BoolVar(&analyzeCmd.jsonOutput, "json-output", false, "create analysis and dependency output as json")
analyzeCommand.Flags().StringVar(&analyzeCmd.jaegerEndpoint, "jaeger-endpoint", "", "jaeger endpoint to collect traces")

return analyzeCommand
}
Expand Down Expand Up @@ -334,6 +338,8 @@ func listOptionsFromLabels(sl []string, label string) {
fmt.Println("available target technologies:")
}
for _, tech := range newSl {
tech = strings.TrimSuffix(tech, "+")
tech = strings.TrimSuffix(tech, "-")
fmt.Println(tech)
}
}
Expand Down Expand Up @@ -378,6 +384,9 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
}
javaConfig.InitConfig[0].ProviderSpecificConfig["mavenSettingsFile"] = fmt.Sprintf("%s/%s", ConfigMountPath, "settings.xml")
}
if Settings.JvmMaxMem != "" {
javaConfig.InitConfig[0].ProviderSpecificConfig["jvmMaxMem"] = Settings.JvmMaxMem
}

provConfig := []provider.Config{
{
Expand Down Expand Up @@ -413,12 +422,26 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
}
err = os.WriteFile(filepath.Join(tempDir, "settings.json"), jsonData, os.ModePerm)
if err != nil {
a.log.V(1).Error(err, "failed to write provider config", "dir", tempDir, "file", "settings.json")
a.log.V(1).Error(err,
"failed to write provider config", "dir", tempDir, "file", "settings.json")
return nil, err
}
return map[string]string{

vols := map[string]string{
tempDir: ConfigMountPath,
}, nil
}
// attempt to create a .m2 directory we can use to speed things a bit
// this will be shared between analyze and dep command containers
m2Dir, err := os.MkdirTemp("", "m2-repo-")
if err != nil {
a.log.V(1).Error(err, "failed to create m2 repo", "dir", m2Dir)
} else {
vols[m2Dir] = M2Dir
a.log.V(1).Info("created directory for maven repo", "dir", m2Dir)
a.tempDirs = append(a.tempDirs, m2Dir)
}

return vols, nil
}

func (a *analyzeCommand) getRulesVolumes() (map[string]string, error) {
Expand Down Expand Up @@ -541,6 +564,11 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e
fmt.Sprintf("--output-file=%s", AnalysisOutputMountPath),
fmt.Sprintf("--context-lines=%d", 100),
}
if a.jaegerEndpoint != "" {
args = append(args, "--enable-jaeger")
args = append(args, "--jaeger-endpoint")
args = append(args, a.jaegerEndpoint)
}
if !a.analyzeKnownLibraries {
args = append(args,
fmt.Sprintf("--dep-label-selector=(!%s=open-source)", provider.DepSourceLabel))
Expand Down
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var noCleanup bool

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
// TODO: better descriptions
Short: "A cli tool for analysis and transformation of applications",
Long: ``,
SilenceUsage: true,
Expand Down
1 change: 1 addition & 0 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {
RootCommandName string `env:"CMD_NAME" default:"kantra"`
PodmanBinary string `env:"PODMAN_BIN" default:"/usr/bin/podman"`
RunnerImage string `env:"RUNNER_IMG" default:"quay.io/konveyor/kantra"`
JvmMaxMem string `env:"JVM_MAX_MEM" default:""`
}

func (c *Config) Load() error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/bombsimon/logrusr/v3 v3.1.0
github.com/codingconcepts/env v0.0.0-20200821220118-a8fbf8d84482
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/konveyor/analyzer-lsp v0.3.0-alpha.1
github.com/konveyor/analyzer-lsp v0.3.0-beta.1.2
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc=
github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
github.com/konveyor/analyzer-lsp v0.3.0-alpha.1 h1:RilOnB9E6+zDSDQs4vBVPMITuSD3o+6P0dkXWW2H3YQ=
github.com/konveyor/analyzer-lsp v0.3.0-alpha.1/go.mod h1:Rv2WcWfVMEGEWqn0Fl4U4NcmJYPrmWdPtaFE9KDVVF8=
github.com/konveyor/analyzer-lsp v0.3.0-beta.1.2 h1:yZh5rTZYq1XYzDei3/zwZOqE8XktftaETNycV3Q7ACE=
github.com/konveyor/analyzer-lsp v0.3.0-beta.1.2/go.mod h1:zJCmIq08X0kPvtU8ZSmz+mZmQfBt4hdy9enoEy1AQw4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down
35 changes: 34 additions & 1 deletion hack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,37 @@

## General run

* `sample_jakartaee_duke_analyze.sh`: Clone and analyze a jakartaee sample
* `sample_jakartaee_duke_analyze.sh`: Clone and analyze a jakartaee sample

## Gather analysis traces

Full traces of the analysis process can be collected via Jaeger.

First, run the Jaeger container that will collect traces from analysis:

```sh
podman run -d --net=host --name jaeger -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 jaegertracing/all-in-one:1.23
```

> Note that we are running Jaeger in `host` network so that analyzer container can communicate with it later. There are several services running in the container, it could happen that the ports they use are pre-occupied on your host. In that case, you will need to free them up manually.
The Jaeger collector listens on `14268` while the UI listens on `16686` in the container.

Now, we will run analysis by enabling the tracer that will send traces to our Jaeger collector.

To do that, pass `--jaeger-endpoint` flag with the value being the collector endpoint:

```sh
kantra analyze <YOUR_OPTIONS_HERE> --jaeger-enpoint 'http://172.17.0.1:14268/api/traces'
```

> Note that `172.17.0.1` is the IP address using which a Podman container can communicate with the host on Linux. It might be different for your system. Alternatively, you can create a network, set it as default and create your Jaeger instance in it to access it via a name instead of IP.
When analysis finishes, download the traces from Jaeger:

```sh
curl -o traces.json http://localhost:16686/api/traces?service=analyzer-lsp
```

To view the results locally, open [http://localhost:16686/](http://localhost:16686/) in your browser