ilogtail
ilogtail copied to clipboard
存量 Flusher 支持纳秒级日志时间
Discussed in https://github.com/alibaba/ilogtail/discussions/1098
Originally posted by Abingcbc August 29, 2023 iLogtail 从 v1.7.0 开始,提供了对日志时间进行纳秒级精度解析的支持。对于每一个 flusher,需要将解析得到的纳秒时间保存到指定的字段,然后再将日志 flush 到下游。 每个 flush 如何处理纳秒级的时间都有自己的方法。欢迎社区成员一起参与完成对 flusher 的升级改造。
- [x] SLS
- [x] OTLP
- [ ] Clickhouse
- [ ] Elasticsearch
- [ ] GRPC
- [ ] HTTP
- [ ] KafkaV2
- [ ] Loki
- [ ] Pulsar
开发指南
时间处理插件(e.g. processor_gotime
,processor_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已经支持了纳秒时间戳,其实现的方法如下所示:
https://github.com/alibaba/ilogtail/blob/6827f1963148ac87065847ab965d9ea046d69f50/pkg/protocol/converter/otlp.go#L85-L89
开发注意点
在开发过程中,需要注意以下几点:
- 一定要通过context中的EnableTimestampNanosecond开关,对Flusher中填充对应的时间戳精度进行控制。否则,在未使用时间解析插件和开启EnableTimestampNanosecond时,依然填充纳秒字段会导致数据错误。
- 需要补充相关测试,确保填充行为的正确性