10.13. ログの Loki への転送
内部のデフォルト Red Hat OpenShift Service on AWS Elasticsearch インスタンスに加えて、またはその代わりに外部の Loki ロギングシステムにログを転送できます。
Loki へのログ転送を設定するには、Loki の出力と、出力を使用するパイプラインで ClusterLogForwarder カスタムリソース (CR) を作成する必要があります。Loki への出力は HTTP (セキュアでない) または HTTPS (セキュアな HTTP) 接続を使用できます。
前提条件
-
CR の
urlフィールドで指定する URL で Loki ロギングシステムが実行されている必要がある。
手順
ClusterLogForwarderCR オブジェクトを定義する YAML ファイルを作成または編集します。apiVersion: "logging.openshift.io/v1" kind: ClusterLogForwarder metadata: name: instance 1 namespace: openshift-logging 2 spec: outputs: - name: loki-insecure 3 type: "loki" 4 url: http://loki.insecure.com:3100 5 loki: tenantKey: kubernetes.namespace_name labelKeys: kubernetes.labels.foo - name: loki-secure 6 type: "loki" url: https://loki.secure.com:3100 secret: name: loki-secret 7 loki: tenantKey: kubernetes.namespace_name 8 labelKeys: kubernetes.labels.foo 9 pipelines: - name: application-logs 10 inputRefs: 11 - application - audit outputRefs: 12 - loki-secure- 1
ClusterLogForwarderCR の名前はinstanceである必要があります。- 2
ClusterLogForwarderCR の namespace はopenshift-loggingである必要があります。- 3
- 出力の名前を指定します。
- 4
- タイプを
lokiとして指定します。 - 5
- Loki システムの URL およびポートを有効な絶対 URL として指定します。
http(セキュアでない) プロトコルまたはhttps(セキュアな HTTP) プロトコルを使用できます。CIDR アノテーションを使用するクラスター全体のプロキシーが有効になっている場合、出力は IP アドレスではなくサーバー名または FQDN である必要があります。HTTP(S) 通信用の Loki のデフォルトポートは 3100 です。 - 6
- セキュアな接続では、
シークレットを指定して、認証するhttpsまたはhttpURL を指定できます。 - 7
https接頭辞の場合は、TLS 通信のエンドポイントに必要なシークレットの名前を指定します。シークレットはopenshift-loggingプロジェクトに存在し、tls.crt、tls.key および ca-bundle.crt のキーが含まれる必要があります。これらは、それぞれが表す証明書を参照します。それ以外の場合、httpおよびhttps接頭辞の場合は、ユーザー名とパスワードを含むシークレットを指定できます。詳細は、Example: Setting secret that contains a username and password.を参照してください。- 8
- オプション: メタデータキーフィールドを指定して、Loki の
TenantIDフィールドの値を生成します。たとえば、tenantKey: kubernetes.namespace_nameを設定すると、Kubernetes namespace の名前を Loki のテナント ID の値として使用します。他にどのログレコードフィールドを指定できるかを確認するには、以下の Additional resources セクションの Log Record Fields リンクを参照してください。 - 9
- オプション: デフォルトの Loki ラベルを置き換えるメタデータフィールドキーの一覧を指定します。loki ラベル名は、正規表現
[a-zA-Z_:][a-zA-Z0-9_:]*と一致する必要があります。ラベル名を形成するため、メタデータキーの無効な文字は_に置き換えられます。たとえば、kubernetes.labels.foometa-data キーは Loki ラベルkubernetes_labels_fooになります。labelKeysを設定しないと、デフォルト値は[log_type, kubernetes.namespace_name, kubernetes.pod_name, kubernetes_host]です。Loki で指定可能なラベルのサイズと数に制限があるため、ラベルのセットを小さくします。Configuring Loki, limits_config を参照してください。クエリーフィルターを使用して、ログレコードフィールドに基づいてクエリーを実行できます。 - 10
- オプション: パイプラインの名前を指定します。
- 11
- パイプラインを使用して転送するログタイプ (
application、infrastructureまたはaudit) を指定します。 - 12
- このパイプラインでログを転送する時に使用する出力の名前を指定します。
注記Loki ではログストリームを正しくタイムスタンプで順序付ける必要があるため、
labelKeysには指定しなくてもkubernetes_hostラベルセットが常に含まれます。このラベルセットが含まれることで、各ストリームが 1 つのホストから発信されるので、ホストのクロック間の誤差が原因でタイムスタンプの順番が乱れないようになります。CR オブジェクトを作成します。
$ oc create -f <file-name>.yaml
10.13.1. "entry out of order" エラーのトラブルシューティング
Fluentd がレート制限を超えるサイズの大きいメッセージブロックを Loki ロギングシステムに転送する場合は、Loki は "entry out of order" のエラーを生成します。この問題を修正するには、Loki サーバー設定ファイル loki.yaml のいくつかの値を更新します。
loki.yaml は、Grafana がホストする Loki では使用できません。このトピックは、Grafana がホストする Loki サーバーには適用されません。
条件
-
Cluster Log Forwarderカスタムリソースは、ログを Loki に転送するように設定されています。 システムは、次のような 2MB を超えるメッセージのブロックを Loki に送信します。
"values":[["1630410392689800468","{\"kind\":\"Event\",\"apiVersion\":\ ....... ...... ...... ...... \"received_at\":\"2021-08-31T11:46:32.800278+00:00\",\"version\":\"1.7.4 1.6.0\"}},\"@timestamp\":\"2021-08-31T11:46:32.799692+00:00\",\"viaq_index_name\":\"audit-write\",\"viaq_msg_id\":\"MzFjYjJkZjItNjY0MC00YWU4LWIwMTEtNGNmM2E5ZmViMGU4\",\"log_type\":\"audit\"}"]]}]}oc logs -c fluentdと入力すると、OpenShift Logging クラスターの Fluentd ログに次のメッセージが表示されます。429 Too Many Requests Ingestion rate limit exceeded (limit: 8388608 bytes/sec) while attempting to ingest '2140' lines totaling '3285284' bytes 429 Too Many Requests Ingestion rate limit exceeded' or '500 Internal Server Error rpc error: code = ResourceExhausted desc = grpc: received message larger than max (5277702 vs. 4194304)'
Loki サーバーでログを開くと、次のような
entry out of orderメッセージが表示されます。,\nentry with timestamp 2021-08-18 05:58:55.061936 +0000 UTC ignored, reason: 'entry out of order' for stream: {fluentd_thread=\"flush_thread_0\", log_type=\"audit\"},\nentry with timestamp 2021-08-18 06:01:18.290229 +0000 UTC ignored, reason: 'entry out of order' for stream: {fluentd_thread="flush_thread_0", log_type="audit"}
手順
Loki サーバーの
loki.yaml設定ファイルの次のフィールドを、ここに示す値で更新します。-
grpc_server_max_recv_msg_size: 8388608 -
chunk_target_size: 8388608 -
ingestion_rate_mb: 8 -
ingestion_burst_size_mb: 16
-
-
loki.yamlの変更を Loki サーバーに適用します。
loki.yaml ファイルの例
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
grpc_server_max_recv_msg_size: 8388608
ingester:
wal:
enabled: true
dir: /tmp/wal
lifecycler:
address: 127.0.0.1
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 1h # Any chunk not receiving new logs in this time will be flushed
chunk_target_size: 8388608
max_chunk_age: 1h # All chunks will be flushed when they hit this age, default is 1h
chunk_retain_period: 30s # Must be greater than index read cache TTL if using an index cache (Default index read cache TTL is 5m)
max_transfer_retries: 0 # Chunk transfers disabled
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
storage_config:
boltdb_shipper:
active_index_directory: /tmp/loki/boltdb-shipper-active
cache_location: /tmp/loki/boltdb-shipper-cache
cache_ttl: 24h # Can be increased for faster performance over longer query periods, uses more disk space
shared_store: filesystem
filesystem:
directory: /tmp/loki/chunks
compactor:
working_directory: /tmp/loki/boltdb-shipper-compactor
shared_store: filesystem
limits_config:
reject_old_samples: true
reject_old_samples_max_age: 12h
ingestion_rate_mb: 8
ingestion_burst_size_mb: 16
chunk_store_config:
max_look_back_period: 0s
table_manager:
retention_deletes_enabled: false
retention_period: 0s
ruler:
storage:
type: local
local:
directory: /tmp/loki/rules
rule_path: /tmp/loki/rules-temp
alertmanager_url: http://localhost:9093
ring:
kvstore:
store: inmemory
enable_api: true
関連情報
関連情報