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 a built in created time field for Tickets and the ability to filter Tickets by created time. #1162

Merged
merged 2 commits into from
Mar 20, 2020

Conversation

sawagh
Copy link
Collaborator

@sawagh sawagh commented Mar 19, 2020

Here are the highlights of this change:

  • Adds a create_time field to Ticket proto and populates this field during Ticket creation
  • Adds created_before, created_after to the Pool and filters Tickets based on create time if this field is specified.

One implementation nuance was that the current filter package directly operates on Pools. In this case (and may be similar in future), we need to convert the proto to time field - which doing for each Ticket is a lot of unnecessary repetitive work. Further, this conversion can fail - at which point, failing it at a Ticket level does not make sense (that validation / failure should be outside of the filter package).

Hence, this change abstracts the Pool from the filter package and instead introduces a Criteria structure that contains validated filtering criteria. Any validations on Pool specification can happen outside (in query service) before passing the Criteria to filter package.

One nuance is the test cases. The way the test is currently structured, the 'testcases' package is used by E2E as well as filter_tests which is great - however, with this change, the filter tests need Criteria. Hence, the subtle change is that the testcases package still uses Pool but filter_test converts that to criteria as it intends to test only the criteria whereas the e2e will continue to use more E2E Pool specification.

@sawagh sawagh force-pushed the createtime branch 2 times, most recently from ce7061e to 8703bde Compare March 19, 2020 17:34
@sawagh sawagh requested review from Laremere and yfei1 March 19, 2020 17:42
internal/filter/testcases/testcases.go Outdated Show resolved Hide resolved
internal/filter/testcases/testcases.go Show resolved Hide resolved
internal/filter/filter.go Outdated Show resolved Hide resolved
for _, f := range pool.GetDoubleRangeFilters() {

// CreateTime is only populated by Open Match and hence expected to be valid.
if ct, err := ptypes.Timestamp(ticket.CreateTime); err == nil {

Choose a reason for hiding this comment

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

I don't quite like how this needs to be parsed every time. It will be parsed for every ticket for every query, regardless of if it uses CreatedBefore / CreatedAfter.

We're setting this field, so it should be valid always. Hm.
Maybe we need a type for a parsed ticket too... I don't know. What are your thoughts?

If we are logging, it should be an error, because the system is definitely not behaving at any point where a field it set is invalid.

Choose a reason for hiding this comment

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

Ok, possible course of action (unsure):
Create another type in this package that is created from a ticket proto. No visible fields, but it's passed to the In/Meets method. Maybe it can return the ticket that it was created from.

Then in query cache, use this object in the map instead of tickets.

If the ticket create time parsing fails, I think a reasonable thing to do is loudly log (but this will only happen when query cache reads the ticket, instead of every query), and then assume the ticket is one minute old.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For your logging comment, I ve changed the log to Error.

I see your concern around Ticket parsing. I did go down the path of exploring a type for the Ticket and updating query cache with it. Now, instead of parsing time on each query, you would end up re-creating the ticket for each query. Was not great. The alternative was for that custom type to just have (time.time and Ticket), store and use the entire ticket as is and only parse the time - so query cache still uses the custom type - but internally the type just stores Ticket+time. Seems strange again.

I've added a condition now so that the time gets parsed only if using before / after - so slight improvement over the previous. The time parsing btw, is just another proto conversion - I dont think it would impact performance but again, I ve not validated that. With the condition though, atleast the impact is limited to only using the time range feature.

I would prefer to keep this change as is - and if we want to explore optimizing the time parsing, doing that as a separate change - given that is an internal only optimization.

internal/filter/filter.go Outdated Show resolved Hide resolved
internal/filter/filter_test.go Show resolved Hide resolved
@sawagh
Copy link
Collaborator Author

sawagh commented Mar 20, 2020

@googlebot rescan

@sawagh sawagh merged commit e15fd47 into googleforgames:master Mar 20, 2020
@yfei1 yfei1 added this to the v0.10.0 milestone Mar 25, 2020
@sawagh sawagh deleted the createtime branch December 21, 2020 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants