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

Сhoco search returns different results for GHC package #2271

Open
miketimofeev opened this issue May 12, 2021 · 11 comments
Open

Сhoco search returns different results for GHC package #2271

miketimofeev opened this issue May 12, 2021 · 11 comments

Comments

@miketimofeev
Copy link

miketimofeev commented May 12, 2021

What You Are Seeing?

We use choco during GitHub hosted images generation in https://github.com/actions/virtual-environments repository.
We have been observing an intermittent issue since GHC 9.0.1 was released in March — sometimes choco search ghc --allversions returns 9.0.1 and sometimes doesn't. As a result, different ghc versions are available on the final VM image, which is confusing.

What is Expected?

choco search ghc --allversions returns version 9.0.1 among the others

How Did You Get This To Happen? (Steps to Reproduce)

Just run choco search ghc --allversions and check the results. It happens pretty irregularly, maybe 1 or 2 times a week.

Output Log

The log from choco search ghc --allversions --verbose --trace in one of such cases is more than the allowed comment size so I uploaded it to the repo:
https://github.com/miketimofeev/Choco-search-log/blob/main/Log.log

@gep13
Copy link
Member

gep13 commented May 12, 2021

@miketimofeev I haven't dug into this, so I don't have any answers for you yet, but can I ask what the process you follow for installation is? Why the need to first search for all versions? Aren't you pinning to the installation of a specific version as part of the build of the image?

@miketimofeev
Copy link
Author

@gep13 sorry, I should have mentioned that we need to provide the 3 latest GHC versions to customers:
https://github.com/actions/virtual-environments/blob/main/images/win/scripts/Installers/Install-Haskell.ps1

@steviecoaster
Copy link
Contributor

steviecoaster commented May 17, 2021

Would the following via OData help?

$ODataQuery = '$filter=(Title eq ''ghc'') and (IsPrerelease eq false)'
$Url = "https://community.chocolatey.org/api/v2/Packages()?$ODataQuery"
Invoke-RestMethod -Uri ($Url + '&$top=3')  |
Select-Object -Property @(  @{ Name = 'Id' ; Expression = { $_.title.innertext } }
@{ Name = 'Version' ; Expression = { $_.properties.Version }})

That returns the following:

Id  Version
--  -------
ghc 8.4.3
ghc 8.6.1
ghc 8.6.1.1

@steviecoaster
Copy link
Contributor

To be fair, that's more or less what is happening under the covers with choco search, but maybe a direct approach will yield a different result? Something to try in the interim while our team investigates and provides a more thorough answer back to you folks.

@miketimofeev
Copy link
Author

@steviecoaster thanks for the answer! For me it returns the following:

Id  Version
--  -------
ghc 8.2.2  
ghc 8.6.4  
ghc 8.8.3  

However, choco search returns the following in case there are no issues

[Version[]] $ChocoVersionsOutput = & choco search ghc --allversions | Where-Object { $_.StartsWith('ghc ') -and $_ -match 'Approved' } | ForEach-Object { [regex]::matches($_, '\d+(\.\d+){2,}').value }
$ChocoVersionsOutput | Group-Object { $_.ToString(2) } | Sort-Object Name -Descending | Select-Object -First 3 | ForEach-Object { $_.Group | Select-Object -First 1 } | Sort-Object
Major  Minor  Build  Revision
-----  -----  -----  --------
8      6      4      -1
8      8      4      -1
9      0      1      -1

@vexx32
Copy link
Member

vexx32 commented May 17, 2021

That looks like a sorting issue in the OData query. If we modify the OData query to include an $orderBy parameter, sorting by the most recent versions, we can get the following (from my machine, anyway):

Id  Version
--  -------
ghc 9.0.1
ghc 8.8.4.1
ghc 8.8.4

this is using the following code:

$ODataQuery = '$filter=(Title eq ''ghc'') and (IsPrerelease eq false)&$orderby=Version desc&$top=3'
$Url = "https://community.chocolatey.org/api/v2/Packages()?$ODataQuery"
Invoke-RestMethod -Uri $Url |
    Select-Object -Property @(
        @{ Name = 'Id'; Expression = { $_.title.innertext } }
        @{ Name = 'Version'; Expression = { $_.properties.Version } }
    )

I'd be interested to know if y'all are getting bad results from that query occasionally similar to how you're getting intermittently bad results from choco search.

@miketimofeev
Copy link
Author

@vexx32 Sorry, I forgot to mention that we need not the 3 latest versions, but 3 latest major.minor versions like 9.0.1, 8.10.4, 8.8.4.1 — that's why we use the additional filtration using Powershell. I'm not sure it can be done using ODataQuery.
Anyway, I'll check whether ODataQuery returns version 9.0.1 when the choco search doesn't and get back with the results.

@miketimofeev
Copy link
Author

Quick question — what am I doing wrong?
image

@vexx32
Copy link
Member

vexx32 commented May 18, 2021

Ah, that's on me, sorry about that, I must have edited that without thinking. The parameter is case sensitive and should be $orderby in all lowercase. I amended the above code snippet to reflect that properly.

@HUMBERP
Copy link

HUMBERP commented May 25, 2021

I have verified, that when choco search --allversions did not return version 9.0.1 the odata query did.

PS C:\> Write-Host ('Result from odata query ({0})' -f (Get-Date))
      $ODataQuery = '$filter=(Title eq ''ghc'') and (IsPrerelease eq false)&$orderby=Version desc&$top=3'
$Url = "https://community.chocolatey.org/api/v2/Packages()?$ODataQuery"
Invoke-RestMethod -Uri $Url |
    Select-Object -Property @(
        @{ Name = 'Id'; Expression = { $_.title.innertext } }
        @{ Name = 'Version'; Expression = { [Version]$_.properties.Version } }
    )
Result from odata query (25.05.2021 11:49:07)

Id  Version
--  -------
ghc 9.0.1
ghc 8.8.4.1
ghc 8.8.4
---------------------------------------------------------------
PS C:\> Write-Host ('Result from choco search ({0})' -f (Get-Date))
& choco search ghc --allversions --source=https://community.chocolatey.org/api/v2/ | Where-Object { $_.StartsWith('ghc ') -and $_ -match 'Approved' } | ForEach-Object { [regex]::matches($_, '\d+(\.\d+){2,}').value } | Sort-Object | Select-Object -Last 3
Result from choco search (25.05.2021 11:50:00)
8.8.3.1
8.8.4
8.8.4.1

therefore i sugested a modification (see comment on actions/runner-images#3434 (comment)

@miketimofeev
Copy link
Author

We haven't seen the issue since switching to use OData instead of choco search so it seems that something goes wrong with the search command itself 🤔

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

No branches or pull requests

5 participants