mattermost icon indicating copy to clipboard operation
mattermost copied to clipboard

Added download button for downloading logs from server logs page in system console.

Open Aryakoste opened this issue 11 months ago • 39 comments

Summary

Added download logs button in server logs page of admin in system console. When clicked logs get downloaded as mattermost.log file.

Ticket Link

Fixes https://github.com/mattermost/mattermost/issues/26320 Jira https://mattermost.atlassian.net/browse/MM-57013

Screenshots

before after
plainLogsBefore
plainLogsAfter
before after
logsBefore
logsAfter

Release Note

Added download functionality for admins to download server logs from Server Logs Page in System Console.

Aryakoste avatar Mar 04 '24 19:03 Aryakoste

Hello @Aryakoste,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

mattermost-build avatar Mar 04 '24 19:03 mattermost-build

E2E tests not automatically triggered, because the PR is not in a mergeable state. Please update the branch with the base branch and resolve outstanding conflicts.

mattermost-build avatar Mar 05 '24 15:03 mattermost-build

@svelle Would you mind taking a look from an UX standpoint?

hanzei avatar Mar 11 '24 10:03 hanzei

Creating a new SpinWick test server using Mattermost Cloud.

mm-cloud-bot avatar Mar 12 '24 09:03 mm-cloud-bot

Enterprise Edition Image not available in the 30 minutes timeframe, checking the Team Edition Image and if available will use that.

mm-cloud-bot avatar Mar 12 '24 09:03 mm-cloud-bot

Test server creation failed. Review the error details here.

mm-cloud-bot avatar Mar 17 '24 11:03 mm-cloud-bot

Creating a new SpinWick test server using Mattermost Cloud.

mm-cloud-bot avatar Mar 18 '24 13:03 mm-cloud-bot

Enterprise Edition Image not available in the 30 minutes timeframe, checking the Team Edition Image and if available will use that.

mm-cloud-bot avatar Mar 18 '24 14:03 mm-cloud-bot

Should I make backend change as discussed or do the frontend changes given.

Aryakoste avatar Mar 26 '24 20:03 Aryakoste

If you could do the backend change, that'd be great

hmhealey avatar Mar 28 '24 13:03 hmhealey

Ok. Will make the backend change. So we have to use common endpoint of /logs/download for downloading both plain and JSON logs right ?.

Aryakoste avatar Mar 28 '24 14:03 Aryakoste

Yeah, a new API for each of those would work. The body of the new methods will be mostly the same as the old ones except for the headers attached to the response to trigger the download. The API metrods can call web.WriteFileResponse with true for its forceDownload parameter to write all those headers for you.

hmhealey avatar Mar 28 '24 22:03 hmhealey

Update:- I have made the api and checked the response. Just have to make some changes on frontend to make it properly work. Will commit my changes after that.

Aryakoste avatar Apr 02 '24 20:04 Aryakoste

Test server creation failed. Review the error details here.

mm-cloud-bot avatar Apr 07 '24 05:04 mm-cloud-bot

func downloadLogs(c *Context, w http.ResponseWriter, r *http.Request) {

lines, _ := c.App.GetLogs(c.AppContext, c.Params.Page, c.Params.LogsPerPage)

tmpfile, err := os.CreateTemp("", "logs-*.log")
if err != nil {
	http.Error(w, "Failed to create temporary file", http.StatusInternalServerError)
	return
}
defer tmpfile.Close()
defer os.Remove(tmpfile.Name())

for _, line := range lines {
	if _, err := io.WriteString(tmpfile, line); err != nil {
		http.Error(w, "Failed to write logs to file", http.StatusInternalServerError)
		return
	}
}

fileInfo, err := tmpfile.Stat()
if err != nil {
	http.Error(w, "Failed to get file information", http.StatusInternalServerError)
	return
}

web.WriteFileResponse("mattermost.log",
	"text/plain",
	fileInfo.Size(),
	time.Now(),
	*c.App.Config().ServiceSettings.WebserverMode,
	tmpfile,
	true,
	w,
	r)

}

this is the function/controller i wrote to download the log file. But the log file isnt downloading automatically. I have set the forceDownload parameter to true.

Aryakoste avatar Apr 07 '24 10:04 Aryakoste

That's strange. I would've expected that to work, but perhaps something else is missing.

Could you push those changes so that I could try them out? They can either be part of this branch or on a separate one, but I want to be able to run the code locally

hmhealey avatar Apr 08 '24 21:04 hmhealey

Test server creation failed. Review the error details here.

mm-cloud-bot avatar Apr 09 '24 09:04 mm-cloud-bot

I have pushed the changes. Check and let me know.

Aryakoste avatar Apr 09 '24 09:04 Aryakoste

Test server creation failed. Review the error details here.

mm-cloud-bot avatar Apr 12 '24 18:04 mm-cloud-bot

Test server creation failed. Review the error details here.

mm-cloud-bot avatar Apr 12 '24 18:04 mm-cloud-bot

Test server creation failed. Review the error details here.

mm-cloud-bot avatar Apr 16 '24 20:04 mm-cloud-bot

Test server creation failed. Review the error details here.

mm-cloud-bot avatar Apr 18 '24 20:04 mm-cloud-bot

@hanzei I'm not sure who your team usually assigns to QA test your tickets, so I assigned @yasserfaraazkhan. If there's someone else who'd be better to test it, feel free to re-assign

hmhealey avatar Apr 18 '24 20:04 hmhealey

/update-branch

yasserfaraazkhan avatar Apr 21 '24 15:04 yasserfaraazkhan

@Aryakoste can you check the CI failure ?

yasserfaraazkhan avatar Apr 22 '24 07:04 yasserfaraazkhan

what does this check-i18n suggest me to do.

Aryakoste avatar Apr 22 '24 19:04 Aryakoste

Looks like that that's complaining about the order of the translation strings being wrong. I can update that.

Edit: If you're ever needing to do it yourself, you can run npm run -w channels i18n-extract to update that file

hmhealey avatar Apr 24 '24 20:04 hmhealey

/update-branch

yasserfaraazkhan avatar Apr 25 '24 04:04 yasserfaraazkhan

/e2e-tests

yasserfaraazkhan avatar Apr 25 '24 04:04 yasserfaraazkhan

The command /e2e-test requires all PR checks to pass.

mattermost-build avatar Apr 25 '24 04:04 mattermost-build