Skip to content

Commit

Permalink
Merge pull request #703 from kongfei605/log_up
Browse files Browse the repository at this point in the history
log timestamp precision
  • Loading branch information
kongfei605 committed Nov 1, 2023
2 parents 5220368 + d5a601e commit 047c6b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type (
ContainerExclude []string `json:"container_exclude" toml:"container_exclude"`
GlobalProcessingRules []*logsconfig.ProcessingRule `json:"processing_rules" toml:"processing_rules"`
Items []*logsconfig.LogsConfig `json:"items" toml:"items"`
Precision string `toml:"precision" json:"precision"`
Accuracy string `toml:"accuracy" json:"accuracy"`
KafkaConfig
KubeConfig
}
Expand Down
2 changes: 1 addition & 1 deletion config/logs/integration_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type (
IdleTimeout string `mapstructure:"idle_timeout" json:"idle_timeout" toml:"idle_timeout"` // Network
Path string // File, Journald
Topic string `mapstructure:"topic" json:"topic" toml:"topic"`
Precision string `mapstructure:"precision" json:"precision" toml:"precision"`
Accuracy string `mapstructure:"accuracy" json:"accuracy" toml:"accuracy"`

Encoding string `mapstructure:"encoding" json:"encoding" toml:"encoding"` // File
ExcludePaths []string `mapstructure:"exclude_paths" json:"exclude_paths" toml:"exclude_paths"` // File
Expand Down
17 changes: 8 additions & 9 deletions logs/processor/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,19 @@ func (j *jsonEncoder) Encode(msg *message.Message, redactedMsg []byte) ([]byte,
if !msg.Timestamp.IsZero() {
ts = msg.Timestamp
}
precision := config.Config.Logs.Precision
if msg.Origin.LogSource.Config.Precision != "" {
precision = msg.Origin.LogSource.Config.Precision
accuracy := config.Config.Logs.Accuracy
if msg.Origin.LogSource.Config.Accuracy != "" {
accuracy = msg.Origin.LogSource.Config.Accuracy
}
if precision == "" {
precision = "ms"
if accuracy == "" {
accuracy = "ms"
}
timestamp := ts.UnixMilli()
switch precision {
switch accuracy {
case "s":
timestamp = timestamp / 1000 * 1000
timestamp = timestamp / 1000
case "m":
ts := timestamp / 1000 * 1000 // ms
timestamp = ts - ts%60000
timestamp = timestamp / 60000
}
topic := config.Config.Logs.Topic
if msg.Origin.LogSource.Config.Topic != "" {
Expand Down

0 comments on commit 047c6b8

Please sign in to comment.