Skip to content
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-13008]: modified default streams logger #6682

Merged
merged 1 commit into from
Oct 30, 2024
Merged

Conversation

kofoworola
Copy link
Contributor

@kofoworola kofoworola commented Oct 29, 2024

User description

Description

TT-13008

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • 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

  • 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

PR Type

enhancement


Description

  • Enhanced the stream manager by adding a logger configuration to the stream creation process.
  • Configured the logger with specific settings such as level, format, timestamp, and static fields to improve logging capabilities.

PRDescriptionHeader.CHANGES_WALKTHROUGH

Relevant files
Enhancement
manager.go
Add logger configuration to stream creation in manager     

ee/middleware/streams/manager.go

  • Added a logger configuration to the stream creation process.
  • Configured logger with level, format, timestamp, and static fields.
  • Enhanced logging for stream management.
  • +10/-0   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @buger
    Copy link
    Member

    buger commented Oct 29, 2024

    💔 The detected issue is not in one of the allowed statuses 💔

    Detected Status Blocked
    Allowed Statuses In Dev,In Code Review,Ready for Testing,In Test,In Progress,In Review ✔️

    Please ensure your jira story is in one of the allowed statuses

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Hardcoded Values
    The logger configuration in the createStream function has hardcoded values for logging level, format, and timestamp inclusion. This might not be flexible enough for different environments or user preferences. Consider making these configurable through external configuration or environment variables.

    Copy link
    Contributor

    API Changes

    no api changes detected

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Security
    Validate streamID to prevent potential formatting or security issues

    Validate the streamID to ensure it does not contain characters that might break the
    formatting or injection issues in streamFullID.

    ee/middleware/streams/manager.go [85]

    +if !isValidStreamID(streamID) {
    +    return fmt.Errorf("invalid stream ID")
    +}
     streamFullID := fmt.Sprintf("%s_%s", sm.mw.Spec.APIID, streamID)
    Suggestion importance[1-10]: 9

    Why: Validating streamID is important for preventing formatting or injection issues, which could lead to security vulnerabilities, making this a high-impact suggestion.

    9
    Possible issue
    Add a check to prevent overwriting an existing logger configuration in the config map

    Ensure that the config map has not already defined a "logger" key to avoid potential
    overwrites which could lead to unexpected behavior.

    ee/middleware/streams/manager.go [89-95]

    -config["logger"] = map[string]interface{}{
    -    "level":         "INFO",
    -    "format":        "json",
    -    "add_timestamp": true,
    -    "static_fields": map[string]interface{
    -        "stream": streamID,
    -    },
    +if _, exists := config["logger"]; !exists {
    +    config["logger"] = map[string]interface{}{
    +        "level":         "INFO",
    +        "format":        "json",
    +        "add_timestamp": true,
    +        "static_fields": map[string]interface{
    +            "stream": streamID,
    +        },
    +    }
     }
    Suggestion importance[1-10]: 8

    Why: Adding a check to ensure the "logger" key is not already defined prevents potential overwrites, which could lead to unexpected behavior, making this a crucial improvement for robustness.

    8
    Best practice
    Replace hardcoded logger level with a constant for improved maintainability

    Consider using a predefined constant for the logger level instead of a hardcoded
    string to facilitate easier changes and consistency across different parts of the
    application.

    ee/middleware/streams/manager.go [90]

    -"level": "INFO",
    +"level": DefaultLogLevel,
    Suggestion importance[1-10]: 7

    Why: Using a predefined constant for the logger level enhances maintainability and consistency across the application, making it easier to manage changes in logging levels.

    7
    Maintainability
    Refactor logger configuration into a separate function for clarity and reusability

    Consider extracting the logger configuration into a separate function for better
    code organization and reusability.

    ee/middleware/streams/manager.go [89-95]

    -config["logger"] = map[string]interface{}{
    -    "level":         "INFO",
    -    "format":        "json",
    -    "add_timestamp": true,
    -    "static_fields": map[string]interface{
    -        "stream": streamID,
    -    },
    -}
    +config["logger"] = getDefaultLoggerConfig(streamID)
    Suggestion importance[1-10]: 6

    Why: Extracting the logger configuration into a separate function improves code organization and reusability, enhancing maintainability without affecting functionality.

    6

    @kofoworola kofoworola requested a review from a team October 30, 2024 07:02
    Copy link

    sonarcloud bot commented Oct 30, 2024

    Quality Gate Failed Quality Gate failed

    Failed conditions
    0.0% Coverage on New Code (required ≥ 80%)

    See analysis details on SonarCloud

    @kofoworola kofoworola merged commit 0c8a86a into master Oct 30, 2024
    34 of 40 checks passed
    @kofoworola kofoworola deleted the fix/streams-logger branch October 30, 2024 20:31
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants