使用 fluentd 更新 mongo 条记录

Update mongo records with fluentd

我们需要将 nodejs 应用程序日志保存为 MongoDB 处的记录。 大多数记录我们应该创建,但有些记录只需要更新。

我们想使用 Fluentd。我看到它有将日志插入 mongo 的选项,但我找不到更新现有记录的方法。

有办法实现吗?

这是我目前的td-agent.conf(还在开发中):

<match mongo.*>
  @type mongo
  host localhost
  port 27017
  database my-db

  # Set 'tag_mapped' if you want to use tag mapped mode.
  tag_mapped

  # If the tag is "mongo.foo", then the prefix "mongo." is removed.
  # The inserted collection name is "foo".
  remove_tag_prefix mongo.

  # This configuration is used if the tag is not found. The default is 'untagged'.
  collection misc
</match>

查看documentation and code for fluentd mongo插件,好像不支持update/upsert操作。

目前仅执行insert_many操作。

get_collection(database, collection, @collection_options).insert_many(records)

https://github.com/fluent/fluent-plugin-mongo/blob/master/lib/fluent/plugin/out_mongo.rb#L265

其中一个选项是使用 update_many(或批量更新插入)操作在此回购协议上创建功能请求或拉取请求,但这需要您在每个文档插入中发送更新字段。


更新 - 任何替代工具?

我能想到 logstash 但即使它有一堆功能请求打开以支持 update/upsert 到 MongoDB。

https://github.com/logstash-plugins/logstash-output-mongodb/issues/16

当您查看以上 link 评论时,有人建议您通常不希望对日志存储执行更新操作。

https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying

我会说首先重新审视你的更新日志方法的设计,否则创建一个可以执行更新操作(替换 fluentd 或从 fluentd 传播到自定义应用程序到 mongodb).