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

Add spec.min, spec.max to categories endpoint #1059

Merged
merged 26 commits into from
Jul 27, 2023

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Jul 20, 2023

This PR adds the query parameters capabilities as well as spec.min and spec.max in the categories endpoint as they were introduced for search endpoint in these issues:

Examples:

This PR is a follow-up of #1058 . At the time of creating this PR was not merged, so this PR contains the same changes.

How to test

  1. Update some test packages to build different packages with different version of format_version
    • Remember to update for each built package the version in manifest and changelog (e.g. 0.0.9) too
    • As an example, elastic_package_registry could be modified as:
     $ git diff
    diff --git packages/elastic_package_registry/manifest.yml packages/elastic_package_registry/manifest.yml
    index b8a41f9b5..0d819ff0e 100644
    --- packages/elastic_package_registry/manifest.yml
    +++ packages/elastic_package_registry/manifest.yml
    @@ -1,4 +1,4 @@
    -format_version: 1.0.0
    +format_version: 2.10.0
     name: elastic_package_registry
     title: "Elastic Package Registry"
     version: 0.0.7
    @@ -9,6 +9,9 @@ categories:
     conditions:
       kibana.version: "^8.0.0"
       elastic.subscription: basic
    +  elastic.capabilities:
    +    - observability
    +    - security
     icons:
       - src: /img/elastic_package_registry-logo.svg
         title: Elastic Package Registry logo
  2. Build the packages
    elastic-package build
  3. Build a new local docker image for package-registry
    cd /path/to/package-registry   
    docker build -t docker.elastic.co/package-registry/package-registry:v1.21.0-rc1 .
  4. Run local package-registry using the packages directory with the built packages as a volume mount point:
    docker run --rm -p 8080:8080 -v /home/mariorodriguez/Coding/work/integrations/build/packages/:/packages/package-registry -it docker.elastic.co/package-registry/package-registry:v1.21.0-rc1
  5. Execute some queries against this local package-registry:
    # filter categories with spec.min and spec.max
    curl -s "http://localhost:8080/categories?spec.min=2.2.0&spec.max=3.0.0&prerelease=true" | jq -r '.[]|"\(.name) - \(.version)"'
    # filter categories with spec and kibana.version
    curl -s "http://localhost:8080/categories?spec.min=2.2.0&spec.max=3.0.0&kibana.version=8.6.0&prerelease=true" | jq -r '.[]|"\(.name) - \(.version)"'
    
    # filter categories with capabilities
    curl -s "http://localhost:8080/categories?capabilities=observability,security&prerelease=true" | jq -r '.[]|"\(.name) - \(.version)"'
     curl -s "http://localhost:8080/categories?capabilities=none&prerelease=true" | jq -r '.[]|"\(.name) - \(.version)"'

@mrodm mrodm self-assigned this Jul 20, 2023
"github.com/elastic/package-registry/proxymode"
)

func TestCategoriesWithProxyMode(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was moved from proxy_mode_test.go file

@mrodm mrodm force-pushed the add_spec_capabilities_categories branch from 04684d5 to 8a56ca2 Compare July 24, 2023 10:52
categories.go Outdated
Comment on lines 131 to 148
if v := query.Get("capabilities"); v != "" {
filter.Capabilities = strings.Split(v, ",")
}

if v := query.Get("spec.min"); v != "" {
filter.SpecMin, err = semver.NewVersion(v)
if err != nil {
return nil, fmt.Errorf("invalid 'spec.min' version '%s': %w", v, err)
}
}

if v := query.Get("spec.max"); v != "" {
filter.SpecMax, err = semver.NewVersion(v)
if err != nil {
return nil, fmt.Errorf("invalid 'spec.max' version '%s': %w", v, err)
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main changes included in this PR, adding these new filters to categories endpoint.

main_test.go Outdated
Comment on lines 75 to 78
{"/categories?capabilities=observability,security&prerelease=true", "/categories", "categories-prerelease-capabilities-observability-security.json", categoriesHandler(testLogger, indexer, testCacheTime)},
{"/categories?capabilities=none&prerelease=true", "/categories", "categories-prerelease-capabilities-none.json", categoriesHandler(testLogger, indexer, testCacheTime)},
{"/categories?spec.min=1.1.0&spec.max=2.10.0&prerelease=true", "/categories", "categories-spec-min-1.1.0-max-2.10.0.json", categoriesHandler(testLogger, indexer, testCacheTime)},
{"/categories?spec.max=2.10.0&prerelease=true", "/categories", "categories-spec-max-2.10.0.json", categoriesHandler(testLogger, indexer, testCacheTime)},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new test cases for these new query parameters.

@mrodm mrodm requested a review from a team July 24, 2023 14:46
@mrodm mrodm marked this pull request as ready for review July 24, 2023 14:46
@mrodm mrodm force-pushed the add_spec_capabilities_categories branch from 848766a to ae570dd Compare July 25, 2023 14:00
@mrodm mrodm changed the title Add spec.min, spec.max and capabilities to categories endpoint Add spec.min, spec.max to categories endpoint Jul 25, 2023
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but not sure if this will work for patch versions, please add a test for this case.

packages/packages_test.go Outdated Show resolved Hide resolved
packages/package.go Outdated Show resolved Hide resolved
packages/package.go Outdated Show resolved Hide resolved
@mrodm mrodm requested a review from jsoriano July 26, 2023 16:30
@elasticmachine
Copy link

💚 Build Succeeded

History

cc @mrodm

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mrodm mrodm merged commit 4e84d23 into elastic:main Jul 27, 2023
@mrodm mrodm deleted the add_spec_capabilities_categories branch July 27, 2023 07:51
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

Successfully merging this pull request may close these issues.

3 participants