mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-16 15:38:40 +00:00
fixed upload entries (#407)
This commit is contained in:
parent
fbee4454e4
commit
e3ead981ec
@ -13,11 +13,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DBPath = "./entries.db"
|
DBPath = "./entries.db"
|
||||||
OrderDesc = "desc"
|
OrderDesc = "desc"
|
||||||
OrderAsc = "asc"
|
OrderAsc = "asc"
|
||||||
LT = "lt"
|
LT = "lt"
|
||||||
GT = "gt"
|
GT = "gt"
|
||||||
|
TimeFormat = "2006-01-02 15:04:05.000000000"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -57,7 +58,7 @@ func initDataBase(databasePath string) *gorm.DB {
|
|||||||
return temp
|
return temp
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetEntriesFromDb(timestampFrom int64, timestampTo int64, protocolName *string) []tapApi.MizuEntry {
|
func GetEntriesFromDb(timeFrom time.Time, timeTo time.Time, protocolName *string) []tapApi.MizuEntry {
|
||||||
order := OrderDesc
|
order := OrderDesc
|
||||||
protocolNameCondition := "1 = 1"
|
protocolNameCondition := "1 = 1"
|
||||||
if protocolName != nil {
|
if protocolName != nil {
|
||||||
@ -67,7 +68,7 @@ func GetEntriesFromDb(timestampFrom int64, timestampTo int64, protocolName *stri
|
|||||||
var entries []tapApi.MizuEntry
|
var entries []tapApi.MizuEntry
|
||||||
GetEntriesTable().
|
GetEntriesTable().
|
||||||
Where(protocolNameCondition).
|
Where(protocolNameCondition).
|
||||||
Where(fmt.Sprintf("timestamp BETWEEN %v AND %v", timestampFrom, timestampTo)).
|
Where(fmt.Sprintf("created_at BETWEEN '%s' AND '%s'", timeFrom.Format(TimeFormat), timeTo.Format(TimeFormat))).
|
||||||
Order(fmt.Sprintf("timestamp %s", order)).
|
Order(fmt.Sprintf("timestamp %s", order)).
|
||||||
Find(&entries)
|
Find(&entries)
|
||||||
|
|
||||||
|
@ -206,13 +206,13 @@ func syncEntriesImpl(token string, model string, envPrefix string, uploadInterva
|
|||||||
|
|
||||||
sleepTime := time.Second * time.Duration(uploadIntervalSec)
|
sleepTime := time.Second * time.Duration(uploadIntervalSec)
|
||||||
|
|
||||||
var timestampFrom int64 = 0
|
var timeFrom time.Time
|
||||||
|
protocolFilter := "http"
|
||||||
|
|
||||||
for {
|
for {
|
||||||
timestampTo := time.Now().UnixNano() / int64(time.Millisecond)
|
timeTo := time.Now()
|
||||||
logger.Log.Infof("Getting entries from %v, to %v\n", timestampFrom, timestampTo)
|
logger.Log.Infof("Getting entries from %v, to %v\n", timeFrom.Format(time.RFC3339Nano), timeTo.Format(time.RFC3339Nano))
|
||||||
protocolFilter := "http"
|
entriesArray := database.GetEntriesFromDb(timeFrom, timeTo, &protocolFilter)
|
||||||
entriesArray := database.GetEntriesFromDb(timestampFrom, timestampTo, &protocolFilter)
|
|
||||||
|
|
||||||
if len(entriesArray) > 0 {
|
if len(entriesArray) > 0 {
|
||||||
result := make([]har.Entry, 0)
|
result := make([]har.Entry, 0)
|
||||||
@ -276,13 +276,14 @@ func syncEntriesImpl(token string, model string, envPrefix string, uploadInterva
|
|||||||
analyzeInformation.SentCount += len(entriesArray)
|
analyzeInformation.SentCount += len(entriesArray)
|
||||||
logger.Log.Infof("Finish uploading %v entries to %s\n", len(entriesArray), GetTrafficDumpUrl(envPrefix, model))
|
logger.Log.Infof("Finish uploading %v entries to %s\n", len(entriesArray), GetTrafficDumpUrl(envPrefix, model))
|
||||||
|
|
||||||
|
logger.Log.Infof("Uploaded %v entries until now", analyzeInformation.SentCount)
|
||||||
} else {
|
} else {
|
||||||
logger.Log.Infof("Nothing to upload")
|
logger.Log.Infof("Nothing to upload")
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Log.Infof("Sleeping for %v...\n", sleepTime)
|
logger.Log.Infof("Sleeping for %v...\n", sleepTime)
|
||||||
time.Sleep(sleepTime)
|
time.Sleep(sleepTime)
|
||||||
timestampFrom = timestampTo
|
timeFrom = timeTo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user