Repository navigation
chore: enhance rsources stats collector with component tagging and error handling #6124
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
889cf54
chore: enhance rsources stats collector with component tagging and er…
mihir20 9f8bbbe
feat(buckets): add rsources_publish_time_second metrics to bucket con…
mihir20 065a62f
fix(handler): handle error correctly when inserting into rsources_stats
mihir20 ba828f8
fix(handler): log error when cleanup of rsources tables fails
mihir20 ec3f46d
chore: add logging for rsources tables cleanup process
mihir20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,18 @@ import ( | |
| "sort" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/rudderlabs/rudder-go-kit/stats" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/tidwall/gjson" | ||
|
|
||
| "github.com/rudderlabs/rudder-server/jobsdb" | ||
| ) | ||
|
|
||
| const rsourcesPublishTime = "rsources_publish_time_second" | ||
|
|
||
| // StatsPublisher publishes stats | ||
| type StatsPublisher interface { | ||
| // Publish publishes statistics | ||
|
|
@@ -55,7 +60,7 @@ type FailedJobsStatsCollector interface { | |
| } | ||
|
|
||
| // NewStatsCollector creates a new stats collector | ||
| func NewStatsCollector(jobservice JobService, opts ...OptFunc) StatsCollector { | ||
| func NewStatsCollector(jobservice JobService, component string, statFactory stats.Stats, opts ...OptFunc) StatsCollector { | ||
| sc := &statsCollector{ | ||
| jobService: jobservice, | ||
| jobIdsToStatKeyIndex: map[int64]statKey{}, | ||
|
|
@@ -67,11 +72,12 @@ func NewStatsCollector(jobservice JobService, opts ...OptFunc) StatsCollector { | |
| for _, opt := range opts { | ||
| opt(sc) | ||
| } | ||
| sc.stats.publishTime = statFactory.NewTaggedStat(rsourcesPublishTime, stats.TimerType, stats.Tags{"module": component}) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a new metric? Do we have defined buckets for it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes its a new metric, I will add buckets for this |
||
| return sc | ||
| } | ||
|
|
||
| // NewDroppedJobsCollector creates a new stats collector for publishing failed job stats and records | ||
| func NewDroppedJobsCollector(jobservice JobService, opts ...OptFunc) FailedJobsStatsCollector { | ||
| func NewDroppedJobsCollector(jobservice JobService, component string, statFactory stats.Stats, opts ...OptFunc) FailedJobsStatsCollector { | ||
| sc := &statsCollector{ | ||
| jobService: jobservice, | ||
| jobIdsToStatKeyIndex: map[int64]statKey{}, | ||
|
|
@@ -83,6 +89,7 @@ func NewDroppedJobsCollector(jobservice JobService, opts ...OptFunc) FailedJobsS | |
| for _, opt := range opts { | ||
| opt(sc) | ||
| } | ||
| sc.stats.publishTime = statFactory.NewTaggedStat(rsourcesPublishTime, stats.TimerType, stats.Tags{"module": component}) | ||
| return sc | ||
| } | ||
|
|
||
|
|
@@ -105,6 +112,9 @@ type statsCollector struct { | |
| statsIndex map[statKey]*Stats | ||
| failedRecordsIndex map[statKey][]FailedRecord | ||
| parametersParser parametersParser | ||
| stats struct { | ||
| publishTime stats.Timer | ||
| } | ||
| } | ||
|
|
||
| func (r *statsCollector) orderedStatMapKeys() []statKey { | ||
|
|
@@ -206,6 +216,8 @@ func (r *statsCollector) Publish(ctx context.Context, tx *sql.Tx) error { | |
| if r.jobService == nil { | ||
| return fmt.Errorf("no JobService provided during initialization") | ||
| } | ||
| startTime := time.Now() | ||
|
|
||
| // sort the maps to avoid deadlocks | ||
| statKeys := r.orderedStatMapKeys() | ||
| for i := range statKeys { | ||
|
|
@@ -216,7 +228,7 @@ func (r *statsCollector) Publish(ctx context.Context, tx *sql.Tx) error { | |
| } | ||
| err := r.jobService.IncrementStats(ctx, tx, k.jobRunId, k.JobTargetKey, *v) | ||
| if err != nil { | ||
| return err | ||
| return fmt.Errorf("failed to increment stats for job %s, idx %d,: %w", k.String(), i, err) | ||
| } | ||
| } | ||
| failedRecordsKeys := r.orderedFailedRecordsKeys() | ||
|
|
@@ -229,9 +241,10 @@ func (r *statsCollector) Publish(ctx context.Context, tx *sql.Tx) error { | |
| }) | ||
| err := r.jobService.AddFailedRecords(ctx, tx, k.jobRunId, k.JobTargetKey, v) | ||
| if err != nil { | ||
| return err | ||
| return fmt.Errorf("failed to add failed records for job %s: %w", k.String(), err) | ||
| } | ||
| } | ||
| r.stats.publishTime.SendTiming(time.Since(startTime)) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How often would you say we would get these printed out? I'm asking because I'm a bit afraid of noise/pollution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not very often we are printing this everytime we create a new table. we have a log here as well