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

KAFKA-7906: Improve logging for failed leader elections #8176

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

agam
Copy link
Contributor

@agam agam commented Feb 26, 2020

  • Log election errors within the kafka.controller class hierarchy instead of within state.changed.logger
  • Log failure reason when present
  • Verified existing tests pass

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@agam agam force-pushed the improve-failed-election-logging branch from 45e9557 to cb25ec3 Compare February 26, 2020 21:34
Copy link
Contributor

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

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

Thanks for the patch. Left some comments.

""
}
logger.error(s"Controller $controllerId epoch ${controllerContext.epoch} failed to "
+ s" change state for partition $partition from ${partitionState(partition)} "
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra space at the start

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

} else {
""
}
logger.error(s"Controller $controllerId epoch ${controllerContext.epoch} failed to "
Copy link
Contributor

@hachikuji hachikuji Mar 4, 2020

Choose a reason for hiding this comment

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

The controllerId is already included in logIdent. Perhaps we could add controller epoch to logIdent as well and remove it from log lines where it appears unnecessarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Went through the other log messages in the file, the rest are passed through StateChangeLogger (which has its own logIdent, so the id and epoch are useful there)

}
logger.error(s"Controller $controllerId epoch ${controllerContext.epoch} failed to "
+ s" change state for partition $partition from ${partitionState(partition)} "
+ s"to $OnlinePartition $reasonMsg", e)
Copy link
Contributor

Choose a reason for hiding this comment

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

With this change we'll actually see the exception message twice since we are still including it in the call to error. Would it be worthwhile to check for StateChangeFailedException separately? Perhaps we can print the stack trace only when it is an unexpected exception type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added separate cases for StateChangeFailedException and others.

logFailedStateChange(partition, partitionState(partition), OnlinePartition, e)
// Extract failure message, if present, to append to error log.
val reasonMsg = if (e.isInstanceOf[StateChangeFailedException]) {
s", reason: ${e.getMessage}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be simpler to move this into the check below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

} else {
""
}
val failMsg = s"Controller failed to change state for partition $partition from ${partitionState(partition)} to $OnlinePartition"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since the log identity already starts with "Controller," I think we can leave it out and start from "Failed."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

""
}
val failMsg = s"Controller failed to change state for partition $partition from ${partitionState(partition)} to $OnlinePartition"
if (e.isInstanceOf[StateChangeFailedException]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a match is considered better style. For example:

match {
  case e: StateChangeFailedException => ...
  case _ => ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, did the equivalent

e match {
  case _:StateChangeFailedException => ...
  case _ => ...
}

// Extract failure message, if present, to append to error log.
val failMsg = s"Failed to change state for partition $partition from ${partitionState(partition)} to $OnlinePartition"
e match {
case _:StateChangeFailedException => logger.error(s"$failMsg, reason: ${e.getMessage}")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add space after colon. Also, you can use error instead of logger.error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants