Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

odo/alizer reports wrong devfile #105

Closed
jeffmaury opened this issue Oct 10, 2022 · 13 comments · Fixed by #106
Closed

odo/alizer reports wrong devfile #105

jeffmaury opened this issue Oct 10, 2022 · 13 comments · Fixed by #106

Comments

@jeffmaury
Copy link
Member

When using odo 3.0.0-rc2 against https://github.com/quarkusio/quarkus-super-heroes/tree/main/ui-super-heroes, odo init proposes the NodeJS devfile where it should report the Angular devfile.
Please note that odo uses SelectDevFileFromTypes and that the Alizer go cli reports corrects info with the analyze command but nodejs with the devfile command

@jeffmaury
Copy link
Member Author

List of NodeJS stacks supported by the registry:

  • Angular
  • NextJS
  • NuxtJS
  • React
  • Svelte
  • Vue

lstocchi added a commit to lstocchi/alizer that referenced this issue Oct 26, 2022
Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
lstocchi added a commit that referenced this issue Nov 4, 2022
* feat: add detection for multiple js frameworks (#105)

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add vue detection

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add tests for angular

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add tests for nextjs

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add tests for nuxtjs

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add tests for svelte

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* extend port detection for dev script for next and nuxt frameworks

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add tests for vue

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* rename method

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* fix test in java

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* fix java test

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add detection from config file for nuxt and vue

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* fix copyright dates

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* update port detection doc

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

* add js frameworks to alizer-spec doc

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
@rm3l
Copy link
Member

rm3l commented Dec 7, 2022

We (odo) have recently updated Alizer to a more recent commit (cde3c3f), which should include this fix.

I wanted to see if I could close the original issue in odo (redhat-developer/odo#6210), but noticed that the output was different this time.

With odo analyze (which uses SelectDevFileFromTypes) against https://github.com/quarkusio/quarkus-super-heroes/tree/main/ui-super-heroes, I am now getting java-maven:

$ odo analyze -o json     
[
        {
                "devfile": "java-maven",
                "devfileRegistry": "DefaultDevfileRegistry"
        }
]

Am I missing something?

I tried using the Alizer Go CLI and I have the same output:

$ alizer devfile .  
{
        "Name": "java-maven",
        "Language": "Java",
        "ProjectType": "Maven",
        "Tags": [
                "Java",
                "Maven"
        ]
}

And below is the output of alizer analyze .:

alizer analyze .
[
  {
    "Name": "TypeScript",
    "Aliases": [
      "ts"
    ],
    "Weight": 81.25,
    "Frameworks": [
      "Express"
    ],
    "Tools": [
      "NodeJs",
      "Node.js"
    ],
    "CanBeComponent": true
  },
  {
    "Name": "Shell",
    "Aliases": [
      "sh",
      "shell-script",
      "bash",
      "zsh"
    ],
    "Weight": 6.25,
    "Frameworks": [],
    "Tools": [],
    "CanBeComponent": false
  },
  {
    "Name": "JavaScript",
    "Aliases": [
      "js",
      "node",
      "nodejs"
    ],
    "Weight": 6.25,
    "Frameworks": [
      "Express"
    ],
    "Tools": [
      "NodeJs",
      "Node.js"
    ],
    "CanBeComponent": true
  },
  {
    "Name": "Batchfile",
    "Aliases": [
      "bat",
      "batch",
      "dosbatch",
      "winbatch"
    ],
    "Weight": 3.1199999999999997,
    "Frameworks": [],
    "Tools": [],
    "CanBeComponent": false
  },
  {
    "Name": "Java",
    "Aliases": null,
    "Weight": 3.1199999999999997,
    "Frameworks": [],
    "Tools": [
      "Maven"
    ],
    "CanBeComponent": true
  }
]

@jeffmaury
Copy link
Member Author

They change a few metadata on the registry so maybe alizer needs an update as well

@lstocchi
Copy link
Collaborator

lstocchi commented Dec 7, 2022

Hey @rm3l ,

When you asks for a devfile to alizer, it takes the path to start the search from (in your case the project root), if a component is detected there, it uses those infos to pick a devfile.
As you pasted in your message the component is a mix between nodejs/express (angular is not found as it is only imported as a devDependency) and java/maven. Alizer will pick one of those devfiles.

Did you expect something different? What would you like to see as an output?

@jeffmaury
Copy link
Member Author

The origin issue was running on the sub folder that was an Angular app if I remember correctly

@lstocchi
Copy link
Collaborator

lstocchi commented Dec 7, 2022

in this case it has a pom.xml and a package.json so how do you pick the right devfile? Then angular is only listed as a devDependency so it should be used only for development, is it something to track?

@rm3l
Copy link
Member

rm3l commented Dec 7, 2022

Hey @rm3l ,

When you asks for a devfile to alizer, it takes the path to start the search from (in your case the project root), if a component is detected there, it uses those infos to pick a devfile. As you pasted in your message the component is a mix between nodejs/express (angular is not found as it is only imported as a devDependency) and java/maven (if you look at the pom.xml there is no quarkus package, it's just a multi-module maven configuration). Alizer will pick one of those devfiles.

Did you expect something different? What would you like to see as an output?

Thanks for the explanations, @lstocchi !

Yes, I was trying to reproduce the original issue reported by @jeffmaury by running odo analyze from a sub-folder: he was expecting Angular/Typescript to be returned.
What I found surprising at first sight was that Alizer was returning nodejs before the update (which was almost correct), and now it is returning java-maven.
Without knowing how Alizer works, I found the output of alizer analyze to be much more accurate. TypeScript has a higher weight in the output, and that was what I was expecting to see returned. Or even NodeJS as before because it still has a higher weight than Java-Maven. But maybe my assumptions are wrong :D

@jeffmaury
Copy link
Member Author

Don't know why they have an (almost empty) pom.xml but code analysis should lead us to nodejs

@lstocchi
Copy link
Collaborator

lstocchi commented Dec 7, 2022

@rm3l when alizer finds multiple languages/frameworks it tries to give priority to the devfile that has a higher weight calculated in terms of frameworks/tools supported. e.g if it finds that the app is a golang (no framework)/nodejs (express), it picks nodejs express devfile if available as it is considered more valuable (in simple words Alizer gives points based on the feature detected... a framework is detected -> +10 points, a tool is detected -> +5 and so on, the devfile with the higher points at the end, wins).

Thinking about what i wrote above, in this case, typescript should be returned as it has a framework (express) and a tool (nodejs) while java only a tool (maven).
So the question is ... does your registry have an express devfile? If not, this is the reason why there is no a clear winner and a random devfile between maven and nodejs is picked, otherwise there is a bug. I'll give it a look btw.

Should i detect a framework in the devDependency list as well? By doing this if you have an angular devfile in your registry, alizer will pick this one.

cc @kadel to hear his opinion

@rm3l
Copy link
Member

rm3l commented Dec 7, 2022

@rm3l when alizer finds multiple languages/frameworks it tries to give priority to the devfile that has a higher weight calculated in terms of frameworks/tools supported. e.g if it finds that the app is a golang (no framework)/nodejs (express), it picks nodejs express devfile if available as it is considered more valuable (in simple words Alizer gives points based on the feature detected... a framework is detected -> +10 points, a tool is detected -> +5 and so on, the devfile with the higher points at the end, wins).

Thanks again for the clarifications. I better understand how Alizer works now.

Thinking about what i wrote above, in this case, typescript should be returned as it has a framework (express) and a tool (nodejs) while java only a tool (maven). So the question is ... does your registry have an express devfile?

I currently have my odo configured to use the staging Devfile registry at https://registry.stage.devfile.io/, and I see the Node.JS Devfile has at least the "Express" tag.

If not, this is the reason why there is no a clear winner and a random devfile between maven and nodejs is picked, otherwise there is a bug. I'll give it a look btw.

So is the Weight field in the alizer analyze output supposed to take into account what you mentioned above? Because even without considering devDependencies, it should have picked nodejs (like before the update) because it seems to have a higher Weight (6.25) than maven (3.11999...), no?

@lstocchi
Copy link
Collaborator

lstocchi commented Dec 7, 2022

I currently have my odo configured to use the staging Devfile registry at https://registry.stage.devfile.io, and I see the Node.JS Devfile has at least the "Express" tag.

Ok then there is an issue in alizer. It should have picked this one. Just opened this issue #114 to investigate more about it . I'll let you know asap

So is the Weight field in the alizer analyze output supposed to take into account what you mentioned above? Because even without considering devDependencies, it should have picked nodejs (like before the update) because it seems to have a higher Weight (6.25) than maven (3.11999...), no?

No that Weight property was originally called percentage and it is related to the number of files per language. It was renamed because of some specific scenario (see #77) . It is not taken in consideration when picking a devfile.

@rm3l
Copy link
Member

rm3l commented Dec 8, 2022

Okay, I see. Thanks, @lstocchi !

@kadel
Copy link
Member

kadel commented Dec 12, 2022

Should i detect a framework in the devDependency list as well? By doing this if you have an angular devfile in your registry, alizer will pick this one.

I think that Alizer should look into devDepedency as well. I'm no NodeJS expert, but I have seen quite a few frameworks that were listed only as devDependency.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants