Skip to content

Log spout timeouts with the root id and the spout task - #9302

Open
dpol1 wants to merge 1 commit into
apache:masterfrom
dpol1:message-timeout-report
Open

dpol1 wants to merge 1 commit into
apache:masterfrom
dpol1:message-timeout-report

Conversation

@dpol1

@dpol1 dpol1 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What is the purpose of the change

When Storm calls fail() on a spout, the spout receives the message id and nothing else. A tuple tree that timed out and a tuple that a bolt failed reach the spout through the same fail() call. In a StormCrawler crawl the message id can be the URL, so fail() cannot say whether that URL timed out or a bolt failed it. STORM-154 (#3996) asked for this distinction. Its JIRA entry was opened in 2013.

Today topology.debug: true logs the reason at INFO, along with a line for every spout ack and for every tuple a bolt executes. A tracer set with topology.tracing.tracer also receives TIMEOUT or FAIL, for tuple trees that carry a trace context.

This PR adds a log line for a spout timeout, off by default:

timeout root=00000000075bcd15 task=7 component=url-spout id="https://example.org/a"
  1. root is the id of the tuple tree that timed out. A replay of the same URL is a new emit and gets a new random id.
  2. task and component name the spout task that emitted the tree. They identify only the origin of the tree.
  3. id is the message id when it is a String, and it is always the last field. Any other type is written id=<not supported>.

Turning it on. Set it in the topology configuration. The default is disabled.

topology.message.timeout.report: timeout-events

Finding the line for a URL. Search the log of the spout's worker for part of the id, or for the whole token root=00000000075bcd15. Other Storm logs print root ids in decimal.

An explicit fail. When a bolt fails the tuple and the fail reaches the spout before the timeout, the reporter writes no line for that root.

How it works.

  1. The spout executor queues each timeout. One reporter thread per worker writes the queued timeouts at INFO.
  2. The spout still receives fail() while the reporter is blocked writing a timeout line.
  3. The queue has 1024 slots. When it is full, the line of a new timeout is dropped and counted, and a summary line gives the count:
summary events_dropped=3

What a missing line means. A timeout can leave no line for its root, for example when the queue was full or the reporter's logger is set to WARN or higher. That level also hides the summary lines. The docs list the other cases.

The report works with tuple tracing disabled. docs/Message-timeout-report.md in this diff has the rest: the escapes, the truncation of long ids, the counters.

TL;DR. An opt-in log line that says "this tuple tree timed out" and carries the message id when it is a String. The configuration key and the line format become public on release, so I'd welcome feedback on both now.

How was the change tested

  • The 15 tests in MessageTimeoutReporterTest cover the line format, escaping and truncation of ids, a full queue, summaries, log write exceptions and reporter thread failures.
  • SpoutExecutorTest checks that the executor still calls spout.fail() on timeout after an exception stops the reporter thread.
  • TestConfigValidate checks the two accepted values and the disabled default.
  • MessageTimeoutReportTest runs three cases on a LocalCluster. In the first, a spout timeout produces a line with the root, spout task and URL, and an explicit fail that reaches the spout before the timeout produces no timeout line for that root. In the second, with the default settings, the worker starts no reporter thread and writes no report. In the third, the reporter is blocked writing the first timeout line while the spout receives fail() for a second URL.
  • On a clean clone of this commit, RAT and Checkstyle passed. The storm-client, storm-server and storm-opentelemetry suites finished with zero failures or errors. Four client tests and one server test were skipped.

cc @GGraziadei @rzo1 @reiabreu

When a tuple tree times out, the spout executor calls ISpout.fail()
with the message id only, so the spout cannot tell a timeout from an
explicit fail. With topology.message.timeout.report set to
timeout-events (the default is disabled), the worker logs the timeouts
of its spouts:

  timeout root=00000000075bcd15 task=7 component=url-spout id="https://example.org/a"

At INFO, the first word names the line type. root is the id of the tuple
tree as 16 hexadecimal digits. task and component name the spout task
that emitted the tree. id is the message id when it is a String, and it
is always the last field; any other type is written id=<not supported>,
and the reporter calls no method of it. An explicit fail that reaches
the spout before the timeout writes nothing.

The spout executor hands the event to MessageTimeoutReporter before it
calls ISpout.fail(). All spouts of a worker share one queue of 1024
events, and a daemon thread of the reporter writes them at INFO, so a
blocked log does not hold the spout. An event that finds the queue full
is counted and dropped before it is formatted. Each cycle of the thread
writes up to 1024 queued events, then the counters that changed since
the last summary whose logging call returned, and waits one second:

  summary events_dropped=3

Backslash, control, format, line separator, paragraph separator and
unpaired surrogate characters in a message id become escapes such as
\u{a}. An id whose escaped form exceeds 1024 UTF-16 units is cut and
marked with truncated=true originalLength=N, which counts toward the
same 1024 units. A component id is cut at 64 units, with a space
written as an escape too.

A log call that throws is counted as write_failed and the report goes
on. A RuntimeException that escapes a cycle of the reporter's thread
turns the report off until the worker restarts; the reporter then makes
one attempt to log this at ERROR. An Error reaches the uncaught
exception handler. With the report disabled, the worker creates no
reporter and the expiry path tests one field.

docs/Message-timeout-report.md describes the lines, their limits and
how to read them.
* {@code org.apache.storm.daemon.worker.MessageTimeoutReporter} at INFO. With {@code disabled}, the default,
* nothing is reported.
*/
@IsString(acceptedValues = {"disabled", "timeout-events"})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A string so we can add another mode later without a second key. Happy to make it a boolean if you prefer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have a prototype that also logs deliveries a bvolt hels past the timeout, proposing later :)


/** Fixed width, so that a whole token is never the prefix of another root's token. */
static String rootToken(long rootId) {
return "root=" + HexFormat.of().toHexDigits(rootId);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I picked hex to get a fixed width and no sign. topology.debug prints the root in decimal though, so happy to switch if you prefer that.

/** Returns the {@code id} field of an event, after the truncation fields when the id is cut. */
static String idField(Object messageId) {
if (!(messageId instanceof String id)) {
return "id=<not supported>";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This runs on the spout executor's thread, so I didn't want to call toString() on a class I know nothing about. It means Kafka spout ids show up as <not supported>, so I'm open to ideas.

@Override
public void expire(Long key, TupleInfo tupleInfo) {
if (timeoutReporter != null) {
timeoutReporter.timedOut(key, tupleInfo.getTaskId(), componentId, tupleInfo.getMessageId());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Another option would be a reason on SpoutFailInfo for task hooks. Would you prefer that?

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.

1 participant