Skip to content

command line support bundle uploader#29

Merged
laverya merged 1 commit intomasterfrom
andrewlavery/ch2986/command-line-support-bundle-upload
Nov 2, 2017
Merged

command line support bundle uploader#29
laverya merged 1 commit intomasterfrom
andrewlavery/ch2986/command-line-support-bundle-upload

Conversation

@laverya
Copy link
Copy Markdown
Contributor

@laverya laverya commented Nov 2, 2017

No description provided.

@laverya laverya requested a review from emosbaugh November 2, 2017 20:27
Comment thread cmd/upload.go Outdated
// is called directly, e.g.:
// uploadCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

uploadCmd.Flags().StringVar(&uploadBundlePath, "path", "supportbundle.tar.gz", "Path to the bundle that should be uploaded")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how about some StringVarPs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

p, f, l, e ,c, d? Not sure if that is massively more usable

Comment thread cmd/upload.go
jww.FEEDBACK.Println("Upload support bundle is not implemented...")
jww.FEEDBACK.Println("Uploading the provided support bundle")

contents, err := os.Open(uploadBundlePath)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe after this is merged we can also add option to accept from stdin since a lot of ppl like to run things in docker containers these days

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean accept the support bundle contents from stdin?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes

Comment thread pkg/bundle/upload.go
res, err := client.Do(req)
if err != nil {
return "", err
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

defer res.Body.Close()

Comment thread pkg/bundle/upload.go Outdated
}

respData := responseData{}
json.Unmarshal(response, &respData)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

err = json.Unmarshal(response, &respData)

Comment thread pkg/bundle/upload.go Outdated
return "", err
}

response, err := ioutil.ReadAll(res.Body)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how about json.NewDecoder(io.Reader)?

Comment thread pkg/bundle/upload.go Outdated
}

if res.StatusCode != http.StatusCreated {
err = fmt.Errorf("Bad status when uploading support bundle: %s", res.Status)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we use github.com/pkg/errors in this project? i prefer errors.Wrap

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to use errors, but we're generating a new error anyways

Comment thread pkg/bundle/upload.go
if err != nil {
return "", err
}
if _, err := io.Copy(formFile, file); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there has got to be a way to stream this...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

@laverya laverya Nov 2, 2017

Choose a reason for hiding this comment

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

As far as I can tell, that's basically what we do...
Pipewriter instead of a buffered writer?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well here you load it all into memory and then stream upload. you probably need a goroutine somewhere

Comment thread pkg/bundle/upload.go Outdated
req.Header.Set("Content-Type", w.FormDataContentType())

// submit request
client := &http.Client{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use http.DefaultClient

Comment thread pkg/bundle/upload.go Outdated
}

// closing the multipart writer sets the closing boundary
w.Close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think you need to close this if there is an error

Comment thread cmd/upload.go Outdated
jww.FEEDBACK.Println("Uploading the provided support bundle")

contents, err := os.Open(uploadBundlePath)
defer contents.Close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you may want this defer after the error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I really wish github had a facepalm reaction.

Comment thread pkg/bundle/upload.go Outdated
}

func streamingUploadFile(file *os.File, w *io.PipeWriter, data string, contentType chan string) {
defer file.Close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i believe you close the file twice. you can remove this

Comment thread pkg/bundle/upload.go Outdated
}
}

func streamingUploadFile(file *os.File, w *io.PipeWriter, data string, contentType chan string) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how about just io.Reader and io.WriteCloser ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

io.WriteCloser would work, but I do use file.Name. I don't think the api endpoint uses the filename at the moment and it could be omitted/be a placeholder, though the web interface does send it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ah, ok

Comment thread pkg/bundle/upload.go Outdated
writer := multipart.NewWriter(w)
defer writer.Close()

contentType <- writer.FormDataContentType()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you just take this out of this function so you dont need the weird contentTypeChan

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can, but then I have to pass both the pipewriter and the multipart.Writer so that close is called at the appropriate time for the pipewriter

Otherwise it just hangs. Unfortunately, it doesn't seem that multipart calls Close on the backing writer.

Comment thread cmd/upload.go
// is called directly, e.g.:
// uploadCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

uploadCmd.Flags().StringVarP(&uploadBundlePath, "path", "p", "supportbundle.tar.gz", "Path to the bundle that should be uploaded")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe only shorthand path

Comment thread pkg/bundle/upload.go
go streamingUploadFile(file, write, string(bundleBytes), contentTypeChan)
multipartWriter := multipart.NewWriter(write)
contentType := multipartWriter.FormDataContentType()
go streamingUploadFile(file, write, multipartWriter, string(bundleBytes))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

go func() {
  defer write.Close()
  streamingUploadFile(file, multipartWriter, string(bundleBytes))
}()

@laverya laverya force-pushed the andrewlavery/ch2986/command-line-support-bundle-upload branch from e3ac63b to 8df789b Compare November 2, 2017 22:53
@laverya laverya merged commit a34a255 into master Nov 2, 2017
@laverya laverya deleted the andrewlavery/ch2986/command-line-support-bundle-upload branch November 2, 2017 22:56
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.

2 participants