[Bug]: A refused request's analytics event and traffic log lose the path the client called

オープン 初心者向け
#4,348 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go

調査の方向性

gateway/gateway-runtime/policy-engine/internal/analytics/analytics.go の prepareAnalyticEvent から始めてください。issue では、リクエストパスと空の APIResourceTemplate が重要なポイントとして挙げられています。この値が publishers/traffic_log_event.go と publishers/moesif.go にどのように渡るかを追ってください。拒否されたリクエストにも、成功したリクエストと同様に、呼び出されたパスがトラフィックログ操作、Moesif URI、メタデータに含まれる状態になれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Area/Gateway Aspect/API Severity/Minor Type/Bug
Please select the area the issue is related to

Gateway

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

When a policy refuses a request, for example a 401 from jwt-auth, the analytics event and the traffic log lose the path the client called:

  • The traffic log line's operation has only method, with no path.
  • The Moesif event's URI is the API context alone, and its apiResourceTemplate metadata is missing.

A request that reaches the backend reports its full path in both, so refused requests can't be grouped or filtered by operation.

Observed

Setup: gateway built from current main, with the Moesif publisher and the traffic log enabled. One REST API, context /probe-path-ktel3flz-3, with jwt-auth on GET /data.

Request 1: GET /probe-path-ktel3flz-3/data with a valid token, 200.

  • Traffic log: "operation":{"method":"GET","path":"/probe-path-ktel3flz-3/data"}.
  • Moesif event: URI /probe-path-ktel3flz-3/data, metadata apiResourceTemplate /probe-path-ktel3flz-3/data.

Request 2: the same path with no token, 401.

  • Traffic log: "operation":{"method":"GET"}. The client's path appears only in "target":{"statusCode":401,"destination":"127.0.0.1:33384/probe-path-ktel3flz-3/data"}.
  • Moesif event: URI /probe-path-ktel3flz-3, with no apiResourceTemplate in its metadata.

Expected

The refused request's traffic log operation.path, Moesif URI and apiResourceTemplate are the path the client called, /probe-path-ktel3flz-3/data, as for the request that succeeded.

Cause

prepareAnalyticEvent in gateway/gateway-runtime/policy-engine/internal/analytics/analytics.go sets operation.APIResourceTemplate only from the access log entry's original path, the pre-rewrite :path (Envoy's x-envoy-original-path). gateway/configs/config-template.toml notes that Envoy sets it "whenever a route rewrite occurred". A request a policy refuses never reaches the upstream, so it's never rewritten and the original path is empty.

The same function already reads the request's own path into requestPath (it uses it for target.destination), but doesn't fall back to it.

With APIResourceTemplate empty:

  • The traffic log publisher omits path, because TrafficLogOperation.Path is omitempty in publishers/traffic_log_event.go.
  • The Moesif publisher (publishers/moesif.go, Publish) builds the URI as APIContext + APIResourceTemplate, which is the context alone.
Steps to Reproduce
  1. Start a gateway with [traffic_logging] enabled = true and the Moesif analytics publisher.
  2. Create a REST API with context /orders, operation GET /data and the policy {"name": "jwt-auth", "version": "v1"}, with a key manager configured.
  3. Call GET /orders/data with a valid token. The traffic log line has "path":"/orders/data", and the Moesif URI is /orders/data.
  4. Call GET /orders/data with no Authorization header. It returns 401. The traffic log line has "operation":{"method":"GET"}, and the Moesif URI is /orders.
Severity Level of the Issue

Severity/Minor (Minor functionality is broken. Doesn't need immediate attention)

Environment Details (with versions)

Current main. The gateway is built from source and run by the IT suite (tests/framework), on macOS with Rancher Desktop.

主要言語
Go
スター
85
フォーク
137
平均マージ
1日 12時間
マージ済み PR(30日)
247

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

wso2/api-platform のほかの issue

wso2/api-platform の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。