This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.11.13. 将日志转发到 Loki
除了内部的默认 OpenShift Container Platform Elasticsearch 实例外,您还可以将日志转发到外部 Loki 日志记录系统。
要配置日志转发到 Loki,您必须创建一个 ClusterLogForwarder
自定义资源 (CR),并创建一个输出到 Loki 的 ClusterLogForwarder 自定义资源 (CR),以及使用输出的管道。到 Loki 的输出可以使用 HTTP(不安全)或 HTTPS(安全 HTTP)连接。
先决条件
-
您必须有一个 Loki 日志记录系统在您通过 CR 中的
url
字段指定的 URL 中运行。
流程
创建或编辑定义
ClusterLogForwarder
CR 对象的 YAML 文件:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
ClusterLogForwarder
CR 的名称必须是instance
。- 2
ClusterLogForwarder
CR 的命名空间必须是openshift-logging
。- 3
- 指定输出的名称。
- 4
- 将类型指定为
"loki"
。 - 5
- 将 Loki 系统的 URL 和端口指定为有效的绝对 URL。您可以使用
http
(不安全)或https
(安全 HTTP)协议。如果启用了使用 CIDR 注解的集群范围代理,输出必须是服务器名称或 FQDN,而不是 IP 地址。Loki 用于 HTTP(S) 通讯的默认端口为 3100。 - 6
- 对于安全连接,您可以通过指定
secret
来指定您进行身份验证的https
或http
URL。 - 7
- 对于
https
前缀,请指定 TLS 通信端点所需的 secret 名称。secret 必须存在于openshift-logging
项目中,且必须具有指向它们所代表的相应证书的:tls.crt、tls.key 和 ca-bundle.crt 的密钥。否则,对于http
和https
前缀,您可以指定一个包含用户名和密码的 secret。如需更多信息,请参阅以下"示例:设置包含用户名和密码的 secret"。 - 8
- 可选:指定一个 meta-data key 字段,为 Loki 中的
TenantID
字段生成值。例如,设置tenantKey: kubernetes.namespace_name
使用 Kubernetes 命名空间的名称作为 Loki 中的租户 ID 的值。要查看您可以指定的其他日志记录字段,请查看以下"Additional resources"部分中的"Log Record Fields"链接。 - 9
- 可选:指定一个 meta-data 字段键列表来替换默认的 Loki 标签。Loki 标签名称必须与正则表达式
[a-zA-Z_:][a-zA-Z0-9_:]*
匹配。元数据键中的非法字符会替换为_
以组成标签名称。例如,kubernetes.labels.foo
meta-data 键变成 Loki 标签kubernetes_labels_foo
。如果没有设置labelKeys
,则默认值为:[log_type, kubernetes.namespace_name, kubernetes.pod_name, kubernetes_host]
。尽量保持标签数量少,因为 Loki 会限制允许标签的大小和数量。请参阅配置 Loki、limit_config。您仍然可以使用查询过滤器基于任何日志记录字段进行查询。 - 10
- 可选:指定管道的名称。
- 11
- 使用管道指定要转发的日志类型:
application
、infrastructure
或audit
。 - 12
- 指定使用此管道转发日志时使用的输出名称。
注意由于 Loki 要求按时间戳正确排序日志流,
labelKeys
始终包含kubernetes_host
标签,即使您没有指定它。此包含确保每个流源自单一主机,这样可防止因为不同主机上的时钟差异而导致时间戳出现问题。创建 CR 对象。
oc create -f <file-name>.yaml
$ oc create -f <file-name>.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.13.1. Loki 速率限制错误故障排除 复制链接链接已复制到粘贴板!
如果 Log Forwarder API 将超过速率限制的大量信息转发到 Loki,Loki 会生成速率限制(429
)错误。
这些错误可能会在正常操作过程中发生。例如,当将 logging 子系统添加到已具有某些日志的集群中时,logging 子系统会尝试充分利用现有日志条目时可能会出现速率限制错误。在这种情况下,如果添加新日志的速度小于总速率限值,历史数据最终会被处理,并且不要求用户干预即可解决速率限制错误。
如果速率限制错误持续发生,您可以通过修改 LokiStack
自定义资源(CR)来解决此问题。
LokiStack
CR 在 Grafana 托管的 Loki 上不可用。本主题不适用于 Grafana 托管的 Loki 服务器。
Conditions
- Log Forwarder API 配置为将日志转发到 Loki。
您的系统向 Loki 发送大于 2 MB 的消息块。例如:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 输入
oc logs -n openshift-logging -l component=collector
后,集群中的收集器日志会显示包含以下错误消息之一的行:429 Too Many Requests Ingestion rate limit exceeded
429 Too Many Requests Ingestion rate limit exceeded
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Vector 错误消息示例
2023-08-25T16:08:49.301780Z WARN sink{component_kind="sink" component_id=default_loki_infra component_type=loki component_name=default_loki_infra}: vector::sinks::util::retries: Retrying after error. error=Server responded with an error: 429 Too Many Requests internal_log_rate_limit=true
2023-08-25T16:08:49.301780Z WARN sink{component_kind="sink" component_id=default_loki_infra component_type=loki component_name=default_loki_infra}: vector::sinks::util::retries: Retrying after error. error=Server responded with an error: 429 Too Many Requests internal_log_rate_limit=true
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Fluentd 错误消息示例
2023-08-30 14:52:15 +0000 [warn]: [default_loki_infra] failed to flush the buffer. retry_times=2 next_retry_time=2023-08-30 14:52:19 +0000 chunk="604251225bf5378ed1567231a1c03b8b" error_class=Fluent::Plugin::LokiOutput::LogPostError error="429 Too Many Requests Ingestion rate limit exceeded for user infrastructure (limit: 4194304 bytes/sec) while attempting to ingest '4082' lines totaling '7820025' bytes, reduce log volume or contact your Loki administrator to see if the limit can be increased\n"
2023-08-30 14:52:15 +0000 [warn]: [default_loki_infra] failed to flush the buffer. retry_times=2 next_retry_time=2023-08-30 14:52:19 +0000 chunk="604251225bf5378ed1567231a1c03b8b" error_class=Fluent::Plugin::LokiOutput::LogPostError error="429 Too Many Requests Ingestion rate limit exceeded for user infrastructure (limit: 4194304 bytes/sec) while attempting to ingest '4082' lines totaling '7820025' bytes, reduce log volume or contact your Loki administrator to see if the limit can be increased\n"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在接收结束时也会看到这个错误。例如,在 LokiStack ingester pod 中:
Loki ingester 错误消息示例
level=warn ts=2023-08-30T14:57:34.155592243Z caller=grpc_logging.go:43 duration=1.434942ms method=/logproto.Pusher/Push err="rpc error: code = Code(429) desc = entry with timestamp 2023-08-30 14:57:32.012778399 +0000 UTC ignored, reason: 'Per stream rate limit exceeded (limit: 3MB/sec) while attempting to ingest for stream
level=warn ts=2023-08-30T14:57:34.155592243Z caller=grpc_logging.go:43 duration=1.434942ms method=/logproto.Pusher/Push err="rpc error: code = Code(429) desc = entry with timestamp 2023-08-30 14:57:32.012778399 +0000 UTC ignored, reason: 'Per stream rate limit exceeded (limit: 3MB/sec) while attempting to ingest for stream
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
流程
更新
LokiStack
CR 中的ingestionBurstSize
和ingestionRate
字段:Copy to Clipboard Copied! Toggle word wrap Toggle overflow