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

chore: gateway stores singular event batches #3256

Merged
merged 10 commits into from
May 29, 2023

Conversation

Sidddddarth
Copy link
Member

@Sidddddarth Sidddddarth commented Apr 29, 2023

Description

gateway opens a batch of event, stores each event inside as its own batch.

gateway receives:

{
  "batch": [
    {event-1},
    {event-2}
  ]
}

gateway stores:

jobid - 1:
{
  "batch": [
    {event-1}
  ]
}

jobid - 2:
{
  "batch": [
    {event-2}
  ]
}

Tangential to another PR where gateway simply stores the singular event to gateway table.
The current approach avoids changing things at processor, and does not bear the burden of transitioning from previous behaviour which is evident from the other PR.

Notion Ticket

relevant slack thread

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@Sidddddarth Sidddddarth changed the title Chore.gw store singular batch chore: gateway stores singular event batches Apr 29, 2023
@Sidddddarth Sidddddarth force-pushed the chore.gwStoreSingularBatch branch 3 times, most recently from 5e0c2dc to 2ff4893 Compare May 2, 2023 12:11
@codecov
Copy link

codecov bot commented May 2, 2023

Codecov Report

Patch coverage: 67.45% and project coverage change: +0.11 🎉

Comparison is base (3f88f50) 68.46% compared to head (619e20e) 68.58%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3256      +/-   ##
==========================================
+ Coverage   68.46%   68.58%   +0.11%     
==========================================
  Files         329      329              
  Lines       52742    52778      +36     
==========================================
+ Hits        36109    36196      +87     
+ Misses      14301    14252      -49     
+ Partials     2332     2330       -2     
Impacted Files Coverage Δ
jobsdb/jobsdb.go 74.61% <44.61%> (+1.03%) ⬆️
gateway/gateway.go 75.98% <78.88%> (-0.29%) ⬇️
gateway/configuration.go 96.42% <100.00%> (+0.06%) ⬆️
processor/processor.go 87.53% <100.00%> (+0.86%) ⬆️
processor/worker.go 94.11% <100.00%> (+15.68%) ⬆️

... and 8 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.

@Sidddddarth Sidddddarth force-pushed the chore.gwStoreSingularBatch branch 2 times, most recently from cd416aa to 59989e2 Compare May 3, 2023 08:16
@Sidddddarth Sidddddarth marked this pull request as ready for review May 3, 2023 09:04
gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
Comment on lines 710 to 730
EventCount: 1,
WorkspaceId: workspaceId,
Copy link
Member

Choose a reason for hiding this comment

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

Should we also populate the payload size field?

Suggested change
EventCount: 1,
WorkspaceId: workspaceId,
EventCount: 1,
PayloadSize: len(payload),
WorkspaceId: workspaceId,

Also, we might want to populate the userID of the payload instead of firstUserID. Although it breaks compatibility with our current approach and might introduce performance downsides.
.

Copy link
Member Author

Choose a reason for hiding this comment

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

True
We consider each individual event's userID for suppression purposes anyway.
Elaborate further on the performance downsides.. I don't see a drastic effect due to this at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

adopted👍

gateway/gateway.go Outdated Show resolved Hide resolved
@atzoum
Copy link
Contributor

atzoum commented May 8, 2023

Would it be easy to introduce this behaviour behind a configuration flag (enabled by default), i.e. be able to disable it in case we observed any undesired side-effects?

gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
@Sidddddarth Sidddddarth force-pushed the chore.gwStoreSingularBatch branch 2 times, most recently from ecf9b40 to 2d3c18b Compare May 16, 2023 10:55
jobsdb/jobsdb.go Outdated
Comment on lines 2992 to 2904
var (
err error
res map[uuid.UUID]string
)
storeCmd := func() error {
command := func() interface{} {
dsList := jd.getDSList()
res, err = jd.internalStoreEachBatchRetryInTx(ctx, tx.Tx(), dsList[len(dsList)-1], jobBatches)
return res
}
res, _ = jd.executeDbRequest(newWriteDbRequest("store_each_batch_retry", nil, command)).(map[uuid.UUID]string)
return err
}
if tx.storeSafeTxIdentifier() != jd.Identifier() {
_ = jd.inStoreSafeCtx(ctx, storeCmd)
return res, err
}
_ = storeCmd()
return res, err
Copy link
Member

Choose a reason for hiding this comment

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

How is the error handling work in this part of the code?

As per my understanding, we always return nil and we are ignoring errors

Copy link
Member Author

Choose a reason for hiding this comment

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

assigning the error returned below to err(line#2999)
res, err = jd.internalStoreEachBatchRetryInTx(ctx, tx.Tx(), dsList[len(dsList)-1], jobBatches)

gateway/gateway.go Outdated Show resolved Hide resolved
@Sidddddarth Sidddddarth force-pushed the chore.gwStoreSingularBatch branch 4 times, most recently from 1ea52e8 to bdc167a Compare May 19, 2023 06:07
jobsdb/jobsdb.go Outdated Show resolved Hide resolved
jobsdb/jobsdb.go Outdated
if err != nil {
return failAll(err), nil
}
jd.logger.Errorf("Copy In command failed with error %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this?

gateway/gateway.go Outdated Show resolved Hide resolved
gateway/gateway.go Outdated Show resolved Hide resolved
jobsdb/jobsdb.go Outdated
if err != nil {
return failAll(err), nil
}
err = jd.internalStoreJobsInTx(ctx, tx, ds, lo.Flatten(jobBatches))
Copy link
Contributor

Choose a reason for hiding this comment

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

one side-effect of using this here is that the store_jobs metric will be published additionally to store_jobs_retry_each

Copy link
Member Author

@Sidddddarth Sidddddarth May 19, 2023

Choose a reason for hiding this comment

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

Thankfully because the table_prefix is only gateway where this happens, we can excuse this(at least while inferring job storage times from the stats, but redundant stats would still exist).
We could pull out the stat part inside internalStoreJobsInTx, and have the caller publish said stat(maybe a wrapper?)

just realised, I could simply use jd.doStoreJobsInTx(ctx, tx, ds, jobList) instead of jd.internalStoreJobsInTx.

Copy link
Collaborator

@fracasula fracasula left a comment

Choose a reason for hiding this comment

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

I'm not too comfortable with code that access slice elements returned by other functions without checking for its length, but if you're positive there's always at least one element when err is not nil then go ahead.

i.e. when you do jobIDReqMap[jobData.jobs[0].UUID] = req and jobData is returned by gateway.getJobDataFromRequest(req).

gateway/gateway_test.go Outdated Show resolved Hide resolved
@Sidddddarth
Copy link
Member Author

I'm not too comfortable with code that access slice elements returned by other functions without checking for its length, but if you're positive there's always at least one element when err is not nil then go ahead.

i.e. when you do jobIDReqMap[jobData.jobs[0].UUID] = req and jobData is returned by gateway.getJobDataFromRequest(req).

True.
Returning Invalid JSON if length is 0.

@Sidddddarth Sidddddarth merged commit 1ccec6e into master May 29, 2023
30 checks passed
@Sidddddarth Sidddddarth deleted the chore.gwStoreSingularBatch branch May 29, 2023 07:27
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.

None yet

4 participants