teler-sh / teler-waf

teler-waf is a Go HTTP middleware that protects local web services from OWASP Top 10 threats, known vulnerabilities, malicious actors, botnets, unwanted crawlers, and brute force attacks.
https://test.teler.sh
Apache License 2.0
340 stars 30 forks source link

feat(teler): add `listen_addr` & `caller` fields in the log #194

Closed dwisiswant0 closed 3 months ago

dwisiswant0 commented 3 months ago

IMPORTANT: Please do not create a PR without creating an issue first!

(Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request).

Summary

feat(teler): add listen_addr & caller fields in the log

Proposed of changes

This PR fixes/implements the following bugs/features:

How has this been tested?

Proof:

go1.19 test -v -race -count=1 -run=^TestNewWithLogFile$ ./...
cat /tmp/teler-test.log | jq
{
  "level": "warn",
  "ts": 1717703738.552389,
  "msg": "bad crawler",
  "id": "0c1de9f7aff7f6be51c5",
  "category": "BadCrawler",
  "caller": "teler-waf",
  "listen_addr": "*********:36267",
  "request": {
    "method": "GET",
    "path": "/",
    "ip_addr": "*********",
    "headers": {
      "Accept-Encoding": [
        "gzip"
      ],
      "User-Agent": [
        "Go-http-client/1.1"
      ]
    },
    "body": ""
  }
}

Closing issues

Fixes #

Checklist:

dwisiswant0 commented 3 months ago

decisions:

  1. why do I go with caching when calling getListenAddr? well after putting it through some benchmarking, I saw it was doing 3 allocs per op w/o any caching. fetching local addresses was turning out to be a bit of a performance hog, so i figured caching would smooth (cut down that overhead) things out and make everything run way more efficiently.
  2. since it (d34ca96) required by (1), refactoring to initialize (root) cache no matter what the Options.Development value does NOT really have any downsides. :shrug:
codecov-commenter commented 3 months ago

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 78.64%. Comparing base (20b5e7c) to head (18f804e). Report is 5 commits behind head on master.

Files Patch % Lines
utils.go 90.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #194 +/- ## ========================================== + Coverage 78.47% 78.64% +0.16% ========================================== Files 12 12 Lines 920 932 +12 ========================================== + Hits 722 733 +11 - Misses 131 132 +1 Partials 67 67 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.