New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TT-11470] Add human identifiable information in NodeData #6229
base: master
Are you sure you want to change the base?
Conversation
PR Description updated to latest commit (904be81) |
PR Review
Code feedback:
✨ Review tool usage guide:Overview: The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
See the review usage page for a comprehensive guide on using this tool. |
PR Code Suggestions
✨ Improve tool usage guide:Overview:
See the improve usage page for a comprehensive guide on using this tool. |
Hey @padiazg, nice to see a contribution from your side. Could you please consider moving any extractable parts into subpackages of /internal? The PR:
if there's no better location, create an |
💥 CI tests failed 🙈git-statediff --git a/gateway/server_test.go b/gateway/server_test.go
index 1d1aab4..3c32100 100644
--- a/gateway/server_test.go
+++ b/gateway/server_test.go
@@ -9,11 +9,12 @@ import (
"testing"
"time"
+ "github.com/sirupsen/logrus"
+ "github.com/stretchr/testify/assert"
+
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/internal/otel"
"github.com/TykTechnologies/tyk/user"
- "github.com/sirupsen/logrus"
- "github.com/stretchr/testify/assert"
)
func TestGateway_afterConfSetup(t *testing.T) {
diff --git a/gateway/util_test.go b/gateway/util_test.go
index 6d18a1c..e50f08b 100644
--- a/gateway/util_test.go
+++ b/gateway/util_test.go
@@ -6,9 +6,10 @@ import (
"strings"
"testing"
+ "github.com/stretchr/testify/assert"
+
"github.com/TykTechnologies/tyk/apidef"
"github.com/TykTechnologies/tyk/config"
- "github.com/stretchr/testify/assert"
)
func TestAppendIfMissingUniqueness(t *testing.T) { Please look at the run or in the Checks tab. |
GetIpAddres returns all addreses, IPv4 and IPv6 Updated tests to test IPv6
💥 CI tests failed 🙈git-statediff --git a/gateway/server_test.go b/gateway/server_test.go
index c7fd075..41e8cab 100644
--- a/gateway/server_test.go
+++ b/gateway/server_test.go
@@ -8,12 +8,13 @@ import (
"testing"
"time"
+ "github.com/sirupsen/logrus"
+ "github.com/stretchr/testify/assert"
+
"github.com/TykTechnologies/tyk/config"
"github.com/TykTechnologies/tyk/internal/netutil"
"github.com/TykTechnologies/tyk/internal/otel"
"github.com/TykTechnologies/tyk/user"
- "github.com/sirupsen/logrus"
- "github.com/stretchr/testify/assert"
)
func TestGateway_afterConfSetup(t *testing.T) { Please look at the run or in the Checks tab. |
Updated tests that uses it
this is meant to be used only to catch the logs during tests, not to be used in any regular flow |
…t to use testify/assert
…gies/tyk into TT-11470-human-readable-info
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API Changes --- prev.txt 2024-05-23 12:48:40.156587638 +0000
+++ current.txt 2024-05-23 12:48:37.220569796 +0000
@@ -733,14 +733,6 @@
"proxy": {
"type": ["object", "null"],
"properties": {
- "features": {
- "type": ["object", "null"],
- "properties": {
- "use_immutable_headers": {
- "type": "boolean"
- }
- }
- },
"auth_headers": {
"type": ["object", "null"]
},
@@ -1366,7 +1358,6 @@
which will be hosted alongside the api.
type GraphQLProxyConfig struct {
- Features GraphQLProxyFeaturesConfig `bson:"features" json:"features"`
AuthHeaders map[string]string `bson:"auth_headers" json:"auth_headers"`
SubscriptionType SubscriptionType `bson:"subscription_type" json:"subscription_type,omitempty"`
RequestHeaders map[string]string `bson:"request_headers" json:"request_headers"`
@@ -1374,10 +1365,6 @@
RequestHeadersRewrite map[string]RequestHeadersRewriteConfig `json:"request_headers_rewrite" bson:"request_headers_rewrite"`
}
-type GraphQLProxyFeaturesConfig struct {
- UseImmutableHeaders bool `bson:"use_immutable_headers" json:"use_immutable_headers"`
-}
-
type GraphQLResponseExtensions struct {
OnErrorForwarding bool `bson:"on_error_forwarding" json:"on_error_forwarding"`
}
@@ -1605,6 +1592,7 @@
Tags []string `json:"tags"`
Health map[string]HealthCheckItem `json:"health"`
Stats GWStats `json:"stats"`
+ HostDetails model.HostDetails `json:"host_details"`
}
type NotificationsManager struct {
@@ -11496,6 +11484,37 @@
TYPES
+type BufferedLog struct {
+ Message string `json:"message"`
+ Time time.Time `json:"time"`
+ Level logrus.Level `json:"level"`
+}
+ BufferedLog is the struct that holds the log entry.
+
+type BufferedLogger struct {
+ *logrus.Logger
+ // Has unexported fields.
+}
+ BufferedLogger is the struct that holds the logger and the buffer.
+
+func NewBufferingLogger() *BufferedLogger
+ NewBufferingLogger creates a new buffered logger.
+
+func (bl *BufferedLogger) ClearLogs()
+ ClearLogs clears the logs from the buffer. IMPORTANT: Must be called before
+ each test iteration.
+
+func (bl *BufferedLogger) GetLogs(Level logrus.Level) []*BufferedLog
+ GetLogs returns the logs that are stored in the buffer.
+
+type BufferingFormatter struct {
+ // Has unexported fields.
+}
+ BufferingFormatter is the struct that holds the buffer of the logs.
+
+func (f *BufferingFormatter) Format(entry *logrus.Entry) ([]byte, error)
+ Format is the method that stores the log entry in the buffer.
+
type ClientOption func(*http.Client)
Options for populating a http.Client
|
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
@@ -1540,6 +1540,17 @@ func (gw *Gateway) getHostDetails(file string) { | |||
if gw.hostDetails.Hostname, err = os.Hostname(); err != nil { | |||
mainLog.Error("Failed to get hostname: ", err) | |||
} | |||
|
|||
gw.hostDetails.Address = gw.GetConfig().ListenAddress | |||
if gw.hostDetails.Address == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is correct. Wouldn't listenaddress be set to 0.0.0.0 to listen on all interfaces by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably, but that was on the original code: https://github.com/TykTechnologies/tyk/blob/master/gateway/server.go#L1923
I just changed gw.GetConfig().ListenAddress
for gw.hostDetails.Address
not to call the function twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly reviewed for the code structure conventions, models/ needs a rename, everything else LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! Only address the comment above from Tit
💥 CI tests failed 🙈git-statediff --git a/gateway/server.go b/gateway/server.go
index 11e0676..0f7a00c 100644
--- a/gateway/server.go
+++ b/gateway/server.go
@@ -25,6 +25,7 @@ import (
textTemplate "text/template"
"time"
+ "github.com/TykTechnologies/storage/temporal/model"
"github.com/TykTechnologies/tyk/internal/crypto"
"github.com/TykTechnologies/tyk/internal/httputil"
"github.com/TykTechnologies/tyk/internal/otel" Please look at the run or in the Checks tab. |
Quality Gate passedIssues Measures |
User description
Description
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 prRelated Issue
https://tyktech.atlassian.net/browse/TT-11470
Motivation and Context
How This Has Been Tested
/dataplanes
endpoint, and now you get host details per nodeScreenshots (if appropriate)
Types of changes
Checklist
Type
enhancement, tests
Description
BufferedLogger
andBufferingFormatter
) to facilitate better logging, especially for testing scenarios.Gateway
struct to include node IP address handling, which fetches and stores the IP if not provided.getIpAddress
to fetch the first non-loopback IPv4 address, enhancing node identification.Changes walkthrough
buffered-logger.go
Implement Buffered Logger for Enhanced Testing
gateway/buffered-logger.go
BufferedLogger
andBufferingFormatter
to handle logging ina buffered manner, primarily for use in tests.
BufferedLogger
includes methods to retrieve logs of a specific level.server.go
Enhance Gateway with Node IP Address Handling
gateway/server.go
Address
field tohostDetails
struct to store node IP address.getHostDetails
to fetch and store the node's IP address ifnot already provided.
util.go
Add Utility Function to Fetch Non-Loopback IPv4 Address
gateway/util.go
getIpAddress
function to retrieve the first non-loopback IPv4address.
server_test.go
Add Tests for Gateway Host Details and IP Address Retrieval
gateway/server_test.go
getHostDetails
to verify correct logging and IPaddress retrieval.
BufferedLogger
in tests to capture log outputs.util_test.go
Implement Tests for IP Address Retrieval Utility Function
gateway/util_test.go
getIpAddress
to ensure it correctly identifies andreturns non-loopback IPv4 addresses.