-
Notifications
You must be signed in to change notification settings - Fork 67
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 and spec.max query parameter in search endpoint #1058
Conversation
|
||
// Deprecated, release tags to be removed. | ||
Experimental bool | ||
} | ||
|
||
// Apply applies the filter to the list of packages, if the filter is nil, no filtering is done. | ||
func (f *Filter) Apply(ctx context.Context, packages Packages) Packages { | ||
func (f *Filter) Apply(ctx context.Context, packages Packages) (Packages, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update return parameters, since semver.NewConstraint could fail too with an error.
if f.Capabilities != nil { | ||
if valid := p.WorksWithCapabilities(f.Capabilities); !valid { | ||
continue | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed from legacy. These clients should not send capabilities
in their queries.
} | ||
} | ||
|
||
func TestPackagesSpecMinMaxFilter(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a new test based on TestPackagesFilter
in order to be able to set specific packages.
packages/package.go
Outdated
if specMin == nil && kibanaVersion == nil { | ||
specMin = semver.MustParse("3.0.0") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not totally sure about this, this could be changed depending on what it is decided here #1050 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this default minimum spec.
So in case there is no spec.min
in the default query, it will return all the packages filtered just by spec.max
main_test.go
Outdated
{"/search?capabilities=observability,security&prerelease=true", "/search", "search-prerelease-capabilities-observability-security.json", searchHandler(testLogger, indexer, testCacheTime)}, | ||
{"/search?capabilities=none&prerelease=true", "/search", "search-prerelease-capabilities-none.json", searchHandler(testLogger, indexer, testCacheTime)}, | ||
{"/search?spec.min=1.1.0&spec.max=2.10.0&prerelease=true", "/search", "search-spec-min-1.1.0-max-2.10.0.json", searchHandler(testLogger, indexer, testCacheTime)}, | ||
{"/search?spec.max=2.10.0&prerelease=true", "/search", "search-spec-max-2.10.0.json", searchHandler(testLogger, indexer, testCacheTime)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some tests for search endpoint using capabilities and spec parameters.
Some versions of the example
and foo
test packages have been updated:
- adding capabilities
- updating
format_version
number
main_test.go
Outdated
@@ -90,6 +90,10 @@ func TestEndpoints(t *testing.T) { | |||
{"/search?type=input&prerelease=true", "/search", "search-input-packages.json", searchHandler(testLogger, indexer, testCacheTime)}, | |||
{"/search?type=input&package=integration_input&prerelease=true", "/search", "search-input-integration-package.json", searchHandler(testLogger, indexer, testCacheTime)}, | |||
{"/search?type=integration&package=integration_input&prerelease=true", "/search", "search-integration-integration-package.json", searchHandler(testLogger, indexer, testCacheTime)}, | |||
{"/search?capabilities=observability,security&prerelease=true", "/search", "search-prerelease-capabilities-observability-security.json", searchHandler(testLogger, indexer, testCacheTime)}, | |||
{"/search?capabilities=none&prerelease=true", "/search", "search-prerelease-capabilities-none.json", searchHandler(testLogger, indexer, testCacheTime)}, | |||
{"/search?spec.min=1.1.0&spec.max=2.10.0&prerelease=true", "/search", "search-spec-min-1.1.0-max-2.10.0.json", searchHandler(testLogger, indexer, testCacheTime)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see I didn't copy this to the description of the issue, sorry. In the original proposal we thought about using only <major>.<minor>
, so if a version of Kibana supports 2.0, it supports any 2.0.X version. Patch versions shouldn't include differences that break compatibility, or new features.
So the API would work like this:
{"/search?spec.min=1.1.0&spec.max=2.10.0&prerelease=true", "/search", "search-spec-min-1.1.0-max-2.10.0.json", searchHandler(testLogger, indexer, testCacheTime)}, | |
{"/search?spec.min=1.1&spec.max=2.10&prerelease=true", "/search", "search-spec-min-1.1.0-max-2.10.0.json", searchHandler(testLogger, indexer, testCacheTime)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it makes sense.
Updated the tests accordingly with that.
I also added a validation to check that versions in the query parameter are just major.minor
(added also a test for that).
func getSpecVersion(version string) (*semver.Version, error) { | ||
// version must cointain just <major.minor> | ||
if len(strings.Split(version, ".")) != 2 { | ||
return nil, fmt.Errorf("invalid version '%s': it should be <major.version>", version) | ||
} | ||
specVersion, err := semver.NewVersion(version) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid spec version '%s': %w", version, err) | ||
} | ||
return specVersion, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that versions in query parameters are as expected. That means with the pattern major.minor
packages/package.go
Outdated
} | ||
|
||
versionSplit := strings.Split(p.FormatVersion, ".") | ||
versionSplit[2] = "0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. Check length to avoid panics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe we can just build this version based on the previously parsed one.
specMajorMinorVersion := fmt.Sprintf("%d.%d.0", p.specSemVer.Major(), p.specSemVer.Minor())
04b1e17
to
0b01436
Compare
💚 Build Succeeded
History
cc @mrodm |
Fixes #1050
This PR adds two new filter parameters
spec.min
andspec.max
for the search endpoint. These values will be used to filter packages according to theirformat_version
value.If no
spec.min
norkibana.version
are in the query, the default value forspec.min
is going to be3.0.0
.How to test
format_version
elastic_package_registry
could be modified as: