feat: support ClickHouse log database (#5663)
* feat: support ClickHouse log database * feat(log): optimize log deletion process for ClickHouse
This commit is contained in:
+16
-1
@@ -2,7 +2,9 @@ package common
|
||||
|
||||
import (
|
||||
crand "crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
@@ -15,6 +17,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -264,7 +267,19 @@ func GetTimestamp() int64 {
|
||||
|
||||
func GetTimeString() string {
|
||||
now := time.Now().UTC()
|
||||
return fmt.Sprintf("%s%d", now.Format("20060102150405"), now.UnixNano()%1e9)
|
||||
return fmt.Sprintf("%s%09d", now.Format("20060102150405"), now.UnixNano()%1e9)
|
||||
}
|
||||
|
||||
var requestIdPrefix = func() string {
|
||||
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Path != "" {
|
||||
h := sha256.Sum256([]byte(bi.Main.Path))
|
||||
return hex.EncodeToString(h[:4])
|
||||
}
|
||||
return GetRandomString(8)
|
||||
}()
|
||||
|
||||
func NewRequestId() string {
|
||||
return GetTimeString() + requestIdPrefix + GetRandomString(8)
|
||||
}
|
||||
|
||||
func Max(a int, b int) int {
|
||||
|
||||
Reference in New Issue
Block a user