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

Query enhancement and filter engine for metadata search #298

Merged
merged 42 commits into from
May 16, 2020

Conversation

dataclouder
Copy link
Contributor

Added methods catalog.QueryVappTemplateList, catalog.QueryCatalogItemList, catalog.QueryWithMetadataFields, catalog.QueryWithMetadataFilter to support search by filter and filter by metadata in terraform-provider-vcd

Giuseppe Maxia added 5 commits April 10, 2020 15:43
@dataclouder dataclouder changed the title Query enhancement for vApp template and catalog item Query enhancement and filter engine for metadata search Apr 10, 2020
Giuseppe Maxia added 19 commits April 13, 2020 22:09
* Change SearchByFilter function to use dependency injection
* Add unit test for query engine
* Add filter type 'earliest'
* Add human readable explanation of engine actions
Add filter_helpers.go, containing functions used to create filters
Queries that are paginated will iterate until all elements are
collected.
Add filed type to metadata contents
If we use `xml:"type"`, we get the metadata info, but then the metadata
update will fail. We keep it as it is for the time being
* Add more error information
* Add guessing of metadata type when API doesn't return the info
@dataclouder dataclouder marked this pull request as ready for review April 30, 2020 11:45
Copy link
Collaborator

@Didainius Didainius left a comment

Choose a reason for hiding this comment

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

Pass one.
Great PR! As a side joke I wished writing YOLO and approving a few times :)

Getting to serious matters - a few more thoughts in addition to comments inline:

  • One thing which I'd like to change is conditionMatches() function and avoid types for each field like dateCondition, ipCondition, etc. In reality they are just two types string or *regexp.Regexp. However so far a perfect solution doesn't come to my mind so far so have nothing exact to propose and will obey.
  • var definitions in searchByFilter could come closer to their usage

Test suites passed on 9.5 and 10.1.

if err != nil {
return nil, explanation, fmt.Errorf("[SearchByFilter] error retrieving query item list: %s", err)
}
if os.Getenv("GOVCD_FAIL") == "1" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A thought here - wouldn't it be the same in terms of debugging to simply use logging utility and dump structures to the log. That way we could tap into existing troubleshooting system. No need to ask users for additional env variable setting.

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 approach was made this way because the output of these user-defined failures are huge. If we use them always, the log will grow considerably.
A change that I am considering is to make these logs entries depend on GOVCD_FAIL=X.

As I mentioned in my intro presentation, I could completely eliminate this backdoor once we finish the review, or we may decide to convert them into a log-based interface

Copy link
Collaborator

Choose a reason for hiding this comment

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

Having them is good. In some situations we need all we can get :)
Another thought about logging. What if we gradually introduce loglevels to GOVCD_LOG variable. For example log this output only when GOVCD_LOG=TRACE. It wouldn't break anything, but could give flexibility without new variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to a log-based data inspection. Also explained in CODE_GUIDELINES

Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

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

That's huge work. Thank you
First things which I would like to be improved.


* If we want to include metadata, we need to add the metadata fields to the list of fields we want the query to fetch.
* Unfortunately, not all fields defined in the corresponding type is accepted by the `fields` parameter in a query.
The fields returned by `queryFieldsOnDemand` are the one that have been proven to be accepted.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, to better understand any example would be valuable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see the comment at the top of the file.

},
UseMetadataApiFilter: false,
}
queryType := govcd.QtMedia
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about naming QtSomething

Copy link
Contributor Author

@dataclouder dataclouder May 5, 2020

Choose a reason for hiding this comment

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

Qt stands for "Query Type". It's used for constants that can be called from go-vcloud-director and terraform provider, to avoid mistyping. For example, vApp template query types use a bizarre camel case that is easy to get wromg.

Giuseppe Maxia added 8 commits May 5, 2020 19:51
When the catalog items are more than the default page size, we don't get
all of them. Instead of calling the regular QueryWithNotEncodedParams,
we need to run cumulativeQuery
* Improve functions comments
* Add to CHANGELOG.md
* Make some functions private
* Reduce wide scope variable in the search engine
@@ -112,7 +112,7 @@ func (vcd *TestVCD) Test_NewVdc(check *C) {

// Skipping this check, as we can't define the existence of a given vApp template beforehand
/*
check.Assert(vcd.vdc.Vdc.ResourceEntities[0].ResourceEntity[0].Name, Equals, "vAppTemplate")
check.Assert(vcd.vdc.Vdc.ResourceEntities[0].ResourceEntity[0].Name, Equals, QTVappTemplate)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like "QT" should be "Qt" (or whatever prefix we end up with).

CHANGELOG.md Outdated
* Changed signature for `FindAdminCatalogRecords`, which now returns normalized type `[]*types.CatalogRecord`
* Added methods `catalog.QueryVappTemplateList`, `catalog.QueryCatalogItemList`, `client.queryWithMetadataFields`, `client.queryByMetadataFilter`
* Added query engine based on `client.SearchByFilter`, type `FilterDef`, and interface `QueryItem`
* Added methods `adminOrg.QueryCatalogList` and `org.QueryCatalogList`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed that URL links to the PR are missing. They are esp. important here given the size and complexity of the PR.

Copy link
Collaborator

@lvirbalas lvirbalas left a comment

Choose a reason for hiding this comment

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

One nit in CHANGELOG.md, otherwise LGTM.

Copy link
Contributor

@vbauzys vbauzys left a comment

Choose a reason for hiding this comment

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

LGTM

@dataclouder dataclouder merged commit 980d170 into vmware:master May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants