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

stmtdiagnostics: remove conditional request from registry after completion #89131

Merged
merged 1 commit into from
Oct 3, 2022

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Sep 30, 2022

Previously, we had a minor bug in how we handle the conditional
diagnostics requests when we got a bundle that satisfied the condition - we
correctly updated the corresponding system table, but we forgot to remove
the request from the local registry. As a result, we would continue
collecting conditional bundles until the local node polls the system
table and updates its registry (every 10 seconds by default). This
commit fixes that issue. Additionally, this commit updates the tests to
enforce that the in-memory registry doesn't contain completed requests.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich force-pushed the stmt-diag-remove branch 2 times, most recently from 3dc64fe to 6cbd7c5 Compare October 1, 2022 00:19
@yuzefovich yuzefovich marked this pull request as ready for review October 1, 2022 00:23
@yuzefovich yuzefovich requested review from irfansharif and a team October 1, 2022 00:23
expired := req.isExpired(timeutil.Now())
shouldRemove := expired
defer func() {
if shouldRemove {
Copy link
Contributor

Choose a reason for hiding this comment

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

[tiny nit] Make this if !shouldRemove { return } to outdent the block below.

// the logic of RemoveOngoing.
// latency satisfies the request's condition. The request is automatically
// removed from the registry (unless the continuous collection is enabled and
// the request hasn't expired).
Copy link
Contributor

Choose a reason for hiding this comment

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

This inlining of logic (before this PR) reads confusingly. Can it be pulled out into the one caller instead?

func (r *Registry) IsExecLatencyConditionMet(
requestID RequestID, req Request, execLatency time.Duration,
) bool {
expired := req.isExpired(timeutil.Now())
Copy link
Contributor

Choose a reason for hiding this comment

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

[tiny nit] Skip this holdover variable expired, it's used just once below.

// continueCollecting returns true if we want to continue collecting bundles for
// this request. Notably it doesn't check whether the request has expired.
func (r *Request) continueCollecting(st *cluster.Settings) bool {
return collectUntilExpiration.Get(&st.SV) && r.samplingProbability != 0 && !r.expiresAt.IsZero()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm to blame for this unfortunate leakage. Is there a way to assert closer to where samplingProbability is set that expiresAt is non-zero? (Or is that already done?)) That way this validation code doesn't have to leak elsewhere.

…etion

Previously, we had a minor bug in how we handle the conditional
diagnostics requests when we got a bundle that satisfied the condition - we
correctly updated the corresponding system table, but we forgot to remove
the request from the local registry. As a result, we would continue
collecting conditional bundles until the local node polls the system
table and updates its registry (every 10 seconds by default). This
commit fixes that issue. Additionally, this commit updates the tests to
enforce that the in-memory registry doesn't contain completed requests.

Release note: None
Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @irfansharif)


pkg/sql/stmtdiagnostics/statement_diagnostics.go line 134 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

I'm to blame for this unfortunate leakage. Is there a way to assert closer to where samplingProbability is set that expiresAt is non-zero? (Or is that already done?)) That way this validation code doesn't have to leak elsewhere.

Actually the leakage was pre-existing - it was introduced when we added the conditional diagnostics about a year ago.


pkg/sql/stmtdiagnostics/statement_diagnostics.go line 422 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

This inlining of logic (before this PR) reads confusingly. Can it be pulled out into the one caller instead?

Done.


pkg/sql/stmtdiagnostics/statement_diagnostics.go line 426 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

[tiny nit] Skip this holdover variable expired, it's used just once below.

Done.


pkg/sql/stmtdiagnostics/statement_diagnostics.go line 429 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

[tiny nit] Make this if !shouldRemove { return } to outdent the block below.

Refactored.

@yuzefovich
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 3, 2022

Build succeeded:

@craig craig bot merged commit fca6c42 into cockroachdb:master Oct 3, 2022
@yuzefovich yuzefovich deleted the stmt-diag-remove branch October 3, 2022 21:43
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