mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-11 21:32:37 +00:00
Update main.go, main.go, and size_enforcer.go
This commit is contained in:
parent
79a8ee37f9
commit
21b91ea6e4
@ -161,7 +161,7 @@ func saveHarToDb(entry *har.Entry, connectionInfo *tap.ConnectionInfo) {
|
|||||||
IsOutgoing: connectionInfo.IsOutgoing,
|
IsOutgoing: connectionInfo.IsOutgoing,
|
||||||
}
|
}
|
||||||
mizuEntry.EstimatedSizeBytes = getEstimatedEntrySizeBytes(mizuEntry)
|
mizuEntry.EstimatedSizeBytes = getEstimatedEntrySizeBytes(mizuEntry)
|
||||||
database.GetEntriesTable().Create(&mizuEntry)
|
database.CreateEntry(&mizuEntry)
|
||||||
|
|
||||||
baseEntry := models.BaseEntryDetails{}
|
baseEntry := models.BaseEntryDetails{}
|
||||||
if err := models.GetEntry(&mizuEntry, &baseEntry); err != nil {
|
if err := models.GetEntry(&mizuEntry, &baseEntry); err != nil {
|
||||||
|
@ -12,11 +12,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
DBPath = "./entries.db"
|
DBPath = "./entries.db"
|
||||||
)
|
|
||||||
|
|
||||||
var DB *gorm.DB
|
|
||||||
|
|
||||||
const (
|
|
||||||
OrderDesc = "desc"
|
OrderDesc = "desc"
|
||||||
OrderAsc = "asc"
|
OrderAsc = "asc"
|
||||||
LT = "lt"
|
LT = "lt"
|
||||||
@ -24,6 +19,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
DB *gorm.DB
|
||||||
|
IsDBLocked = false
|
||||||
OperatorToSymbolMapping = map[string]string{
|
OperatorToSymbolMapping = map[string]string{
|
||||||
LT: "<",
|
LT: "<",
|
||||||
GT: ">",
|
GT: ">",
|
||||||
@ -43,6 +40,13 @@ func GetEntriesTable() *gorm.DB {
|
|||||||
return DB.Table("mizu_entries")
|
return DB.Table("mizu_entries")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateEntry(entry *models.MizuEntry) {
|
||||||
|
if IsDBLocked {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
GetEntriesTable().Create(entry)
|
||||||
|
}
|
||||||
|
|
||||||
func initDataBase(databasePath string) *gorm.DB {
|
func initDataBase(databasePath string) *gorm.DB {
|
||||||
temp, _ := gorm.Open(sqlite.Open(databasePath), &gorm.Config{
|
temp, _ := gorm.Open(sqlite.Open(databasePath), &gorm.Config{
|
||||||
Logger: &utils.TruncatingLogger{LogLevel: logger.Warn, SlowThreshold: 500 * time.Millisecond},
|
Logger: &utils.TruncatingLogger{LogLevel: logger.Warn, SlowThreshold: 500 * time.Millisecond},
|
||||||
|
@ -81,6 +81,9 @@ func checkFileSize(maxSizeBytes int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pruneOldEntries(currentFileSize int64) {
|
func pruneOldEntries(currentFileSize int64) {
|
||||||
|
IsDBLocked = true
|
||||||
|
defer func() {IsDBLocked = false}()
|
||||||
|
|
||||||
amountOfBytesToTrim := currentFileSize / (100 / percentageOfMaxSizeBytesToPrune)
|
amountOfBytesToTrim := currentFileSize / (100 / percentageOfMaxSizeBytesToPrune)
|
||||||
|
|
||||||
rows, err := GetEntriesTable().Limit(10000).Order("id").Rows()
|
rows, err := GetEntriesTable().Limit(10000).Order("id").Rows()
|
||||||
|
Loading…
Reference in New Issue
Block a user