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

feat(crons): initial cron support #661

Merged
merged 14 commits into from
Jul 18, 2023

Conversation

Comment on lines +416 to +417
// CaptureCheckIn captures a check in.
func (client *Client) CaptureCheckIn(checkIn *CheckIn, monitorConfig *MonitorConfig, scope EventModifier) *EventID {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a discussion in Discord (#off-topic) between me and @cleptric about what function name to implement (as the PHP and Node implementation is quite different), where Michi suggested to follow the PHP implementation as the event is the check in already. As for Go SDK, if this implementation folows PHP's, this would be something like:

event := &sentry.Event{
 // fill payloads
}

event.SetCheckIn(checkInPayload)

eventId :=  sentry.CaptureEvent(event)

It's kind of awkward and confusing for me, so I went ahead with the CaptureCheckIn as a method of Client struct.

interfaces.go Outdated
Comment on lines 321 to 325
// The fields below are only relevant for crons/check ins

CheckInID string `json:"check_in_id,omitempty"`
CheckIn *CheckIn `json:"check_in,omitempty"`
MonitorConfig *MonitorConfig `json:"monitor_config,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I follow how transactions are keeping their data, it would mean that every entry on CheckIn would be spread out and might mess with other fields in the future, so I keep it enclosed here with omitempty tag.

interfaces.go Outdated
Comment on lines 474 to 480
if e.MonitorConfig != nil {
checkIn.MonitorConfig = &MonitorConfig{}
checkIn.MonitorConfig.Schedule = e.MonitorConfig.Schedule
checkIn.MonitorConfig.CheckInMargin = e.MonitorConfig.CheckInMargin
checkIn.MonitorConfig.MaxRuntime = e.MonitorConfig.MaxRuntime
checkIn.MonitorConfig.Timezone = e.MonitorConfig.Timezone
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I know it looks bad. It's 10 PM on Tuesday and I can't think of anything better right now. So sorry 🙈

@tonyo
Copy link
Contributor

tonyo commented Jul 5, 2023

Thanks @aldy505 , we'll have a look this/next week 👍

@tonyo tonyo self-assigned this Jul 10, 2023
@codecov
Copy link

codecov bot commented Jul 10, 2023

Codecov Report

Patch coverage: 86.48% and project coverage change: +0.20 🎉

Comparison is base (b6dfea7) 80.49% compared to head (5c43228) 80.70%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #661      +/-   ##
==========================================
+ Coverage   80.49%   80.70%   +0.20%     
==========================================
  Files          42       44       +2     
  Lines        4333     4416      +83     
==========================================
+ Hits         3488     3564      +76     
- Misses        717      724       +7     
  Partials      128      128              
Impacted Files Coverage Δ
sentry.go 29.31% <0.00%> (-1.60%) ⬇️
check_in.go 73.33% <73.33%> (ø)
hub.go 86.50% <75.00%> (-0.74%) ⬇️
client.go 87.92% <100.00%> (+0.88%) ⬆️
interfaces.go 93.30% <100.00%> (+0.72%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@tonyo tonyo left a comment

Choose a reason for hiding this comment

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

Overall looking good 👍
Left some comments, but nothing super major.

sentry.go Outdated Show resolved Hide resolved
hub.go Outdated Show resolved Hide resolved
client.go Outdated
// CaptureCheckIn captures a check in.
func (client *Client) CaptureCheckIn(checkIn *CheckIn, monitorConfig *MonitorConfig, scope EventModifier) *EventID {
event := client.EventFromCheckIn(checkIn, monitorConfig)
return client.processEvent(event, nil, scope)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's maybe make it consistent with other Client.Capture* methods.

Suggested change
return client.processEvent(event, nil, scope)
return client.CaptureEvent(event, nil, scope)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll have to reread the code before committing the suggested changes. I don't remember if it's okay to call that method from here.

check_in.go Show resolved Hide resolved
check_in.go Show resolved Hide resolved
check_in.go Outdated Show resolved Hide resolved
client_test.go Show resolved Hide resolved
interfaces.go Outdated Show resolved Hide resolved
check_in.go Outdated Show resolved Hide resolved
check_in.go Outdated Show resolved Hide resolved
aldy505 and others added 5 commits July 10, 2023 19:12
Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
@aldy505 aldy505 requested a review from tonyo July 16, 2023 01:18
@aldy505
Copy link
Contributor Author

aldy505 commented Jul 17, 2023

I'll address any errors on CI in a few hours.

@tonyo
Copy link
Contributor

tonyo commented Jul 17, 2023

Failures on Windows can be ignored for now, seems like it's only a test that has been flaky recently.

// The status of the check-in.
Status CheckInStatus `json:"status"`
// The duration of the check-in. Will only take effect if the status is ok or error.
Duration time.Duration `json:"duration,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

What I realized is that we don't have an option to pass an existing CheckInID via CheckIn now.
At the moment we basically create a new CheckInID every time, so there's no way to link the "in-progress" and "ok"/"error" status.
Could you handle this case please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I might want to add a test case for this one, or an example.

@tonyo
Copy link
Contributor

tonyo commented Jul 17, 2023

Another thing that we'll have to do eventually is to update the docs, basically adding Go to this list: https://docs.sentry.io/product/crons/getting-started/
@aldy505 let us know if you're ready to contribute to the docs too; that'd speed up the release/adoption of the feature.

@tonyo tonyo merged commit 4b3a135 into getsentry:master Jul 18, 2023
@tonyo
Copy link
Contributor

tonyo commented Jul 18, 2023

Thanks a lot @aldy505 👍 🎉

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.

Cron implementation
3 participants