-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdatabase.go
71 lines (64 loc) · 1.91 KB
/
database.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright 2022-present Kuei-chun Chen. All rights reserved.
* database.go
*/
package hatchet
import "log"
const (
SQLite3 = iota
Mongo
)
type NameValue struct {
Name string `bson:"name"`
Value int `bson:"value"`
}
type NameValues struct {
Name string
Values []interface{}
}
type Database interface {
Begin() error
Close() error
Commit() error
CreateMetaData() error
Drop() error
GetAcceptedConnsCounts(duration string) ([]NameValue, error)
GetAuditData() (map[string][]NameValues, error)
GetAverageOpTime(op string, duration string) ([]OpCount, error)
GetConnectionStats(chartType string, duration string) ([]RemoteClient, error)
GetHatchetInfo() HatchetInfo
GetHatchetNames() ([]string, error)
GetLogs(opts ...string) ([]LegacyLog, error)
GetOpsCounts(duration string) ([]NameValue, error)
GetReslenByNamespace(ip string, duration string) ([]NameValue, error)
GetReslenByIP(ip string, duration string) ([]NameValue, error)
GetSlowOps(orderBy string, order string, collscan bool) ([]OpStat, error)
GetSlowestLogs(topN int) ([]LegacyLog, error)
GetVerbose() bool
InsertClientConn(index int, doc *Logv2Info) error
InsertDriver(index int, doc *Logv2Info) error
InsertFailedMessages(m *FailedMessages) error
InsertLog(index int, end string, doc *Logv2Info, stat *OpStat) error
SearchLogs(opts ...string) ([]LegacyLog, error)
SetVerbose(v bool)
UpdateHatchetInfo(info HatchetInfo) error
}
func GetDatabase(hatchetName string) (Database, error) {
var err error
var dbase Database
logv2 := GetLogv2()
if logv2.verbose {
log.Println("url", logv2.url, "hatchet name", hatchetName)
}
if GetLogv2().GetDBType() == Mongo {
if dbase, err = NewMongoDB(logv2.url, hatchetName); err != nil {
return nil, err
}
} else { // default is SQLite3
if dbase, err = NewSQLite3DB(logv2.url, hatchetName, logv2.cacheSize); err != nil {
return nil, err
}
}
dbase.SetVerbose(logv2.verbose)
return dbase, err
}