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

tracing: use byte-limits for logs/structured events per span #61359

Merged
merged 2 commits into from
Mar 5, 2021

Conversation

irfansharif
Copy link
Contributor

@irfansharif irfansharif commented Mar 2, 2021

Touches #59188. Follow-on work from #60678. We can introduce byte-limits for
verbose logging and structured events, instead of limiting things based on
count.

This PR also:

  • adds a _dropped tag to recordings with dropped logs/structured events.
  • squashes a bug where reset spans (as used in SessionTracing) still
    held onto earlier structured events
  • moves away from the internal usage of the opentracing.LogRecord type,
    it's unnecessary

Release justification: low risk, high benefit changes to existing
functionality

Release note: None


+cc @knz / @erikgrinaker / @angelapwen for pod-visibility.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@irfansharif irfansharif requested a review from tbg March 2, 2021 19:14
@irfansharif irfansharif force-pushed the 210302.tracing-mem-limits branch from ec4eefe to 5b72a34 Compare March 3, 2021 02:34
@irfansharif irfansharif changed the title tracing: use byte-limits for structured events per span tracing: use byte-limits for logs/structured events per span Mar 3, 2021
@tbg tbg self-requested a review March 3, 2021 15:32
Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @irfansharif and @tbg)


pkg/util/tracing/crdbspan.go, line 259 at r2 (raw file):

	}

	s.mu.recording.structured.AddFirst(item)

Why is this going in the opposite direction? It looks like for messages, you add via AddLast and you remove via RemoveFirst which is also the order I expect. Here you reverse the order, adding to the front and removing from the back. Shouldn't they be the same to keep things simple? The intention in both cases is to drop the oldest things to make room for the new thing, right? I think there's also an optimization that applies chiefly to verbose logs but that we might as well apply to both (and perhaps factor out the code to be shared?): when an incoming msg alone blows the limit, we want to drop it. So we'd compare item.Size() against maxStructuredBytesPerSpan and and if it's bigger, discard it right there. The current code will lead to dropping all existing data and then holding on to a potentially very large blob, which is not what we want.

Can you mention on RecordStructured that payloads may be dropped subject to size constraints? Don't think it needs to be much more precise than that. Similar for Record{,f}.

Also, on GetRecording, this is also good to mention and you can reference the _dropped tag.

@irfansharif irfansharif force-pushed the 210302.tracing-mem-limits branch from 5b72a34 to c86ce89 Compare March 3, 2021 17:43
Copy link
Contributor Author

@irfansharif irfansharif 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 @tbg)


pkg/util/tracing/crdbspan.go, line 259 at r2 (raw file):

Also, on GetRecording, this is also good to mention and you can reference the _dropped tag.

Done.

Can you mention on RecordStructured that payloads may be dropped subject to size constraints? Don't think it needs to be much more precise than that. Similar for Record{,f}.

Done.

Why is this going in the opposite direction? [...] The intention in both cases is to drop the oldest things to make room for the new thing, right?

In both cases we drop the oldest thing and keep the newest. The reversal in order just stemmed from what the iteration over the ring buffer when materializing its contents (during GetRecording) looked like. For logs, I wanted the oldest log to appear first. For structured events, I wanted the opposite. I guess that's not really that important? We probably want to have timestamps associated with structured events if we care about ordering, so I've simplified for now.

we'd compare item.Size() against maxStructuredBytesPerSpan and and if it's bigger, discard it right there.

Done.

perhaps factor out the code to be shared?

Done (now using the same limit for both verbose + structured events).

@irfansharif
Copy link
Contributor Author

The test flakes are due because different log messages have different sizes - seeing as how they embed a timestamp. Heading into a block of meetings but after I'll add a testing knob to pin the timestamp for logs which should get rid of the issue.

@tbg tbg mentioned this pull request Mar 4, 2021
@tbg tbg self-requested a review March 4, 2021 16:30
Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

:lgtm: but I think we should keep the ringbufs separate due to the more complex semantics the sharing introduces.

Reviewed 5 of 5 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @irfansharif and @tbg)


pkg/util/tracing/tracer.go, line 46 at r3 (raw file):

	// maxRecordedBytesPerSpan limits the size of logs and structured in a span;
	// use a comfortable limit.
	maxRecordedBytesPerSpan = 10 * (1 << 10) // 10 KiB

I wonder if this should be set significantly higher. For payloads only, and for their current usage, I would agree that 10 KiB is enough (though this would likely exclude contention events on some tables with large primary keys). But now we are sharing the combined buffer and so something like 256KiB is perhaps more appropriate. Concretely, I am worried about statement bundles which contain a verbose trace. Since we're not introducing a knob here (should we?) it could happen that the "interesting" part of the trace gets truncated away (though hopefully the eviction policy will keep the interesting part in most cases).

I wasn't actually thinking about merging the byte limits together. I thought it was a good idea to keep them separate. It could make sense to budget up to 256KiB for log messages and 10KiB for payloads. The current code has weird properties. For example, if you have 1KiB in payloads but 8.9999KiB in verbose messages, and another payload comes in, you'll throw out an existing payload rather than evict some old log messages, but then you will actually add the payload and still end up at >10KiB (though I guess at most at 19.999KiB). Things are easier when they are kept separate. If we had to prioritize, we'd likely prefer dropping verbose messages over payloads in all cases. But I don't want to get into that now (or probably ever), so using two buffers seems more appropriate.

Touches cockroachdb#59188. Follow-on work from cockroachdb#60678.

Release justification: low risk, high benefit changes to existing
functionality

Release note: None
@irfansharif irfansharif force-pushed the 210302.tracing-mem-limits branch from 5ce004a to 5689c75 Compare March 5, 2021 16:58
Copy link
Contributor Author

@irfansharif irfansharif left a comment

Choose a reason for hiding this comment

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

but I think we should keep the ringbufs separate due to the more complex semantics the sharing introduces.

Done. Thanks for reviewing!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @tbg)


pkg/util/tracing/tracer.go, line 46 at r3 (raw file):

It could make sense to budget up to 256KiB for log messages and 10KiB for payloads

Done.

@craig
Copy link
Contributor

craig bot commented Mar 5, 2021

Build failed (retrying...):

Touches cockroachdb#59188. We can introduce byte-limits for verbose logging
messages in a similar manner to what we've done for structured events.

This commit also:
- adds a _dropped tag to recordings with dropped logs/structured events.
- squashes a bug where reset spans (as used in SessionTracing) still
  held onto earlier structured events
- moves away from the internal usage of the opentracing.LogRecord type,
  it's unnecessary

Release justification: low risk, high benefit changes to existing
functionality

Release note: None
@irfansharif irfansharif force-pushed the 210302.tracing-mem-limits branch from 5689c75 to 2b71afb Compare March 5, 2021 17:50
@craig
Copy link
Contributor

craig bot commented Mar 5, 2021

Canceled.

@irfansharif
Copy link
Contributor Author

bors r+

@craig craig bot merged commit 2264789 into cockroachdb:master Mar 5, 2021
@craig
Copy link
Contributor

craig bot commented Mar 5, 2021

Build succeeded:

@irfansharif irfansharif deleted the 210302.tracing-mem-limits branch March 5, 2021 21:10
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