问题描述
我正在尝试在google-fluentd的配置文件中添加标签。根据文档https://cloud.google.com/logging/docs/agent/configuration#label-setup,它指出labels
用于静态标签。但是,有什么方法可以将环境变量作为值添加到这些标签?
...
<match **>
@type google_cloud
# Adding labels to the log metadata
labels {
"source": "transform","transformId": "\"#{ENV['TRANSFORM_ID']}\""
}
buffer_type file
buffer_path /var/log/google-fluentd/buffers
...
上面的代码段中引用了主/etc/google-fluentd/google-fluentd.conf
文件。静态标签source: transform
已添加到日志中,但是从transformId
获取值的env variable
无法正常工作。
解决方法
我通过使用以下方法使它起作用:
labels "#{ENV['LABEL_JSON']}"
然后传递env变量-键值对,例如
"LABEL_JSON": "{\"TRANSFORM_ID\": \"transformId\",\"TRANSFORM_NAME\": \"jane\"}"