Skip to content

Cover custom log_format URI variables in botlog#10

Merged
sergeyfast merged 1 commit into
masterfrom
fix/botlog-uri-args
May 12, 2026
Merged

Cover custom log_format URI variables in botlog#10
sergeyfast merged 1 commit into
masterfrom
fix/botlog-uri-args

Conversation

@sergeyfast
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #9. After rolling out the query-params fix, real-world logs showed two formats the priority chain missed:

  1. Key=value formats with separate $uri and $args fields (uriPath="$uri" uriQuery="$args") — bot-log got path-only URIs, the original bug came back for this style.
  2. Hybrid combined + key=value logging both "$request" and ru="$request_uri" plus u="$uri" (post-rewrite internal path).

Changes

  • Extract resolveURI(get func(string) string) walking nginx URI variables in priority order: $request_uri$request$uri (+ optional $args / $query_string). Single source of truth for both gonx text path and JSON map path. Closures stay stack-allocated (func literal does not escape per gcflags -m).
  • Add joinPathArgs(path, args) to recombine split fields.
  • Always strip query before normalizePath in every branch — defense in depth so utm/session params can never reach Prometheus uri labels even if an operator logs $request_uri under the uri field name by mistake.

Test plan

  • make fmt lint test — 0 issues, all green
  • New table cases in TestParsedLine_RawURIUnnormalized (13 total):
    • separate $uri + $args (the immediate regression)
    • empty $args (must not append ?)
    • $query_string alias
    • $request_uri directly
    • hybrid format with internal rewrite ($request_uri wins over post-rewrite $uri)
    • hybrid format with comma-rich query strings (gonx quoted-value handling)
    • metric URI stays query-free even if $uri carries query (defensive)
    • JSON map path with base64 signed-URL token (cardinality collapse)
  • Smoke on staging: verify bot-log events from operators using non-$request log formats now carry the full URI

- Extract resolveURI helper walking the nginx URI variables in
  priority order: $request_uri, $request, $uri (+ $args /
  $query_string). Single source of truth for both gonx text path
  and JSON map path; closure-based accessor stays stack-allocated
- Add joinPathArgs to recombine $uri and $args from log_formats
  that split path and query across two fields (key=value style)
- Always strip query before normalizePath so utm/session params
  cannot reach Prometheus uri labels even if an operator logs
  $request_uri under the "uri" field name
- Cover the new branches: separate $uri/$args, $query_string
  alias, $request_uri directly, hybrid combined + key=value with
  internal rewrite, comma-rich query strings, base64 token URLs,
  and the metric-URI-stays-clean invariant
@sergeyfast sergeyfast merged commit 6a585b0 into master May 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant