mirror of https://github.com/docker/docs.git
Add vbox.log to crashreport
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
This commit is contained in:
parent
32795c9d1f
commit
fd25762c05
|
@ -13,6 +13,8 @@ import (
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/bugsnag/bugsnag-go"
|
"github.com/bugsnag/bugsnag-go"
|
||||||
"github.com/docker/machine/commands/mcndirs"
|
"github.com/docker/machine/commands/mcndirs"
|
||||||
"github.com/docker/machine/libmachine/log"
|
"github.com/docker/machine/libmachine/log"
|
||||||
|
@ -35,8 +37,7 @@ func Configure(key string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send through http the crash report to bugsnag need a call to Configure(apiKey) before
|
func SendWithFile(err error, context string, driverName string, command string, path string) error {
|
||||||
func Send(err error, context string, driverName string, command string) error {
|
|
||||||
if noReportFileExist() || apiKey == noreportAPIKey {
|
if noReportFileExist() || apiKey == noreportAPIKey {
|
||||||
log.Debug("Opting out of crash reporting.")
|
log.Debug("Opting out of crash reporting.")
|
||||||
return nil
|
return nil
|
||||||
|
@ -67,6 +68,7 @@ func Send(err error, context string, driverName string, command string) error {
|
||||||
detectRunningShell(&metaData)
|
detectRunningShell(&metaData)
|
||||||
detectUname(&metaData)
|
detectUname(&metaData)
|
||||||
detectOSVersion(&metaData)
|
detectOSVersion(&metaData)
|
||||||
|
addFile(path, &metaData)
|
||||||
|
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
for _, message := range log.History() {
|
for _, message := range log.History() {
|
||||||
|
@ -76,6 +78,25 @@ func Send(err error, context string, driverName string, command string) error {
|
||||||
return bugsnag.Notify(err, metaData, bugsnag.SeverityError, bugsnag.Context{String: context}, bugsnag.ErrorClass{Name: fmt.Sprintf("%s/%s", driverName, command)})
|
return bugsnag.Notify(err, metaData, bugsnag.SeverityError, bugsnag.Context{String: context}, bugsnag.ErrorClass{Name: fmt.Sprintf("%s/%s", driverName, command)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send through http the crash report to bugsnag need a call to Configure(apiKey) before
|
||||||
|
func Send(err error, context string, driverName string, command string) error {
|
||||||
|
return SendWithFile(err, context, driverName, command, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func addFile(path string, metaData *bugsnag.MetaData) {
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := ioutil.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Debug(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
metaData.Add("logfile", filepath.Base(path), string(data))
|
||||||
|
}
|
||||||
|
|
||||||
func noReportFileExist() bool {
|
func noReportFileExist() bool {
|
||||||
optOutFilePath := filepath.Join(mcndirs.GetBaseDir(), "no-error-report")
|
optOutFilePath := filepath.Join(mcndirs.GetBaseDir(), "no-error-report")
|
||||||
if _, err := os.Stat(optOutFilePath); os.IsNotExist(err) {
|
if _, err := os.Stat(optOutFilePath); os.IsNotExist(err) {
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package crashreport
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/bugsnag/bugsnag-go"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFileIsNotReadWhenNotExisting(t *testing.T) {
|
||||||
|
metaData := bugsnag.MetaData{}
|
||||||
|
addFile("not existing", &metaData)
|
||||||
|
assert.Empty(t, metaData)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRead(t *testing.T) {
|
||||||
|
metaData := bugsnag.MetaData{}
|
||||||
|
content := "foo\nbar\nqix\n"
|
||||||
|
fileName := createTempFile(t, content)
|
||||||
|
defer os.Remove(fileName)
|
||||||
|
addFile(fileName, &metaData)
|
||||||
|
assert.Equal(t, "foo\nbar\nqix\n", metaData["logfile"][filepath.Base(fileName)])
|
||||||
|
}
|
||||||
|
|
||||||
|
func createTempFile(t *testing.T, content string) string {
|
||||||
|
file, err := ioutil.TempFile("", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(file.Name(), []byte(content), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return file.Name()
|
||||||
|
}
|
|
@ -98,7 +98,7 @@ func (api *Client) Create(h *host.Host) error {
|
||||||
log.Info("Creating machine...")
|
log.Info("Creating machine...")
|
||||||
|
|
||||||
if err := api.performCreate(h); err != nil {
|
if err := api.performCreate(h); err != nil {
|
||||||
crashreport.Send(err, "api.performCreate", h.DriverName, "Create")
|
sendCrashReport(err, api, h)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,3 +152,12 @@ func (api *Client) performCreate(h *host.Host) error {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sendCrashReport(err error, api *Client, host *host.Host) {
|
||||||
|
if host.DriverName == "virtualbox" {
|
||||||
|
vboxlogPath := filepath.Join(api.GetMachinesDir(), host.Name, host.Name, "Logs", "VBox.log")
|
||||||
|
crashreport.SendWithFile(err, "api.performCreate", host.DriverName, "Create", vboxlogPath)
|
||||||
|
} else {
|
||||||
|
crashreport.Send(err, "api.performCreate", host.DriverName, "Create")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue