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 1 year has passed since last update.

3scale (RHOAM) のアクセスログを確認する

Last updated at Posted at 2023-07-06

このドキュメントの目的

Red Hat の API Management 製品である 3 scale のマネージドサービスである RHAOM (Red Hat OpenShift API Management) のアクセスログを確認してみます。

デフォルトのログの確認

RHOAM のプロジェクトに移動します。

oc project redhat-rhoam-3scale

oc getapicast-xxxxx と名前を付いた Pod を探します。

$ oc get pods | grep apicast | grep Running 
apicast-production-4-j2qv2          2/2     Running     0              118m
apicast-production-4-qs48n          2/2     Running     0              121m
apicast-staging-4-54zrf             2/2     Running     0              121m
apicast-staging-4-chmht             2/2     Running     0              120m
apicast-staging-4-xp8l9             2/2     Running     0              120m
$ 

ここでは Production 環境を使って実験するので、apicast-production-4-xxxxx となっている Pod のログに注目します。

Tutorial で作られる サンプルの API の Prodcutioncurl を投げてみます。

curl https://api-3scale-apicast-production.apps.rosa-xnhx7.2sg0.p1.openshiftapps.com:443/?user_key=8901105c1ca9a74a3c2f361c10c12345

apicast-production-xxxxx のどちらかの Pod にログが残ります。

$ oc logs apicast-production-4-qs48n -f
...
[06/Jul/2023:05:41:08 +0000] api-3scale-apicast-production.apps.rosa-xnhx7.2sg0.p1.openshiftapps.com:8444 127.0.0.1:40102 "GET /?user_key=8901105c1ca9a74a3c02f361c10c12345 HTTP/2.0" 200 987 (0.100) 0

Format は KB に書いてるように、

[$time_local] $host:$server_port $remote_addr:$remote_port "$request" $status $body_bytes_sent ($request_time) $post_action_impact

になっていますが、$remote_addr127.0.0.1 になっています。恐らくトラフィックが Router Pod からフォワードされてきているせいだと思いますが、これだとインターネットに公開した場合に誰がアクセスしているのかわかりません。

Custom logging format を試して見る。

以下のドキュメントを参考に Custom logging format を試して見ます。
この設定はAPI毎に必要です。

以下のようなフォーマットのストリングを用意します。

[{{time_local}}] {{req.headers['HTTP_X_FORWARDED_HOST']}} :{{server_port}} {{remote_addr}}:{{remote_port}} \"{{request}}\"  {{status}} {{body_bytes_sent}} ({{request_time}}) {{req.headers['X-Forwarded-For']}} {{host}} 
  • [{{time_local}}]  タイムスタンプ
  • {{req.headers['HTTP_X_FORWARDED_HOST']}}:{{server_port}} アクセスされたドメイン名:ポート
  • {{remote_addr}}:{{remote_port}} リモートアドレス:ポート
  • "{{request}}"  HTTP リクエストの内容
  • {{status}}  HTTPステータス
  • {{body_bytes_sent}} Bodyバイト
  • ({{request_time}}) リクエスト時間
  • {{req.headers['X-Forwarded-For']}} X-FORWARDED-FOR
  • {{host}} バックエンドのホスト名

「Integration」=>「Policies」から「Add policies」で「Loggging」を追加します。
image.png

「Custom logging format」の所に前述のストリングを入力します。
image.png

「Update Policy」をクリックします。
image.png

「Update Polciy Chain」をクリックします。
image.png

「Integration」=>「Configuration」に行きます。
image.png

「Staging」=>「Production」と Promotion していきます。
image.png

Production にデプロイされてから、反映されるまで数分かかるようです。
curl でアクセスしてみます。

curl https://api-3scale-apicast-production.apps.rosa-xnhx7.2sg0.p1.openshiftapps.com:443/?user_key=8901105c1ca9a74a3c2f361c10c0850

Pod のログを確認してみます。想定通りに出力されているようです。

$ oc logs apicast-production-4-qs48n -f
...
[06/Jul/2023:11:53:31 +0000] api-3scale-apicast-production.apps.rosa-xnhx7.2sg0.p1.openshiftapps.com :8444 127.0.0.1:59892 \"GET /?user_key=8901105c1ca9a74a3c02f361c10c0850 HTTP/2.0\"  200 987 (0.000) 217.178.16.46 echo-api.3scale.net 
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?