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

Scheduled post #848

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Scheduled post #848

wants to merge 11 commits into from

Conversation

harshilsharma63
Copy link
Member

Summary

Adding scheduled posts support to load test tool.

Ticket Link

Fixes https://mattermost.atlassian.net/browse/MM-61486

@harshilsharma63 harshilsharma63 marked this pull request as ready for review November 14, 2024 07:01
Copy link
Member

@agnivade agnivade left a comment

Choose a reason for hiding this comment

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

It looks like some debug fmt.Println statements are still left over from debugging. Let's clean them up.

Copy link
Member

@agarciamontoro agarciamontoro left a comment

Choose a reason for hiding this comment

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

Thank you so much for all your work on this, great job! I left some comments below, and I also agree with Agniva: we should remove all the fmt.Println lines.

Comment on lines +291 to +314
{
name: "CreateScheduledPost",
run: c.createScheduledPost,
frequency: 0.2,
minServerVersion: semver.MustParse("10.3.0"),
},
{
name: "UpdateScheduledPost",
run: c.updateScheduledPost,
frequency: 0.1,
minServerVersion: semver.MustParse("10.3.0"),
},
{
name: "DeleteScheduledPost",
run: c.deleteScheduledPost,
frequency: 0.1,
minServerVersion: semver.MustParse("10.3.0"),
},
{
name: "SendScheduledPost",
run: c.sendScheduledPost,
frequency: 0.1,
minServerVersion: semver.MustParse("10.3.0"),
},
Copy link
Member

Choose a reason for hiding this comment

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

Are these frequencies computed from real usage data? Or do we need to create a ticket to update them once this has more widespread usage?

Comment on lines +61 to +66
if rand.Float64() < 0.02 {
if err := control.AttachFilesToDraft(u, &scheduledPost.Draft); err != nil {
fmt.Println("createScheduledPost: AttachFilesToDraft error", err)
return control.UserActionResponse{Err: control.NewUserError(err)}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We should probably move this 0.02 ratio to a global constant, we're using it in many places now.

Comment on lines +137 to +143
if err := u.DeleteScheduledPost(scheduledPost.Id); err != nil {
fmt.Println("deleteScheduledPost: DeleteScheduledPost error", err)
return control.UserActionResponse{Err: control.NewUserError(err)}
}

u.Store().DeleteScheduledPost(scheduledPost.Id)
return control.UserActionResponse{Info: fmt.Sprintf("scheduled post deleted with id %v", scheduledPost.Id)}
Copy link
Member

Choose a reason for hiding this comment

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

We should update the store inside the user's function.

return control.UserActionResponse{Info: fmt.Sprintf("scheduled post deleted with id %v", scheduledPost.Id)}
}

func (c *SimulController) sendScheduledPost(u user.User) control.UserActionResponse {
Copy link
Member

Choose a reason for hiding this comment

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

Let me see if I understood this action: it forces a post that was scheduled for the future to be sent immediately. If that's correct, could we come up with an action name that conveys that? Something like sendScheduledPostNow or similar? Or maybe adding a comment, if that's not clear enough.

Comment on lines +176 to +181
if err := u.DeleteScheduledPost(scheduledPost.Id); err != nil {
fmt.Println("sendScheduledPost: DeleteScheduledPost error", err)
return control.UserActionResponse{Err: control.NewUserError(err)}
}

u.Store().DeleteScheduledPost(scheduledPost.Id)
Copy link
Member

Choose a reason for hiding this comment

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

Same here: we should update the store inside the user's DeleteScheduledPost function

Comment on lines +497 to +507
func (s *MemStore) DeleteScheduledPost(scheduledPostID string) {
s.lock.Lock()
defer s.lock.Unlock()

for teamId := range s.scheduledPosts {
if _, ok := s.scheduledPosts[teamId][scheduledPostID]; ok {
delete(s.scheduledPosts[teamId], scheduledPostID)
break
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we know the team ID when deleting the post? We could skip the outer loop if we do.

Comment on lines +25 to +28
id := scheduledPost.ChannelId
if createdScheduledPost.RootId != "" {
id = scheduledPost.RootId
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this ChannelId? Does this mean that we can schedule a single post per channel? This happens in UpdateScheduledPost as well.

Comment on lines +93 to +101
for teamIdInResponse := range scheduledPostsByTeam {
for _, scheduledPost := range scheduledPostsByTeam[teamIdInResponse] {
err := ue.store.SetScheduledPost(teamID, scheduledPost.Id, scheduledPost)
if err != nil {
fmt.Println("GetTeamScheduledPosts: SetScheduledPost error", err)
return err
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I didn't understand this code, so I took a look at the server code and saw that we use directChannels as a special team ID here to get posts scheduled in DMs. Is this something that can break some assumptions elsewhere in this code? I suppose no, but wanted to double-check.
Nit: also, should we add a ue.store.SetScheduledPostsInTeam so that we can pass it the whole slice of posts?

RootId: rootId,
CreateAt: model.GetMillis(),
},
ScheduledAt: loadtest.RandomFutureTime(17_28_00_000, 10),
Copy link
Member

Choose a reason for hiding this comment

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

What does 17_28_00_000 mean?

@@ -87,3 +89,19 @@ func nextPowerOf2(val int) int {
val++
return val
}

// RandomFutureTime generates a random time between (now + xMilliseconds) to (now + xDays) in Unix milliseconds.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can we use the name of the variables themselves? It took me a while to understand the comment

Suggested change
// RandomFutureTime generates a random time between (now + xMilliseconds) to (now + xDays) in Unix milliseconds.
// RandomFutureTime generates a random time between (now + millisecondsFromNow) to (now + uptoDaysFromNow) in Unix milliseconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants