-
Notifications
You must be signed in to change notification settings - Fork 208
Add Piped API to give back the latest Event #1410
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
Conversation
pipecd-bot
left a comment
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.
|
Code coverage for golang is
|
| } | ||
|
|
||
| // GetLatestEvent gives back the latest event that meets the given conditions. | ||
| func (a *PipedAPI) GetLatestEvent(ctx context.Context, req *pipedservice.GetLatestEventRequest) (*pipedservice.GetLatestEventResponse, 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.
I'm still debating letting it give back a list like ListNotCompletedDeployments. Honestly not sure it's able to perform IN query against map[string]string for all Datastore type well. I attempted to put off it but seems like I'd better carefully look into it at this point.
|
I am thinking that maybe we should have a simple local store for the latest Events inside What does the local store
(This local store acts as a memory cache) |
|
@nghialv Acutually I was also looking into having the local store inside Piped, but was not sure how to have the only latest Events. Your suggestion that cache the Event structure as-is looks great! But honestly, I don't get what you said exactly especially the part of |
|
You often use |
|
I just want to know its accurate meaning. |
|
Sorry, I am having a MTG now.
Yes, fetch all newly created events after the milestone/marked-created-at value.
Yes, that value is just stored in memory and can be reset when piped restarted. I am thinking about the flow as following:
|
|
While saving the event into the local store, the one that has the same ID (list of labels(name = event-name, repo-id= foo...)) will be overridden. |
|
Sorry to interrupt your MTG. You can answer after you finished that. The flow you suggested looks great. I'll look into if we really can do it with no problem 👍 |
|
👍 |
pipecd-bot
left a comment
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.
|
Seems like no problem with this solution. I'm still not sure if this usage of Milestone is correct, let me know if it's wrong. |
|
Fixed done! |
|
Code coverage for golang is
|
|
|
||
| message ListEventsRequest { | ||
| // Mark that the client has handled all events created before this value. | ||
| int64 milestone = 1 [(validate.rules).int64.gt = 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: This is API definition so I think it could be from (if the event for this value should be included too) or after.
(Milestone or marked-something is just a name used inside piped code.)
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.
Thank you. Acutually I've cared about this part. from looks good
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.
Exactly we don't include the given value itself, so after is more appropriate.
pkg/app/api/grpcapi/piped_api.go
Outdated
| if len(events) == 0 { | ||
| a.logger.Error("no events found", | ||
| zap.String("project-id", projectID), | ||
| zap.Int64("milestone", req.Milestone), | ||
| ) | ||
| return nil, status.Error(codes.NotFound, "no events found") | ||
| } |
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.
Other List~ API doesn't treat the not found case as an error, but I'd say it should be handled.
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 am not sure why we need to add this NotFound error while the empty list already means nothing was found.
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.
Come to think of it, right, it represents Not Found well. I'll fix it.
| // By that way we can control the traffic to the datastore in a better way. | ||
| rpc ReportApplicationLiveStateEvents(ReportApplicationLiveStateEventsRequest) returns (ReportApplicationLiveStateEventsResponse) {} | ||
|
|
||
| // GetLatestEvent gives back the latest event that meets the given conditions. |
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: gives back -> returns
Just to be unified.
pkg/app/api/grpcapi/piped_api.go
Outdated
| return nil, status.Error(codes.Internal, "failed to list event") | ||
| } | ||
| if len(events) == 0 { | ||
| a.logger.Error("no events found", |
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 think this shouldn't be an Error log.
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.
Right, I started thinking the log itself is no longer needed.
|
@nghialv Thanks for taking a look. Fixed all of them. |
|
Code coverage for golang is
|
|
|
||
| message ListEventsRequest { | ||
| // returns all events created after this value. | ||
| int64 after = 1 [(validate.rules).int64.gt = 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.
How about making this to be more familiar, by using from and to.
The response will contain all events in this range [from, to).
(from <= && < to)
(And the mark at the piped should be to)
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 good. Then PIped uses to+1 value for the next time, right?
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 can be confusable, I mean for the next time Piped uses the maximum created_at in the previous result.
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 think piped uses to, because that the previous call, to was not included.
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.
And by this way we don't need to find the maximum created_at value from the previous response, Just use time.Now()
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 see, maybe I don't fully understand the standard about queries.
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.
Ok, let me confirm this is correct or not: from <= response < to
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.
- first call: [time.Now - time.Hour, time.Now)
- from the second call: [previousCall.To, time.Now)
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.
Ok, let me confirm this is correct or not: from <= response < to
Yes, that is correct.
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.
Fine. Definitely that is more familiar for most developers.
|
The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use Details1. Enable to use labels to filter EventsThis was created by todo plugin since "TODO:" was found in a3dbc03 when #1410 was merged. cc: @nakabonne. |
|
Changed to use |
|
Nice. Thank you. |
|
Code coverage for golang is
|
|
/approve |
**What this PR does / why we need it**: This PR adds a new `apistore` for Events according to @nghialv 's [suggestion](#1410 (comment)). It allows us to reduce communication number by caching the latest events. This will be used by #1411 at first. **Which issue(s) this PR fixes**: Ref #1381 **Does this PR introduce a user-facing change?**: <!-- If no, just write "NONE" in the release-note block below. --> ```release-note NONE ``` This PR was merged by Kapetanios.
What this PR does / why we need it:
Which issue(s) this PR fixes:
Ref #1381
Does this PR introduce a user-facing change?: