-
Notifications
You must be signed in to change notification settings - Fork 76
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
Conversation
New query engine based on client.SearchByFilter, type FilterDef, and interface QueryItem.
* 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
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.
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 likedateCondition
,ipCondition
, etc. In reality they are just two typesstring
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.
govcd/filter_engine.go
Outdated
if err != nil { | ||
return nil, explanation, fmt.Errorf("[SearchByFilter] error retrieving query item list: %s", err) | ||
} | ||
if os.Getenv("GOVCD_FAIL") == "1" { |
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.
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.
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.
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
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.
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.
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.
Changed to a log-based data inspection. Also explained in CODE_GUIDELINES
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.
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. |
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.
Here, to better understand any example would be valuable
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.
Please see the comment at the top of the file.
}, | ||
UseMetadataApiFilter: false, | ||
} | ||
queryType := govcd.QtMedia |
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 sure about naming QtSomething
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.
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.
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
govcd/vdc_test.go
Outdated
@@ -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) |
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.
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` |
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.
Just noticed that URL links to the PR are missing. They are esp. important here given the size and complexity of the PR.
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.
One nit in CHANGELOG.md, otherwise LGTM.
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.
LGTM
Added methods
catalog.QueryVappTemplateList
,catalog.QueryCatalogItemList
,catalog.QueryWithMetadataFields
,catalog.QueryWithMetadataFilter
to support search by filter and filter by metadata in terraform-provider-vcd