Skip to content

Commit

Permalink
[TT-13155] Explicitly copy BaseMiddleware for each middleware that ta…
Browse files Browse the repository at this point in the history
…kes it (#6744)

<details open>
<summary><a href="https://tyktech.atlassian.net/browse/TT-13155"
title="TT-13155" target="_blank">TT-13155</a></summary>
  <br />
  <table>
    <tr>
      <th>Summary</th>
<td>[Regression] Gateway Debug logs starting v5.3 only logs
AccessRightsCheck for most of the middlewares</td>
    </tr>
    <tr>
      <th>Type</th>
      <td>
<img alt="Bug"
src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
/>
        Bug
      </td>
    </tr>
    <tr>
      <th>Status</th>
      <td>In Dev</td>
    </tr>
    <tr>
      <th>Points</th>
      <td>N/A</td>
    </tr>
    <tr>
      <th>Labels</th>
<td><a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20'24Bugsmash%20ORDER%20BY%20created%20DESC"
title="'24Bugsmash">'24Bugsmash</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%202025lts%20ORDER%20BY%20created%20DESC"
title="2025lts">2025lts</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20SESAP%20ORDER%20BY%20created%20DESC"
title="SESAP">SESAP</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20customer_bug%20ORDER%20BY%20created%20DESC"
title="customer_bug">customer_bug</a>, <a
href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20jira_escalated%20ORDER%20BY%20created%20DESC"
title="jira_escalated">jira_escalated</a></td>
    </tr>
  </table>
</details>
<!--
  do not remove this marker as it will break jira-lint's functionality.
  added_by_jira_lint
-->

---

### **PR Type**
Enhancement

PR:

- implements per-middleware basemiddleware copy behaviour
- reverts the logger+mutex on base middleware
- touches coprocess/ to better handle grpc server startup, shutdown,
conflicts on static port number - not to swallow errors when
net.Listener fails

___

### **Description**
- Refactored the `BaseMiddleware` initialization process by introducing
a `NewBaseMiddleware` function, encapsulating the creation logic.
- Added a `Copy` method to `BaseMiddleware` to create scoped copies with
a duplicated logger, ensuring middleware-specific logging.
- Updated all middleware initialization in `gateway/api_loader.go` to
use `baseMid.Copy()` for better isolation and logging scope.
- Enhanced code readability and maintainability by centralizing
`BaseMiddleware` creation logic and ensuring proper separation of
concerns.

---------

Co-authored-by: Tit Petric <[email protected]>
  • Loading branch information
titpetric and Tit Petric authored Dec 12, 2024
1 parent 4af6152 commit 9916296
Show file tree
Hide file tree
Showing 15 changed files with 393 additions and 305 deletions.
9 changes: 5 additions & 4 deletions .taskfiles/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ tasks:
- rm -rf coverage && mkdir -p coverage
- for: { var: packages, as: package }
cmd: |-
gotestsum --no-color=false --hide-summary=skipped --raw-command \
go test -p 1 -parallel 1 -json {{.testArgs}} {{.args}} -count=1 -v \
gotestsum --no-color=false --hide-summary=skipped \
--jsonfile coverage/{{.product}}-{{.package | replace "." "gateway" | replace "/" "-"}}.json \
--raw-command go test -p 1 -parallel 1 -json {{.testArgs}} {{.args}} -count=1 -v \
-coverprofile=coverage/{{.package | replace "." "gateway" | replace "/" "-"}}.cov {{.package}} | head -n -2
integration-combined:
Expand Down Expand Up @@ -86,8 +87,8 @@ tasks:
vars:
count: '{{ .count | default "10" }}'
cmds:
- gotestsum --hide-summary=skipped --junitfile=unit-tests.xml --raw-command cat coverage/{{.product}}-all.json
- echo "Slowest {{.count}} tests:" && cat coverage/{{.product}}-all.json | gotestsum tool slowest | head -n {{.count}} | sed -e 's|{{.package}}/||g'
- gotestsum --hide-summary=skipped --junitfile=unit-tests.xml --raw-command cat coverage/*.json
- echo "Slowest {{.count}} tests:" && cat coverage/*.json | gotestsum tool slowest | head -n {{.count}} | sed -e 's|{{.package}}/||g'

clean:
desc: "Clean test outputs"
Expand Down
5 changes: 4 additions & 1 deletion coprocess/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ tasks:
test:
desc: "Run tests"
deps: [ services:up ]
env:
GOTESTSUM_FORMAT: testname
cmds:
- defer: { task: services:down }
- go fmt ./...
- go test -count=1 ./...
- go test -p 1 -parallel 1 -count=1 -json ./... | gotestsum --format testname --hide-summary=all


# lint target is run from CI
lint:
Expand Down
Loading

0 comments on commit 9916296

Please sign in to comment.