Skip to content

Commit

Permalink
update trace data
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed Dec 10, 2020
1 parent d356f94 commit 9168aa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
3 changes: 1 addition & 2 deletions command/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ $ vermin create <image> </path/to/shell/script.sh>
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)

Expand Down
25 changes: 12 additions & 13 deletions config/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@ 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),
})
}

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
}
Expand Down

0 comments on commit 9168aa1

Please sign in to comment.