mirror of https://github.com/0xERR0R/blocky.git
feat(querylog): add flushInterval parameter
This commit is contained in:
parent
e31d20c132
commit
b1d014017b
|
@ -12,6 +12,7 @@ type QueryLogConfig struct {
|
|||
CreationAttempts int `yaml:"creationAttempts" default:"3"`
|
||||
CreationCooldown Duration `yaml:"creationCooldown" default:"2s"`
|
||||
Fields []QueryLogField `yaml:"fields"`
|
||||
FlushInterval Duration `yaml:"flushInterval" default:"30s"`
|
||||
}
|
||||
|
||||
// SetDefaults implements `defaults.Setter`.
|
||||
|
@ -37,5 +38,6 @@ func (c *QueryLogConfig) LogConfig(logger *logrus.Entry) {
|
|||
logger.Infof("logRetentionDays: %d", c.LogRetentionDays)
|
||||
logger.Debugf("creationAttempts: %d", c.CreationAttempts)
|
||||
logger.Debugf("creationCooldown: %s", c.CreationCooldown)
|
||||
logger.Infof("flushInterval: %s", c.FlushInterval)
|
||||
logger.Infof("fields: %s", c.Fields)
|
||||
}
|
||||
|
|
|
@ -203,6 +203,8 @@ queryLog:
|
|||
fields:
|
||||
- clientIP
|
||||
- duration
|
||||
# optional: Interval to write data in bulk to the external database, default: 30s
|
||||
flushInterval: 30s
|
||||
|
||||
# optional: Blocky can synchronize its cache and blocking state between multiple instances through redis.
|
||||
redis:
|
||||
|
|
|
@ -628,8 +628,9 @@ Configuration parameters:
|
|||
| queryLog.target | string | no | | directory for writing the logs (for csv) or database url (for mysql or postgresql) |
|
||||
| queryLog.logRetentionDays | int | no | 0 | if > 0, deletes log files/database entries which are older than ... days |
|
||||
| queryLog.creationAttempts | int | no | 3 | Max attempts to create specific query log writer |
|
||||
| queryLog.CreationCooldown | duration format | no | 2 | Time between the creation attempts |
|
||||
| queryLog.CreationCooldown | duration format | no | 2s | Time between the creation attempts |
|
||||
| queryLog.fields | list enum (clientIP, clientName, responseReason, responseAnswer, question, duration) | no | all | which information should be logged |
|
||||
| queryLog.flushInterval | duration format | no | 30s | Interval to write data in bulk to the external database |
|
||||
|
||||
!!! hint
|
||||
|
||||
|
@ -647,6 +648,7 @@ example for CSV format with limited logging information
|
|||
fields:
|
||||
- clientIP
|
||||
- duration
|
||||
flushInterval: 30s
|
||||
```
|
||||
|
||||
example for Database
|
||||
|
|
|
@ -42,6 +42,7 @@ var _ = Describe("Query logs functional tests", func() {
|
|||
"queryLog:",
|
||||
" type: mysql",
|
||||
" target: user:user@tcp(mariaDB:3306)/user?charset=utf8mb4&parseTime=True&loc=Local",
|
||||
" flushInterval: 1s",
|
||||
)
|
||||
|
||||
Expect(err).Should(Succeed())
|
||||
|
@ -119,6 +120,7 @@ var _ = Describe("Query logs functional tests", func() {
|
|||
"queryLog:",
|
||||
" type: postgresql",
|
||||
" target: postgres://user:user@postgres:5432/user",
|
||||
" flushInterval: 1s",
|
||||
)
|
||||
|
||||
Expect(err).Should(Succeed())
|
||||
|
|
|
@ -16,7 +16,6 @@ const (
|
|||
cleanUpRunPeriod = 12 * time.Hour
|
||||
queryLoggingResolverType = "query_logging"
|
||||
logChanCap = 1000
|
||||
defaultFlushPeriod = 30 * time.Second
|
||||
)
|
||||
|
||||
// QueryLoggingResolver writes query information (question, answer, duration, ...)
|
||||
|
@ -44,9 +43,9 @@ func NewQueryLoggingResolver(cfg config.QueryLogConfig) *QueryLoggingResolver {
|
|||
case config.QueryLogTypeCsvClient:
|
||||
writer, err = querylog.NewCSVWriter(cfg.Target, true, cfg.LogRetentionDays)
|
||||
case config.QueryLogTypeMysql:
|
||||
writer, err = querylog.NewDatabaseWriter("mysql", cfg.Target, cfg.LogRetentionDays, defaultFlushPeriod)
|
||||
writer, err = querylog.NewDatabaseWriter("mysql", cfg.Target, cfg.LogRetentionDays, cfg.FlushInterval.ToDuration())
|
||||
case config.QueryLogTypePostgresql:
|
||||
writer, err = querylog.NewDatabaseWriter("postgresql", cfg.Target, cfg.LogRetentionDays, defaultFlushPeriod)
|
||||
writer, err = querylog.NewDatabaseWriter("postgresql", cfg.Target, cfg.LogRetentionDays, cfg.FlushInterval.ToDuration())
|
||||
case config.QueryLogTypeConsole:
|
||||
writer = querylog.NewLoggerWriter()
|
||||
case config.QueryLogTypeNone:
|
||||
|
|
Loading…
Reference in New Issue