0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ambassador Edge StackでアクセスログをJSON且つカスタムフォーマットにする方法

Last updated at Posted at 2020-07-22

Ambassador API Gatewayではまだ https://github.com/datawire/ambassador/issues/2593 が対応されていないですが、 Ambassador Edge Stack (API Gatewayの上位互換) ではJSONでカスタムフォーマットを行えるようになりました。
しかし、envoy_log_formatの設定の記述方法が皆無だったので後の人のためにメモを残しておきます。

設定ファイルサンプル

---
apiVersion: getambassador.io/v1
kind: Module
metadata:
  name: ambassador
spec:
  config:
    envoy_log_type: json
    envoy_log_format: 
      start_time: '%START_TIME%'
      method: '%REQ(:METHOD)%'
      path: '%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%'
      protocol: '%PROTOCOL%'
      response_code: '%RESPONSE_CODE%'
      response_flags: '%RESPONSE_FLAGS%'
      bytes_received: '%BYTES_RECEIVED%'
      bytes_sent: '%BYTES_SENT%'
      duration: '%DURATION%'
      upstream_service_time: '%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%'
      x_forwarded_for: '%REQ(X-FORWARDED-FOR)%'
      user_agent: '%REQ(USER-AGENT)%'
      request_id: '%REQ(X-REQUEST-ID)%'
      authority: '%REQ(:AUTHORITY)%'
      upstream_host: '%UPSTREAM_HOST%'
      upstream_cluster: '%UPSTREAM_CLUSTER%'
      upstream_local_address: '%UPSTREAM_LOCAL_ADDRESS%'
      downstream_local_address: '%DOWNSTREAM_LOCAL_ADDRESS%'
      downstream_remote_address: '%DOWNSTREAM_REMOTE_ADDRESS%'
      requested_server_name: '%REQUESTED_SERVER_NAME%'
      istio_policy_status: '%DYNAMIC_METADATA(istio.mixer:status)%'
      upstream_transport_failure_reason: '%UPSTREAM_TRANSPORT_FAILURE_REASON%'

簡易説明

デフォルトのログは何を出力しているかは https://github.com/datawire/ambassador/blob/master/python/ambassador/envoy/v2/v2listener.py#L725-L748 に書かれています。
これをそのまま envoy_log_format の形式にしたものが上になります。

苦労したところ

https://www.getambassador.io/docs/latest/topics/running/ambassador/ の envoy_log_format に

Defines the envoy log line format. See this page for a complete list of operators

と書かれてリンク飛んでいろいろ試しましたが、結果的にはDictである必要があるみたいです。

あとは独自のヘッダー等は %REQ(HOGEHOGE)% で取れるので煮るなり焼くなりできます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?