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

[WIP] Announcements and Monitoring of DST #269

Closed
wants to merge 13 commits into from
Closed

Conversation

vaibhawvipul
Copy link
Contributor

  • draft PR

@vaibhawvipul vaibhawvipul self-assigned this Apr 2, 2024
@vaibhawvipul vaibhawvipul linked an issue Apr 2, 2024 that may be closed by this pull request
internal/announcements/announce.go Outdated Show resolved Hide resolved
cmd/dst/run.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 12, 2024

Codecov Report

Attention: Patch coverage is 81.42857% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 58.62%. Comparing base (377c55b) to head (e597bea).

Files Patch % Lines
internal/announcements/announce.go 73.80% 11 Missing ⚠️
internal/announcements/monitors/taskmonitor.go 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #269      +/-   ##
==========================================
+ Coverage   58.46%   58.62%   +0.16%     
==========================================
  Files         113      115       +2     
  Lines        9775     9845      +70     
==========================================
+ Hits         5715     5772      +57     
- Misses       3693     3706      +13     
  Partials      367      367              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dtornow
Copy link
Contributor

dtornow commented Apr 18, 2024

A few suggestions:

Monitors

Make Monitor an interface with a method

  • apply(event Event)
  • status() []error

Source internal/announcements/monitor.go

Announcement

Extend the Announcement interface with a method

  • register(monitor *Monitor)

register is a Noop for Noop and adds a monitor to DstAnnouncement.

On announce, iterate over all monitors an apply the event

Note

I believe Announce and GetAnnouncements do not need to be thread safe because they can only be accessed from one thread to begin with

if this is not true, please discuss, then my mental model is incomplete

defer tm.mutex.Unlock()

// Increment event type count
tm.eventTypeCount[event.Type]++
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the right idea: When an event happens, modify a counter. When we check the monitors at the end of the run, here we want taskCreated == taskCompleted. If that check is too aggressive, at least we want to check that taskCreated >= taskCompleted

if event.Type == "TaskCreated" {
  tm.taskCreated ++
}
if event.Type == "TaskCompleted" {
  tm.taskCompleted ++
}


package announcements

type Monitors interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename the interface to Monitor instead of Monitors (to the object not the verb)

} else {
res = &http.Response{
StatusCode: http.StatusInternalServerError,
}

event := announcements.NewEvent("HTTPResponse")
Copy link
Contributor

Choose a reason for hiding this comment

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

Good!!

"github.com/resonatehq/resonate/internal/announcements"
)

type taskMonitor struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

TaskMonitor must not part of the core package for announcements and monitors, but part of the test/dst -- it's application specific

type DstAnnouncement struct {
announcements []Event
monitors []Monitors
mutex sync.Mutex // Mutex for thread safety
Copy link
Contributor

@susarlanikhilesh susarlanikhilesh May 7, 2024

Choose a reason for hiding this comment

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

Usually a better practice to have the mutex at the start of the struct.
As the struct need not calculate the offset every time to find the mutex variable inside the struct.

@vaibhawvipul vaibhawvipul removed their assignment May 7, 2024
@guergabo guergabo closed this May 23, 2024
@guergabo guergabo deleted the announcements-dst branch May 23, 2024 01:29
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.

Add Announcements
5 participants