Skip to content

Conversation

@mrodm
Copy link
Contributor

@mrodm mrodm commented Jul 9, 2025

Closes #1336

This PR adds support to discover packages based on the datasets defined in the discovery parameter:

discovery:
  datasets:
    - name: nginx.access
    - name: nginx.error

Example of query:

GET /search?discovery=datasets:nginx.error`

If there are multiple discovery parameters in the query, like:

GET /search?discovery=datasets:nginx.error&discovery=fields:process.pid`

packages must match all filters at the same time. In this example:

  • packages must just define process.pid as its only discovery field.
  • packages must at least define nginx.error in their discovery datasets.

Author's checklist

  • Update tests including discovery.datasets field.
  • Ensure that it can be defined more than once discovery query parameter.
  • Add changelog entry
  • Test that it can be used with discovery.fields filter.

How to test this PR locally

mage build

./package-registry

# in other terminal
# it should return "good_content" content package
curl -s "http://localhost:8080/search?discovery=datasets:good_content.access&prerelease=true"

# it should not return any package
curl -s "http://localhost:8080/search?discovery=datasets:good_content.none&prerelease=true"

# using `datasets` and `fields` discovery filters, it should return also "good_content" package
# using both filter, packages must match in all filters
curl -s "http://localhost:8080/search?discovery=datasets:good_content.access&prerelease=true&discovery=fields:process.pid"

@mrodm mrodm self-assigned this Jul 9, 2025
@prodsecmachine
Copy link

prodsecmachine commented Jul 9, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@mrodm mrodm force-pushed the add-discovery-datasets branch from 2f4de8f to f676e40 Compare July 9, 2025 10:32
@mrodm mrodm force-pushed the add-discovery-datasets branch from 1554fd7 to dc6fed9 Compare July 9, 2025 14:10
}

if v := query.Get("discovery"); v != "" {
for _, v := range query["discovery"] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change required to allow get the values of all the discovery query parameter if it is set several times.

Comment on lines 378 to 389
func (f *discoveryFilter) Matches(p *Package) bool {
if f == nil {
return true
}
return f.Fields.Matches(p)
if len(f.Fields) > 0 && !f.Fields.Matches(p) {
return false
}
if len(f.Datasets) > 0 && !f.Datasets.Matches(p) {
return false
}
return true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way it has been implemented, in order to add a package into a response, the filter must match the given package for fields and for datasets.

So in a query like

GET /search?discovery=fields:process.pid&discovery=datasets:nginx.error

The packages added to the response must fulfill these two conditions:

  • define just process.id in their discovery.fields,
  • define at least nginx.error in their discovery.datasets.

@mrodm mrodm marked this pull request as ready for review July 9, 2025 15:32
@mrodm mrodm requested a review from a team as a code owner July 9, 2025 15:32
"categories": [
"support"
],
"discovery": {}
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 key is shown because discovery is not empty:

  • Package manifest:
discovery:
  fields: []
  datasets: []
  • Field definition in BasePackage struct:
	Discovery               *Discovery           `config:"discovery,omitempty" json:"discovery,omitempty" yaml:"discovery,omitempty"`

Copy link
Member

Choose a reason for hiding this comment

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

Would omitzero help here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks it could be used to allow not show discovery: {} in the response.

I'll push a change to include this tag for json.
Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed change in f6825ec

"categories": [
"support"
],
"discovery": {}
Copy link
Member

Choose a reason for hiding this comment

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

Would omitzero help here?

Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
@elasticmachine
Copy link

💚 Build Succeeded

History

cc @mrodm

@mrodm mrodm merged commit dad8dc8 into elastic:main Jul 15, 2025
5 checks passed
@mrodm mrodm deleted the add-discovery-datasets branch July 15, 2025 15:09
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.

Add a new discovery parameter based on datasets

4 participants