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

Log endpoint uses multipart form #1228

Merged
merged 11 commits into from
Nov 24, 2020
Merged

Log endpoint uses multipart form #1228

merged 11 commits into from
Nov 24, 2020

Conversation

jameskerr
Copy link
Member

@jameskerr jameskerr commented Nov 18, 2020

UPDATE:

I've added a new method to the fetcher called "upload". It uses XHR to make the request and track progress events. We still return an iterable stream of payloads which now include a message that looks like {type: "UploadProgress", progress: number}. This allows us to keep the progress bar unchanged as it was.

Fixes #1094

This changes the log post method in the zealot client to make a multipart form file upload, instead of sending the paths of the files. The pcaps post endpoint has remained unchanged.

It is not easy to get a progress bar for this type of request (it's impossible ATM using the Fetch API, we'd have to rewrite that method with XHR). I think we didn't have progress for log uploads anyway.

@philrz when you verify this, upload a large log file (or set of log files) over 4 GB. I expect it to work but that would be good to check.

P.S.
@mattnibs I noticed that the key for the warnings was a "nil". That may be a bug, see below:

image

@alfred-landrum
Copy link
Contributor

alfred-landrum commented Nov 19, 2020

@jameskerr : I know we can't get the same status messages that were used to implement the existing progress bar. I thought we would watch how much data has been uploaded to the backend api, and use that as the basis for a progress bar in this case? That's how the zapi command is giving a progressive status for the new api.

@jameskerr
Copy link
Member Author

jameskerr commented Nov 19, 2020

@alfred-landrum I understand, it's just that the zealot client is setup to use the modern, promise-based "Fetch" web api for making requests. The Fetch API has not created a way to hook into the upload progress events. We'd have to use the older XMLHttpRequest syntax for just this one api call. Definitely possible, but not quite plug and play.

https://usefulangle.com/post/321/javascript-fetch-upload-progress

@philrz
Copy link
Contributor

philrz commented Nov 19, 2020

Just to chime in with a visual, here's proof of the progress bar we've previously had for log import:

ProgressBar

Regarding large imports, I'll do a final verification when this merges to master, but I did just do a quick test with the "wrccdc-year1" data set that's 12 GB of uncompressed Zeek TSV logs and they did import without complaint.

@jameskerr
Copy link
Member Author

@philrz Thanks for your help! Glad to hear it worked with a big one. So that progress bar is there, but they are unable to search for anything until it completes. That's right.

Copy link
Contributor

@mason-fish mason-fish left a comment

Choose a reason for hiding this comment

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

Looks good! I had thought we could keep track of file upload as well, thanks for pointing out that constraint. Hopefully they do add it in to the fetch api soon.

My comments are mostly superficial, but pls take a look before merging.

@@ -169,6 +171,13 @@ const trackProgress = (client, gDispatch, clusterId) => {
gDispatch(space.setIngestProgress(logPostStatusToPercent(status)))
updateSpaceDetails()
break
case "LogPostResponse":
console.log(status)
Copy link
Contributor

Choose a reason for hiding this comment

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

left a straggler

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

case "LogPostResponse":
console.log(status)
updateSpaceDetails()
;(status.warnings || []).forEach((warning) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this semi-colon isn't doing anything. Also, would recommend using lodash's forEach for this instead

Copy link
Member Author

@jameskerr jameskerr Nov 20, 2020

Choose a reason for hiding this comment

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

Yeah, prettier added that in. I guess when a line starts with parens, it needs the semi-colon.

@@ -1,46 +1,52 @@
import {IngestFileType} from "./detectFileType"
import lib from "../../lib"

export type FileListData = {type: IngestFileType; path: string}[]
export type FileListData = {type: IngestFileType; file: File}[]
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if you considered extending the File interface by annotating it with the new type field? would save all the extra .file.s since it would be flattened, just a thought!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah true, I usually try to stay away from extending things like that. "Compose rather than inherit" mindset I guess. Is this something that is done conventionally in go?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the composition vs inheritance dilemma is the same in go. I do agree with the compose > inheritance mindset, but thought that in this case with just these two types, and one always depending on the other, extending would grant the small bonus of less typing as you access the imbedded File interface. I have no strong feelings in this case at all though!

const iterator = createPushableIterator<ZealotPayload>()
const xhr = new XMLHttpRequest()

xhr.upload.addEventListener("progress", (e) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

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.

Update Log Post API to Multi-Part File Upload
4 participants