Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TT-11470] Add human identifiable information in NodeData (TykTechnol…
…ogies#6229) ## **User description** <!-- Provide a general summary of your changes in the Title above --> ## Description <!-- Describe your changes in detail --> Provide IP, PID and Hostname as identifiers for a node when querying MDCB in the `dataplanes` endpoint. This should be tested with the MDCB version in [this pr](https://github.com/TykTechnologies/tyk-sink/pull/525) ## Related Issue https://tyktech.atlassian.net/browse/TT-11470 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested - Run Tyk in MDCB Env - Enable secure endpoints in MDCB - Consume the `/dataplanes` endpoint, and now you get host details per node ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ## **Type** enhancement, tests ___ ## **Description** - Implemented a buffered logger (`BufferedLogger` and `BufferingFormatter`) to facilitate better logging, especially for testing scenarios. - Enhanced the `Gateway` struct to include node IP address handling, which fetches and stores the IP if not provided. - Added comprehensive tests for new features including the retrieval and logging of node IP addresses. - Introduced a utility function `getIpAddress` to fetch the first non-loopback IPv4 address, enhancing node identification. ___ ## **Changes walkthrough** <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>buffered-logger.go</strong><dd><code>Implement Buffered Logger for Enhanced Testing</code> </dd></summary> <hr> gateway/buffered-logger.go <li>Added a new <code>BufferedLogger</code> and <code>BufferingFormatter</code> to handle logging in <br>a buffered manner, primarily for use in tests.<br> <li> <code>BufferedLogger</code> includes methods to retrieve logs of a specific level.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6229/files#diff-6f5a2cb4531e50ec9d0929cb7c1e5437c72dc829f5a1fe722048b0b117f391a2">+72/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>server.go</strong><dd><code>Enhance Gateway with Node IP Address Handling</code> </dd></summary> <hr> gateway/server.go <li>Added <code>Address</code> field to <code>hostDetails</code> struct to store node IP address.<br> <li> Enhanced <code>getHostDetails</code> to fetch and store the node's IP address if <br>not already provided.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6229/files#diff-4652d1bf175a0be8f5e61ef7177c9666f23e077d8626b73ac9d13358fa8b525b">+9/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>util.go</strong><dd><code>Add Utility Function to Fetch Non-Loopback IPv4 Address</code> </dd></summary> <hr> gateway/util.go <li>Added <code>getIpAddress</code> function to retrieve the first non-loopback IPv4 <br>address.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6229/files#diff-1aa619f406837fb44ac6fba2c8922795eba0285dc4c8d2b0c15755b60b9ee1a5">+25/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests </strong></td><td><table> <tr> <td> <details> <summary><strong>server_test.go</strong><dd><code>Add Tests for Gateway Host Details and IP Address Retrieval</code></dd></summary> <hr> gateway/server_test.go <li>Added tests for <code>getHostDetails</code> to verify correct logging and IP <br>address retrieval.<br> <li> Utilized <code>BufferedLogger</code> in tests to capture log outputs.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6229/files#diff-d9f006370c9748c09affd99d0a4edeb8f3419057703a67fd70838a764a485696">+109/-2</a> </td> </tr> <tr> <td> <details> <summary><strong>util_test.go</strong><dd><code>Implement Tests for IP Address Retrieval Utility Function</code></dd></summary> <hr> gateway/util_test.go <li>Added tests for <code>getIpAddress</code> to ensure it correctly identifies and <br>returns non-loopback IPv4 addresses.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6229/files#diff-3ca88235eab68f9eb691c139bb6e45f10a4038d4c02cf435f66ef7394734f925">+82/-1</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > ✨ **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: sredny buitrago <sredny.buitrago@gmail.com>
- Loading branch information