Skip to content

Conversation

@nakabonne
Copy link
Member

What this PR does / why we need it:

Which issue(s) this PR fixes:

Ref #1381

Does this PR introduce a user-facing change?:

NONE

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.90%. This pull request decreases coverage by -0.16%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.GetLatestEvent -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineRoleHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineRoleBindingHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineClusterRoleHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineClusterRoleBindingHealth -- 0.00% +0.00%
pkg/datastore/eventstore.go NewEventStore -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.AddEvent -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.ListEvents -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineResourceHealth 0.00% 0.00% +0.00%
pkg/datastore/event.go NewEventStore 100.00% -- -100.00%
pkg/datastore/event.go eventStore.AddEvent 100.00% -- -100.00%

}

// GetLatestEvent gives back the latest event that meets the given conditions.
func (a *PipedAPI) GetLatestEvent(ctx context.Context, req *pipedservice.GetLatestEventRequest) (*pipedservice.GetLatestEventResponse, error) {
Copy link
Member Author

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.

@nghialv
Copy link
Member

nghialv commented Jan 13, 2021

I am thinking that maybe we should have a simple local store for the latest Events inside piped. (ref: command store)
And EventWatcher will retrieve the needed events from that local store instead of the control-plane.

What does the local store

  • that local store will periodically fetch the events of a project from its milestone/marked-created-at via something like ListEvents(milestone) then store them inside the memory
  • if the requested event from EventWatcher was not found inside the memory. The store sends a request to fetch that single event via GetLatestEvent(name, labels).

(This local store acts as a memory cache)

@nakabonne
Copy link
Member Author

@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 milestone/marked-created-at. It means we periodically fetch all Events newly created after marked-created-at (or updated-at)?
(Also, isn't it wrong that piped saves the marked-created-at timestamp inside itself?)

@nakabonne
Copy link
Member Author

You often use milestone and i can imagine it's a useful term. I now roughly understand that mean but not get it exactly. What did you refer to when you started using it? Please let me know if you remember.

@nakabonne
Copy link
Member Author

I just want to know its accurate meaning.

@nghialv
Copy link
Member

nghialv commented Jan 13, 2021

Sorry, I am having a MTG now.

It means we periodically fetch all Events newly created after marked-created-at (or updated-at)?

Yes, fetch all newly created events after the milestone/marked-created-at value.

piped saves the marked-created-at timestamp inside itself?

Yes, that value is just stored in memory and can be reset when piped restarted.

I am thinking about the flow as following:

  • when the piped is started, the milestone/marked-created-at value is set by time.Now() - time.Hour or something like this
  • each 1m, piped fetches all newly created events after the current milestone value, and then update that value to the biggest createdAt value from the response

@nghialv
Copy link
Member

nghialv commented Jan 13, 2021

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.

@nakabonne
Copy link
Member Author

nakabonne commented Jan 13, 2021

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 👍

@nghialv
Copy link
Member

nghialv commented Jan 13, 2021

👍

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

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

GO_LINTER

Some issues were detected while linting go source files in your changes.

@nakabonne
Copy link
Member Author

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.
And let me implement the apistore for Event at #1411.

@nakabonne
Copy link
Member Author

Fixed done!

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.86%. This pull request decreases coverage by -0.20%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.GetLatestEvent -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ListEvents -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineRoleHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineRoleBindingHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineClusterRoleHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineClusterRoleBindingHealth -- 0.00% +0.00%
pkg/datastore/eventstore.go NewEventStore -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.AddEvent -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.ListEvents -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineResourceHealth 0.00% 0.00% +0.00%
pkg/datastore/event.go NewEventStore 100.00% -- -100.00%
pkg/datastore/event.go eventStore.AddEvent 100.00% -- -100.00%


message ListEventsRequest {
// Mark that the client has handled all events created before this value.
int64 milestone = 1 [(validate.rules).int64.gt = 0];
Copy link
Member

@nghialv nghialv Jan 13, 2021

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.)

Copy link
Member Author

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

Copy link
Member Author

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.

Comment on lines 760 to 766
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")
}
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.
Copy link
Member

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.

return nil, status.Error(codes.Internal, "failed to list event")
}
if len(events) == 0 {
a.logger.Error("no events found",
Copy link
Member

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.

Copy link
Member Author

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.

@nakabonne
Copy link
Member Author

@nghialv Thanks for taking a look. Fixed all of them.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.87%. This pull request decreases coverage by -0.19%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.GetLatestEvent -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ListEvents -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineRoleHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineRoleBindingHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineClusterRoleHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineClusterRoleBindingHealth -- 0.00% +0.00%
pkg/datastore/eventstore.go NewEventStore -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.AddEvent -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.ListEvents -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineResourceHealth 0.00% 0.00% +0.00%
pkg/datastore/event.go NewEventStore 100.00% -- -100.00%
pkg/datastore/event.go eventStore.AddEvent 100.00% -- -100.00%


message ListEventsRequest {
// returns all events created after this value.
int64 after = 1 [(validate.rules).int64.gt = 0];
Copy link
Member

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)

Copy link
Member Author

@nakabonne nakabonne Jan 13, 2021

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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()

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member

@nghialv nghialv Jan 13, 2021

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)

Copy link
Member

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.

Copy link
Member Author

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.

@pipecd-bot
Copy link
Collaborator

TODO

The following ISSUES will be created once got merged. If you want me to skip creating the issue, you can use /todo skip command.

Details

1. Enable to use labels to filter Events

https://github.com/pipe-cd/pipe/blob/a3dbc03c7f887d45d9d46b193ce51bc81588cd60/pkg/app/api/grpcapi/piped_api.go#L705-L708

This was created by todo plugin since "TODO:" was found in a3dbc03 when #1410 was merged. cc: @nakabonne.

@nakabonne
Copy link
Member Author

Changed to use from and to instead of after.

@nghialv
Copy link
Member

nghialv commented Jan 13, 2021

Nice. Thank you.
/lgtm

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.87%. This pull request decreases coverage by -0.19%.

File Function Base Head Diff
pkg/app/api/grpcapi/piped_api.go PipedAPI.GetLatestEvent -- 0.00% +0.00%
pkg/app/api/grpcapi/piped_api.go PipedAPI.ListEvents -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineRoleHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineRoleBindingHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineClusterRoleHealth -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineClusterRoleBindingHealth -- 0.00% +0.00%
pkg/datastore/eventstore.go NewEventStore -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.AddEvent -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.ListEvents -- 0.00% +0.00%
pkg/app/piped/cloudprovider/kubernetes/state.go determineResourceHealth 0.00% 0.00% +0.00%
pkg/datastore/event.go NewEventStore 100.00% -- -100.00%
pkg/datastore/event.go eventStore.AddEvent 100.00% -- -100.00%

@khanhtc1202
Copy link
Member

/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by khanhtc1202.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit 86009e2 into master Jan 13, 2021
@pipecd-bot pipecd-bot deleted the event-piped-api branch January 13, 2021 08:40
pipecd-bot pushed a commit that referenced this pull request Jan 15, 2021
**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.
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.

5 participants