-
Notifications
You must be signed in to change notification settings - Fork 38
[gce_testing] Create findMatchingLogs to return all found logs and create QueryAllLogs.
#485
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
base: master
Are you sure you want to change the base?
Conversation
|
Why not just leave |
…found logs in the backend from a log query.
hasMatchingLog and QueryLog.hasMatchingLog to return all found logs and create QueryAllLogs.
Thank you for the comment @jefferbrecht ! I was going back and forth between the possibilities of how to expose the "found log count" while minimizing the API updates. The last update returns all found logs in |
| } | ||
| matchingLogs = append(matchingLogs, entry) | ||
| } | ||
| if found && len(matchingLogs) == 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: append here is guaranteed to result in a non-empty slice, and we set found at the same time as append, so we no longer need the found variable -- just test on len(matchingLogs) > 0. We can also eliminate the returned bool: if the query turns up empty then we'd signal "logs not found" by returning an empty slice.
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.
Done! Renamed hasMatchingLogs to findMatchingLogs to represent more accurately the new implementation.
| // over the trailing time interval specified by the given window. | ||
| // Returns the first log entry found, or an error if the log could not be | ||
| // found after some retries. | ||
| func QueryLog(ctx context.Context, logger *log.Logger, vm *VM, logNameRegex string, window time.Duration, query string, maxAttempts int) (*cloudlogging.Entry, 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.
We should be able to implement QueryLog by just calling QueryAllLogs internally and returning the first element of the slice.
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.
Done!
| // over the trailing time interval specified by the given window. | ||
| // Returns all the log entries found, or an error if the log could not be | ||
| // found after some retries. | ||
| func QueryAllLogs(ctx context.Context, logger *log.Logger, vm *VM, logNameRegex string, window time.Duration, query string, maxAttempts int) ([]*cloudlogging.Entry, 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.
QueryAllLogs arguably does not need the "retry until at least one log is found" logic (although the "retry on retriable failure" logic should stay). IMO that's only there for "get me the first matching log ASAP" (which is just QueryLog), whereas here the caller is more likely to be looking for "get me all matching logs from the given time window" (after they've waited an appropriate amount of time for the eventual consistency of the backend).
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 don't see how to remove "retry until at least one log is found" from QueryAllLogs without having some downsides.
@jefferbrecht Could you add more details in the expected solution here ?
IMO that's only there for "get me the first matching log ASAP"
I think it could also be thought as "return query result if you find any data". It has the additional value of shorter tests.
QueryAllLogsarguably does not need the "retry until at least one log is found" logic (although the "retry on retriable failure" logic should stay).
Yes, "get me all matching logs from the given time window" maybe the most likely use case of QueryAllLogs, but i don't see an alternative way of "stopping the lookup" that is more helpful for testing.
Alternatives :
- [Current] Stops querying the backend if any data is found (
len(matchingLogs) > 0).- Shorter tests.
- Caller is expecting to see "all found data".
- Stop when
err == nil- Shorter tests. May result in "no data found".
- No consideration for race conditions when log may take longer to be ingested.
- Create an
expectedLogCountand stop whenlen(matchingLogs) >= expectedLogCount.- Same as the previous one, but more restrictive.
- Remove the "stop after data is found" will result in the always querying "maxAttempts".
- The tests is long (
maxAttempt * backoffTime) and if the time window is small (e.g. 1 minute), the last query could return less data after backoff retries.
- The tests is long (
…Refactor `QueryLog` to use `QueryAllLogs`.
hasMatchingLog to return all found logs and create QueryAllLogs. findMatchingLogs to return all found logs and create QueryAllLogs.
Update
hasMatchingLogto return all found logs and createQueryAllLogs.Context :
file offsetstorage to Otel Logging receivers. ops-agent#2166, we need to able to know how many logs did a query returned.