Skip to content

Commit

Permalink
[7.17] [kbn-failed-test-reporter-cli] truncate report message to fix …
Browse files Browse the repository at this point in the history
…github api call failure (#155141) (#155285)

# Backport

This will backport the following commits from `main` to `7.17`:
- [[kbn-failed-test-reporter-cli] truncate report message to fix github
api call failure
(#155141)](#155141)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Dzmitry
Lemechko","email":"dzmitry.lemechko@elastic.co"},"sourceCommit":{"committedDate":"2023-04-19T14:39:35Z","message":"[kbn-failed-test-reporter-cli]
truncate report message to fix github api call failure (#155141)\n\n##
Summary\r\n\r\nWe recently had
a\r\n[failure](https://buildkite.com/elastic/kibana-on-merge/builds/29020#018792bc-498a-46d1-9343-fb791823d92e)\r\nwhile
calling Github API to open new issue:\r\n\r\n```\r\n2023-04-18 07:56:26
CEST\tERROR Error: [post
https://api.github.com/repos/elastic/kibana/issues] 422 Unprocessable
Entity Error: {\"message\":\"Validation
Failed\",\"errors\":[{\"resource\":\"Issue\",\"code\":\"custom\",\"field\":\"body\",\"message\":\"body
is too
long\"},{\"resource\":\"Issue\",\"code\":\"custom\",\"field\":\"body\",\"message\":\"body
is too long (maximum is 65536
characters)\"}],\"documentation_url\":\"https://docs.github.com/rest/reference/issues#create-an-issue\"}\r\n2023-04-18
07:56:26 CEST\t at GithubApi.request
(github_api.ts:177:17)\r\n2023-04-18 07:56:26 CEST\t at
processTicksAndRejections
(node:internal/process/task_queues:96:5)\r\n2023-04-18 07:56:26 CEST\t
at GithubApi.createIssue (github_api.ts:106:18)\r\n2023-04-18 07:56:26
CEST\t at createFailureIssue (report_failure.ts:39:10)\r\n2023-04-18
07:56:26 CEST\t at description
(failed_tests_reporter_cli.ts:153:28)\r\n2023-04-18 07:56:26 CEST\t at
run.ts:70:7\r\n2023-04-18 07:56:26 CEST\t at withProcRunner
(with_proc_runner.ts:29:5)\r\n2023-04-18 07:56:26 CEST\t at run
(run.ts:69:5)\r\n```\r\n\r\nIt seems like some test might have a very
long failure message that\r\nreaches Github body length limit and causes
a failure.\r\n\r\nSince mocha truncates failure message to 8192 chars, I
thought it might\r\nbe a good option for Github issues as well (Having
too long message is\r\nnot very useful
anyway)","sha":"271d9aa68cf93ae9a3d398e909a0c4fb06a409b5","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v7.17.10","v8.8.0","v8.7.2"],"number":155141,"url":"#155141
truncate report message to fix github api call failure (#155141)\n\n##
Summary\r\n\r\nWe recently had
a\r\n[failure](https://buildkite.com/elastic/kibana-on-merge/builds/29020#018792bc-498a-46d1-9343-fb791823d92e)\r\nwhile
calling Github API to open new issue:\r\n\r\n```\r\n2023-04-18 07:56:26
CEST\tERROR Error: [post
https://api.github.com/repos/elastic/kibana/issues] 422 Unprocessable
Entity Error: {\"message\":\"Validation
Failed\",\"errors\":[{\"resource\":\"Issue\",\"code\":\"custom\",\"field\":\"body\",\"message\":\"body
is too
long\"},{\"resource\":\"Issue\",\"code\":\"custom\",\"field\":\"body\",\"message\":\"body
is too long (maximum is 65536
characters)\"}],\"documentation_url\":\"https://docs.github.com/rest/reference/issues#create-an-issue\"}\r\n2023-04-18
07:56:26 CEST\t at GithubApi.request
(github_api.ts:177:17)\r\n2023-04-18 07:56:26 CEST\t at
processTicksAndRejections
(node:internal/process/task_queues:96:5)\r\n2023-04-18 07:56:26 CEST\t
at GithubApi.createIssue (github_api.ts:106:18)\r\n2023-04-18 07:56:26
CEST\t at createFailureIssue (report_failure.ts:39:10)\r\n2023-04-18
07:56:26 CEST\t at description
(failed_tests_reporter_cli.ts:153:28)\r\n2023-04-18 07:56:26 CEST\t at
run.ts:70:7\r\n2023-04-18 07:56:26 CEST\t at withProcRunner
(with_proc_runner.ts:29:5)\r\n2023-04-18 07:56:26 CEST\t at run
(run.ts:69:5)\r\n```\r\n\r\nIt seems like some test might have a very
long failure message that\r\nreaches Github body length limit and causes
a failure.\r\n\r\nSince mocha truncates failure message to 8192 chars, I
thought it might\r\nbe a good option for Github issues as well (Having
too long message is\r\nnot very useful
anyway)","sha":"271d9aa68cf93ae9a3d398e909a0c4fb06a409b5"}},"sourceBranch":"main","suggestedTargetBranches":["7.17","8.7"],"targetPullRequestStates":[{"branch":"7.17","label":"v7.17.10","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"#155141
truncate report message to fix github api call failure (#155141)\n\n##
Summary\r\n\r\nWe recently had
a\r\n[failure](https://buildkite.com/elastic/kibana-on-merge/builds/29020#018792bc-498a-46d1-9343-fb791823d92e)\r\nwhile
calling Github API to open new issue:\r\n\r\n```\r\n2023-04-18 07:56:26
CEST\tERROR Error: [post
https://api.github.com/repos/elastic/kibana/issues] 422 Unprocessable
Entity Error: {\"message\":\"Validation
Failed\",\"errors\":[{\"resource\":\"Issue\",\"code\":\"custom\",\"field\":\"body\",\"message\":\"body
is too
long\"},{\"resource\":\"Issue\",\"code\":\"custom\",\"field\":\"body\",\"message\":\"body
is too long (maximum is 65536
characters)\"}],\"documentation_url\":\"https://docs.github.com/rest/reference/issues#create-an-issue\"}\r\n2023-04-18
07:56:26 CEST\t at GithubApi.request
(github_api.ts:177:17)\r\n2023-04-18 07:56:26 CEST\t at
processTicksAndRejections
(node:internal/process/task_queues:96:5)\r\n2023-04-18 07:56:26 CEST\t
at GithubApi.createIssue (github_api.ts:106:18)\r\n2023-04-18 07:56:26
CEST\t at createFailureIssue (report_failure.ts:39:10)\r\n2023-04-18
07:56:26 CEST\t at description
(failed_tests_reporter_cli.ts:153:28)\r\n2023-04-18 07:56:26 CEST\t at
run.ts:70:7\r\n2023-04-18 07:56:26 CEST\t at withProcRunner
(with_proc_runner.ts:29:5)\r\n2023-04-18 07:56:26 CEST\t at run
(run.ts:69:5)\r\n```\r\n\r\nIt seems like some test might have a very
long failure message that\r\nreaches Github body length limit and causes
a failure.\r\n\r\nSince mocha truncates failure message to 8192 chars, I
thought it might\r\nbe a good option for Github issues as well (Having
too long message is\r\nnot very useful
anyway)","sha":"271d9aa68cf93ae9a3d398e909a0c4fb06a409b5"}},{"branch":"8.7","label":"v8.7.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>
  • Loading branch information
kibanamachine and dmlemeshko committed Apr 21, 2023
1 parent 9869dd1 commit 6f79ab0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/kbn-test/src/failed_tests_reporter/report_failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ export async function createFailureIssue(
) {
const title = `Failing test: ${failure.classname} - ${failure.name}`;

// Github API body length maximum is 65536 characters
// Let's keep consistency with Mocha output that is truncated to 8192 characters
const failureMaxCharacters = 8192;

const failureBody =
failure.failure.length <= failureMaxCharacters
? failure.failure
: [
failure.failure.substring(0, failureMaxCharacters),
`[report_failure] output truncated to ${failureMaxCharacters} characters`,
].join('\n');

const body = updateIssueMetadata(
[
'A test failed on a tracked branch',
'',
'```',
failure.failure,
failureBody,
'```',
'',
`First failure: [CI Build - ${branch}](${buildUrl})`,
Expand Down

0 comments on commit 6f79ab0

Please sign in to comment.