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-13186/TT-13199] improve logs #6632

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jeffy-mathew
Copy link
Contributor

@jeffy-mathew jeffy-mathew commented Oct 11, 2024

User description

Description

Related Issue

Parent: https://tyktech.atlassian.net/browse/TT-13186
Subtask: https://tyktech.atlassian.net/browse/TT-13199

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

  • Improved logging in the UpstreamBasicAuth middleware by changing the log level from Info to Warn for header conflict detection.
  • Updated the log message to use fmt.Sprintf for better formatting.
  • Added the fmt package import to support the new log message formatting.

Changes walkthrough 📝

Relevant files
Enhancement
mw_upstream_basic_auth.go
Improve logging for upstream basic authentication               

gateway/mw_upstream_basic_auth.go

  • Added import for fmt package.
  • Changed log level from Info to Warn for header conflict detection.
  • Updated log message formatting to use fmt.Sprintf.
  • +3/-3     

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

    @buger
    Copy link
    Member

    buger commented Oct 11, 2024

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

    Detected Status DoD Check
    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

    Logging Level Change
    The change in logging level from 'Info' to 'Warn' for the header conflict detection might be too severe depending on the frequency and criticality of this event. It's important to ensure that this level of logging is justified as it could lead to log flooding.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use structured logging instead of fmt.Sprintf for better performance and consistency

    Replace the direct usage of fmt.Sprintf for logging with structured logging fields
    to maintain consistency and performance.

    gateway/mw_upstream_basic_auth.go [68]

     log.WithFields(logrus.Fields{
         "header": u.HeaderName,
    -}).Warn(fmt.Sprintf("%s header conflict detected: client header overwritten by Gateway upstream authentication header", u.HeaderName))
    +    "message": u.HeaderName + " header conflict detected: client header overwritten by Gateway upstream authentication header",
    +}).Warn("Header conflict detected")
    Suggestion importance[1-10]: 7

    Why: The suggestion to use structured logging instead of fmt.Sprintf aligns with best practices for logging consistency and performance. It enhances the log message by making it more structured and potentially easier to parse, which is beneficial for log analysis and monitoring.

    7

    Copy link
    Contributor

    API Changes

    no api changes detected

    Copy link

    sonarcloud bot commented Oct 11, 2024

    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.

    2 participants