From 9168aa1908cfb6d7b9dcd5d9b69da1bebebcd77b Mon Sep 17 00:00:00 2001 From: Muhammad Hewedy Date: Thu, 10 Dec 2020 10:34:29 +0300 Subject: [PATCH] update trace data --- command/create.go | 3 +-- config/trace/trace.go | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/command/create.go b/command/create.go index 82f8116..54117b2 100644 --- a/command/create.go +++ b/command/create.go @@ -58,9 +58,8 @@ $ vermin create cpus, _ := cmd.Flags().GetInt("cpus") mem, _ := cmd.Flags().GetInt("mem") - trace.PreCreate(imageName) vmName, err := vms.Create(imageName, ps, cpus, mem) - trace.PostCreate(imageName, err) + trace.PostCreate(imageName, version, err) exitOnError(err) diff --git a/config/trace/trace.go b/config/trace/trace.go index a492cda..88812fc 100644 --- a/config/trace/trace.go +++ b/config/trace/trace.go @@ -2,27 +2,27 @@ package trace import ( "encoding/base64" + "fmt" "github.com/matishsiao/goInfo" "github.com/mhewedy/go-gistlog" - "strings" + "regexp" "time" ) -var log = gistlog.NewLog("91d041d80687032b270d3c694ea815b8", token()) - -func PreCreate(imageName string) { +var ( + newline = regexp.MustCompile(`\r?\n`) + log = gistlog.NewLog("91d041d80687032b270d3c694ea815b8", token()) +) - log.InsertAsync("pre-create", []string{ - imageName, - time.Now().UTC().String(), - }) -} +func PostCreate(imageName, version string, err error) { -func PostCreate(imageName string, err error) { + year, month, _ := time.Now().Date() - _ = log.Insert("post-create", []string{ + _ = log.Insert(fmt.Sprintf("create_%d-%d", year, month), []string{ imageName, time.Now().UTC().String(), + version, + goInfo.GetInfo().String(), errorAsString(err), }) } @@ -30,8 +30,7 @@ func PostCreate(imageName string, err error) { func errorAsString(err error) string { var errStr string if err != nil { - errStr = strings.Join(strings.Split(err.Error(), "\n"), " ") - errStr += goInfo.GetInfo().String() + errStr = newline.ReplaceAllString(err.Error(), " ") } return errStr }