Generate json statistics for tag
This commit is contained in:
parent
c2481272e2
commit
f7c884e4f8
65
log.go
65
log.go
@ -6,7 +6,9 @@ package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"code.dumpstack.io/tools/out-of-tree/config"
|
||||
@ -52,6 +54,7 @@ func logHandler(db *sql.DB, path, tag string, num int, rate bool) (err error) {
|
||||
|
||||
ka, kaErr := config.ReadArtifactConfig(path + "/.out-of-tree.toml")
|
||||
if kaErr == nil {
|
||||
log.Println(".out-of-tree.toml found, filter by artifact name")
|
||||
les, err = getAllArtifactLogs(db, tag, num, ka)
|
||||
} else {
|
||||
les, err = getAllLogs(db, tag, num)
|
||||
@ -138,3 +141,65 @@ func logDumpHandler(db *sql.DB, id int) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type runstat struct {
|
||||
All, BuildOK, RunOK, TestOK, Timeout, Panic int
|
||||
}
|
||||
|
||||
func logJsonHandler(db *sql.DB, path, tag string) (err error) {
|
||||
var les []logEntry
|
||||
|
||||
ka, kaErr := config.ReadArtifactConfig(path + "/.out-of-tree.toml")
|
||||
if kaErr == nil {
|
||||
les, err = getAllArtifactLogs(db, tag, -1, ka)
|
||||
} else {
|
||||
les, err = getAllLogs(db, tag, -1)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
distros := make(map[string]map[string]map[string]runstat)
|
||||
|
||||
for _, l := range les {
|
||||
_, ok := distros[l.DistroType.String()]
|
||||
if !ok {
|
||||
distros[l.DistroType.String()] = make(map[string]map[string]runstat)
|
||||
}
|
||||
|
||||
_, ok = distros[l.DistroType.String()][l.DistroRelease]
|
||||
if !ok {
|
||||
distros[l.DistroType.String()][l.DistroRelease] = make(map[string]runstat)
|
||||
}
|
||||
|
||||
rs := distros[l.DistroType.String()][l.DistroRelease][l.KernelRelease]
|
||||
|
||||
rs.All += 1
|
||||
if l.Build.Ok {
|
||||
rs.BuildOK += 1
|
||||
}
|
||||
if l.Run.Ok {
|
||||
rs.RunOK += 1
|
||||
}
|
||||
if l.Test.Ok {
|
||||
rs.TestOK += 1
|
||||
}
|
||||
if l.KernelPanic {
|
||||
rs.Panic += 1
|
||||
}
|
||||
if l.KilledByTimeout {
|
||||
rs.Timeout += 1
|
||||
}
|
||||
|
||||
distros[l.DistroType.String()][l.DistroRelease][l.KernelRelease] = rs
|
||||
}
|
||||
|
||||
bytes, err := json.Marshal(&distros)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(string(bytes))
|
||||
|
||||
return
|
||||
}
|
||||
|
5
main.go
5
main.go
@ -195,6 +195,9 @@ func main() {
|
||||
"Show all info for log entry with ID")
|
||||
logDumpID := logDumpCommand.Arg("ID", "").Required().Int()
|
||||
|
||||
logJsonCommand := logCommand.Command("json", "Generate json statistics")
|
||||
logJsonTag := logJsonCommand.Flag("tag", "Filter tag").Required().String()
|
||||
|
||||
err = checkRequiredUtils()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
@ -277,6 +280,8 @@ func main() {
|
||||
err = logHandler(db, *path, *logTag, *logNum, *logRate)
|
||||
case logDumpCommand.FullCommand():
|
||||
err = logDumpHandler(db, *logDumpID)
|
||||
case logJsonCommand.FullCommand():
|
||||
err = logJsonHandler(db, *path, *logJsonTag)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user