Skip to content

Conversation

@nakabonne
Copy link
Member

What this PR does / why we need it:
After merging this, it will:

  • add event-key when registering an Event
  • use event-key when filtering Events

Which issue(s) this PR fixes:

Fixes #1421
Fixes #1437

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.84%. This pull request increases coverage by 0.01%.

File Function Base Head Diff
pkg/model/event.go MakeEventKey -- 100.00% +100.00%
pkg/datastore/eventstore.go eventStore.AddEvent 100.00% 100.00% +0.00%
pkg/app/piped/apistore/eventstore/store.go makeEventKey 100.00% -- -100.00%

// This is intended to be used to specify additional attributes of event.
map<string,string> labels = 5;
// A unique identifier consists of its own name and labels.
string event_key = 6 [(validate.rules).string.min_len = 1];
Copy link
Member

Choose a reason for hiding this comment

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

Where is the hash value that we talked about before?

Copy link
Member Author

Choose a reason for hiding this comment

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

My apologies, I totally forgot it.

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. I've done added the hash just now.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.84%. This pull request increases coverage by 0.01%.

File Function Base Head Diff
pkg/model/event.go MakeEventKey -- 100.00% +100.00%
pkg/app/piped/apistore/eventstore/store.go store.sync 0.00% 0.00% +0.00%
pkg/app/piped/logpersister/stagelogpersister.go stageLogPersister.flushFromLastCheckpoint 61.11% 50.00% -11.11%
pkg/datastore/eventstore.go eventStore.AddEvent 100.00% 100.00% +0.00%
pkg/app/piped/apistore/eventstore/store.go makeEventKey 100.00% -- -100.00%

func (s *store) GetLatest(ctx context.Context, name string, labels map[string]string) (*model.Event, bool) {
key := makeEventKey(name, labels)
s.mu.RLock()
key := model.MakeEventKey(name, labels)
Copy link
Member

Choose a reason for hiding this comment

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

nit: This should be done before locking.

// Check if we can get the exact same string.
got1 := MakeEventKey(tc.name1, tc.labels1)
got2 := MakeEventKey(tc.name2, tc.labels2)
assert.Equal(t, tc.wantSame, got1 == got2)
Copy link
Member

Choose a reason for hiding this comment

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

Add the check of key length to ensure that they are not empty strings.

}

func (s *eventStore) AddEvent(ctx context.Context, e model.Event) error {
e.EventKey = model.MakeEventKey(e.Name, e.Labels)
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 it is better to set the key when making the event instead of here.
https://github.com/pipe-cd/pipe/blob/master/pkg/app/api/grpcapi/api.go#L323

Copy link
Member Author

Choose a reason for hiding this comment

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

Every event should have an event-key derived from the exact same method. So I thought making here is more appropriate, but you don't think so right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I got your point. I was thinking the same.
But I feel updating the model inside this function is not good because the store is just for storing and querying.

(To be honest, I also want to remove the part of updating CreatedAt and UpdatedAt from this function. But that is future talk.)

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, that makes total sense. This datastore package provides non-domain-specific, versatile facilities and should just operate external Datastore services. I feel exactly the same, so let me fix it!

@nakabonne
Copy link
Member Author

I've fixed all of those pointed out!

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 33.83%. This pull request increases coverage by 0.00%.

File Function Base Head Diff
pkg/model/event.go MakeEventKey -- 100.00% +100.00%
pkg/app/piped/apistore/eventstore/store.go store.sync 0.00% 0.00% +0.00%
pkg/app/piped/logpersister/stagelogpersister.go stageLogPersister.flushFromLastCheckpoint 61.11% 50.00% -11.11%
pkg/app/piped/apistore/eventstore/store.go makeEventKey 100.00% -- -100.00%

@nghialv
Copy link
Member

nghialv commented Jan 18, 2021

/lgtm

@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 6071adb into master Jan 18, 2021
@pipecd-bot pipecd-bot deleted the event-key branch January 18, 2021 07:57
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.

Add event key to Event model Enable to use labels to filter Events

5 participants