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

Error log in notification #176

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

EmileTrotignon
Copy link

This is add error logs for failed builds.

image

image

For know the test are broken, and I don't really understand how to work with them, help is appreciated.

@EmileTrotignon
Copy link
Author

I fixed the test suite by having an explicit Error msg in API local instead of an exception. I tried created the appropriate files first, but a lot of them were needed so I gave up.

Copy link
Collaborator

@thatportugueseguy thatportugueseguy left a comment

Choose a reason for hiding this comment

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

you need to pull the latest changes in master to your branch, a lot has changed.

We need to get logs only for the jobs we are effectively notifying, not for all failed jobs.

These logs should be in a snippet so they are collapsible. These should be present in the tests too.

a few files files need newlines at the end

dune-project Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/github.ml Outdated
Comment on lines 80 to 99
let get_logs ~ctx ~(api : (module Api.Buildkite)) (n : status_notification) =
let module Buildkite = (val api) in
let ( let* ) = Lwt_result.bind in
match n.state with
| Success | Pending -> Lwt.return_ok None
| Failure | Error ->
let* build = Buildkite.get_build ~ctx n in
let failed_jobs =
List.filter
(fun (job : Buildkite_t.job) ->
match job.state with
| Some Failed -> true
| _ -> false)
build.jobs
in
(match failed_jobs with
| [] -> Lwt.return_ok None
| _ :: _ ->
let* log = Buildkite.get_job_log ~ctx (List.hd failed_jobs) in
Lwt.return_ok (Some log.content))
Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't wan to get the logs for every failed job. We only want to get the logs for the failed jobs we will notify to slack. This should be done in Action.generate_notifications before calling Slack.generate_status_notifications and then you can pass in the logs to that function.

I think making the failed_steps arg a tuple of failed_step * log would be the most correct way

lib/buildkite.atd Show resolved Hide resolved
lib/api_local.ml Outdated Show resolved Hide resolved
lib/text_cleanup/test/job_log.t/run.t Outdated Show resolved Hide resolved
lib/text_cleanup/test/job_log.t/run.t Show resolved Hide resolved
lib/slack.ml Outdated
let followups =
match job_log with
| Some log ->
let text = sprintf "Log : ```\n%s\n```" (Text_cleanup.cleanup log) in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let text = sprintf "Log : ```\n%s\n```" (Text_cleanup.cleanup log) in
let text = Text_cleanup.cleanup in

we already know these are logs. It should be on the snippet title.

lib/slack.ml Outdated
Comment on lines 55 to 56
let make_followup ?text ?attachments ?blocks ?(reply_broadcast = false) () =
{ text; attachments; blocks; reply_broadcast }
Copy link
Collaborator

Choose a reason for hiding this comment

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

logs should go in snippets, otherwise it will make for giant messages, no? (and in any case we wouldn't want to spam the channel with logs)

Suggested change
let make_followup ?text ?attachments ?blocks ?(reply_broadcast = false) () =
{ text; attachments; blocks; reply_broadcast }
let make_followup ?text ?attachments ?blocks () =
{ text; attachments; blocks; reply_broadcast = false }

Copy link
Author

Choose a reason for hiding this comment

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

I did not know about snippet, I checked them out, I agree they should be used.

test/slack_payloads.expected Show resolved Hide resolved
@EmileTrotignon EmileTrotignon force-pushed the error-log-in-notification branch from cd28762 to 7c69e6b Compare January 27, 2025 17:59
@EmileTrotignon EmileTrotignon force-pushed the error-log-in-notification branch 3 times, most recently from 3ced39e to 221c847 Compare January 31, 2025 14:59
@EmileTrotignon
Copy link
Author

I did not manage to make the snippet work for now.

I now print the log of every failed job, and only the last 15 lines.

Looks like this :
image

lib/api_local.ml Outdated Show resolved Hide resolved
lib/api_remote.ml Outdated Show resolved Hide resolved
lib/buildkite.atd Outdated Show resolved Hide resolved
@EmileTrotignon EmileTrotignon force-pushed the error-log-in-notification branch from a77c875 to 40f6e87 Compare February 3, 2025 16:08
lib/action.ml Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/action.ml Outdated Show resolved Hide resolved
lib/slack.ml Outdated Show resolved Hide resolved
lib/util.ml Show resolved Hide resolved
lib/api_local.ml Show resolved Hide resolved
{
"channel": "failed-builds",
"thread_ts": "mock_ts",
"text": "Log : ```\nThis is the job's log output\n```",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where are you getting these logs from?

Copy link
Author

Choose a reason for hiding this comment

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

Nowhere, I wrote that file by hand. I can swap in a real one.

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