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

feat: add master logs endpoint #988

Closed
wants to merge 1 commit into from

Conversation

ybt195
Copy link

@ybt195 ybt195 commented Jul 31, 2020

Description

Test Plan

Commentary (optional)

@ybt195 ybt195 requested a review from stoksc July 31, 2020 17:51
@cla-bot cla-bot bot added the cla-signed label Jul 31, 2020
Copy link
Contributor

@stoksc stoksc left a comment

Choose a reason for hiding this comment

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

looks fine, just the calculations made my brain hurt a bit at first.

Comment on lines +37 to +52
total := a.m.logs.Len()
offset := int(req.Offset)
if req.Offset < 0 {
offset = total + offset
if offset < 0 {
offset = 0
}
}

limit := -1
if req.Limit != 0 {
limit = int(req.Limit)
if limit > total-offset {
limit = total - offset
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: can we pull both of these blocks into helper functions that help explain what's going on (by having nice function names)?

func (a *apiServer) MasterLogs(
req *apiv1.MasterLogsRequest, resp apiv1.Determined_MasterLogsServer) error {
if err := grpc.ValidateRequest(
func() (bool, string) { return req.Limit >= 0, "Limit must be >= 0" },
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also validation offset < a.m.logs.Len() (sort of how we set offset = 0 if the negative offset was too large).

Copy link
Author

Choose a reason for hiding this comment

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

I went back and forth on this. Because the offset may be valid in the future, all the logging endpoints will accept offset that are not yet valid.

Comment on lines 55 to 64
for _, log := range a.m.logs.Entries(offset, -1, limit) {
offset += 1
limit -= 1
if err := resp.Send(log.Proto()); err != nil {
return err
}
}
if !req.Follow || limit == 0 {
return nil
}
Copy link
Contributor

@stoksc stoksc Jul 31, 2020

Choose a reason for hiding this comment

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

If we tail the logs, we'll overflow limit eventually and after ~ 2 * math.MaxInt64 exit because limit == 0 on line 62.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might should fix this by adding an

else if req.Follow {
   limit = -1
}

somewhere?

@hamidzr
Copy link
Member

hamidzr commented Aug 4, 2020

closing in favor of #1007

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.

3 participants