Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

存量 Flusher 支持纳秒级日志时间 #1164

Open
2 of 9 tasks
messixukejia opened this issue Oct 5, 2023 Discussed in #1098 · 1 comment
Open
2 of 9 tasks

存量 Flusher 支持纳秒级日志时间 #1164

messixukejia opened this issue Oct 5, 2023 Discussed in #1098 · 1 comment

Comments

@messixukejia
Copy link
Collaborator

Discussed in #1098

Originally posted by Abingcbc August 29, 2023
iLogtail 从 v1.7.0 开始,提供了对日志时间进行纳秒级精度解析的支持。对于每一个 flusher,需要将解析得到的纳秒时间保存到指定的字段,然后再将日志 flush 到下游。
每个 flush 如何处理纳秒级的时间都有自己的方法。欢迎社区成员一起参与完成对 flusher 的升级改造。

  • SLS
  • OTLP
  • Clickhouse
  • Elasticsearch
  • GRPC
  • HTTP
  • KafkaV2
  • Loki
  • Pulsar
@Abingcbc
Copy link
Collaborator

Abingcbc commented May 23, 2024

开发指南

时间处理插件(e.g. processor_gotimeprocessor_strptime)在配置全局参数EnableTimestampNanosecond时,会在Log中添加纳秒时间。

if p.context.GetPipelineScopeConfig().EnableTimestampNanosecond {
	protocol.SetLogTimeWithNano(log, uint32(parsedTime.Unix()), uint32(parsedTime.Nanosecond()))
} else {
	protocol.SetLogTime(log, uint32(parsedTime.Unix()))
}

通过log.TimeNs就可以获取一条日志的纳秒时间。

在flusher阶段,采集到的日志需要转换成对应数据源的数据格式。因此,可以在convertor将日志从iLogtail的Log转换成数据源格式时,将纳秒时间填充到对应的字段。
例如,现在OTLP Flusher已经支持了纳秒时间戳,其实现的方法如下所示:

if c.GlobalConfig.EnableTimestampNanosecond {
logRecord.SetTimestamp(pcommon.Timestamp(uint64(log.Time)*uint64(time.Second)) + pcommon.Timestamp(uint64(*log.TimeNs)*uint64(time.Nanosecond)))
} else {
logRecord.SetTimestamp(pcommon.Timestamp(uint64(log.Time) * uint64(time.Second)))
}

开发注意点

在开发过程中,需要注意以下几点:

  1. 一定要通过context中的EnableTimestampNanosecond开关,对Flusher中填充对应的时间戳精度进行控制。否则,在未使用时间解析插件和开启EnableTimestampNanosecond时,依然填充纳秒字段会导致数据错误。
  2. 需要补充相关测试,确保填充行为的正确性

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants