Closed buraksezer closed 2 months ago
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪ |
🧪 No relevant tests |
🔒 No security concerns identified |
⚡ Key issues to review Error Handling The error handling in `getStreamsConfig` method might lead to silent failures which can be hard to debug. Specifically, if JSON marshaling or unmarshaling fails, the method returns nil without logging the error. Consider adding error logs before returning nil in cases of failures. Code Duplication The logging for stream configuration changes appears to be duplicated in the `getStreamsConfig` method. This could be refactored to reduce redundancy and improve maintainability. |
Category | Suggestion | Score |
Best practice |
Add type assertion for
___
**Use a type assertion to ensure that | 9 |
Possible bug |
Add a check for the 'streams' key in the
___
**Consider checking for the presence of the 'streams' key in the | 8 |
Enhancement |
Log errors from JSON operations to aid in debugging___ **To improve error handling, consider logging the error fromjson.Marshal and json.Unmarshal operations before returning nil. This will help in debugging and understanding why the marshaling or unmarshaling failed.** [gateway/mw_streaming.go [216-224]](https://github.com/TykTechnologies/tyk/pull/6519/files#diff-6f565750150d990575c808f1ca8f38483160dc6edf05f1534cd0bedb27c2e6c8R216-R224) ```diff data, err := json.Marshal(tykStreamingConfig) if err != nil { + s.Logger().Errorf("Failed to marshal tykStreamingConfig: %v", err) return nil } streamsConfig := &StreamsConfig{} err = json.Unmarshal(data, streamsConfig) if err != nil { + s.Logger().Errorf("Failed to unmarshal into StreamsConfig: %v", err) return nil } ``` Suggestion importance[1-10]: 7Why: Logging errors from JSON operations improves error handling and aids in debugging, making it easier to identify issues during marshaling and unmarshaling. | 7 |
Performance |
Optimize the check for
___
**Instead of checking for | 6 |
I believe for CI/CD use case, this field can be optional, right?
This PR should be reworked due to conflicts.
User description
PR for https://tyktech.atlassian.net/browse/TT-13036
Adding a version for streams config It is expected that the configuration will evolve heavily in the feature when gathering feedback from users. Therefore a version will be important to allow breaking changes if needed while keeping old configurations possible.
For MVP the version can live inside an info block in the streams config section.
PR Type
enhancement
Description
StreamsConfig
struct to encapsulate the streaming configuration, including anInfo
section with aVersion
field.initStreams
method to utilize the newStreamsConfig
struct for better organization and future extensibility.getStreamsConfig
method to return a pointer toStreamsConfig
, improving the handling of streaming configurations.Changes walkthrough 📝
mw_streaming.go
Refactor streaming configuration with new StreamsConfig struct
gateway/mw_streaming.go
StreamsConfig
struct to encapsulate streamingconfiguration.
initStreams
method to use the newStreamsConfig
struct.getStreamsConfig
method to return aStreamsConfig
pointer.processing.