[Bug]: content-length-guardrail policy does not mark streamed violations in analytics

Open
#4,323 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
56/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
go
Domain
observability

Research direction

Start by locating the content-length-guardrail policy implementation and comparing the streamed response violation path with the request and buffered response paths that set analytics metadata. Trace where the stream violation sets its error and fault, then check the analytics event for isGuardrailHit and guardrailName. Done means streamed violations include both fields, matching the other violation paths.

Written by the indexing model from the issue text.

Description

Area/Policies Aspect/Monitoring Severity/Minor Type/Bug
Please select the area the issue is related to

Gateway

Please select the aspect the issue is related to

Aspect/Monitoring (Metrics, observability, health checks, alerts)

Description

The content-length-guardrail policy does not mark a streamed response violation in analytics. The analytics event has no isGuardrailHit or guardrailName metadata.

Request violations and buffered response violations set both fields. When the policy ends a stream for a violation, it sets the error and the fault but leaves the analytics metadata empty.

The enforcement itself works. The client gets the guardrail's error event and the stream ends. Only the analytics record is incomplete. Dashboards and reports that count guardrail hits from this metadata miss every streamed violation.

Steps to Reproduce
  1. Create a REST API with the content-length-guardrail policy on an operation, with analytics enabled on the Gateway:
    {"name":"content-length-guardrail","version":"v1","params":{"response":{"enabled":true,"min":1,"max":5}}}
    
  2. Send a request whose upstream replies with an SSE stream. The first delta has more than 5 bytes of content:
    data: {"choices":[{"delta":{"content":"this is longer than five bytes"}}]}
    
    data: [DONE]
    
  3. The client gets the guardrail's SSE error event, and the stream ends. This is expected.
  4. Read the request's analytics event. It has neither isGuardrailHit nor guardrailName in its metadata.
  5. Repeat with a request over a request-side max, or a buffered response over max. The event has isGuardrailHit: true and guardrailName: content-length-guardrail.
Severity Level of the Issue

Severity/Minor (Non-critical functionality. Can be fixed in future releases)

Environment Details (with versions)
  • Policy: content-length-guardrail v1.1.0, wso2/gateway-controllers main (4f1520a8)
  • Gateway versions: 1.1.0 (patched), 1.2.0 and latest (main-59dcd51)
  • macOS 27.0.1 (Apple silicon), Colima 0.10.3, Docker Engine 29.5.2
Dominant language
Go
Stars
85
Forks
137
Avg merge
1d 12h
Merged PRs (30d)
247

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wso2/api-platform

All issues in wso2/api-platform

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.