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

Handle Missing Redis Ports by Defaulting to Standard Redis Port in Loki #11414

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nstankov-bg
Copy link

@nstankov-bg nstankov-bg commented Dec 8, 2023

Summary of Changes:

  • Modified the deriveEndpoints function in pkg/storage/chunk/cache/redis_client.go to handle cases where the Redis port is not specified in the Loki configuration.
  • Implemented a fallback mechanism that sets the default Redis port (6379) when the port is absent in the endpoint address.
  • This change addresses a bug encountered when initializing Loki in Docker Swarm environments, specifically in setting up the Redis client for the query result cache.

Reason for Changes:

  • The bug was identified when Loki failed to initialize properly due to an error in deriving endpoints for the Redis client. This occurred when the port was not specified in the endpoint address, leading to an error in splitting host and port.
  • The implemented fix ensures that a default port is used in such scenarios, preventing initialization failures and enhancing the robustness of the endpoint derivation process.

Impact on the Project:

  • These changes directly impact the initialization process of Loki, particularly in environments where explicit port specification might be omitted.
  • By defaulting to the standard Redis port, the changes ensure smoother and more reliable deployment of Loki in various infrastructures, especially in Docker Swarm setups.

Additional Notes for Reviewers:

  • Reviewers are encouraged to verify the default port setting aligns with standard Redis configurations and does not interfere with custom setups.
  • It is important to assess if this change might affect any existing deployments where specific port configurations are expected.

Related Issue:

  • This PR addresses the bug described in the GitHub issue titled "Redis Client Setup Fails in Loki When Port is Missing in Address". Issue

Checklist for Review and Merge:

  • Ensure changes align with project standards and requirements.
  • Verify that the solution adequately addresses the reported issue.
  • Assess potential impacts on other parts of the codebase.
  • Review for coding best practices and performance implications.
  • Ensure adequate test coverage for the new logic.
  • Update relevant documentation to reflect these changes.
  • Check for any necessary updates in configuration files or upgrade guides.

@CLAassistant
Copy link

CLAassistant commented Dec 8, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

github-actions bot commented Dec 8, 2023

Trivy scan found the following vulnerabilities:

  • HIGH, Target: docker.io/grafana/loki:main-6034063 (alpine 3.18.4), Type: alpine openssl: Incorrect cipher key and IV length processing in libcrypto3 v3.1.3-r0. Fixed in v3.1.4-r0
  • HIGH, Target: docker.io/grafana/loki:main-6034063 (alpine 3.18.4), Type: alpine openssl: Incorrect cipher key and IV length processing in libssl3 v3.1.3-r0. Fixed in v3.1.4-r0
    \nTo see more details on these vulnerabilities, and how/where to fix them, please run docker build -t grafana/loki:main-6034063 -f cmd/loki/Dockerfile .
    trivy i grafana/loki:main-6034063 on your branch. If these were not introduced by your PR, please considering fixing them in via a subsequent PR. Thanks!

@nstankov-bg nstankov-bg marked this pull request as ready for review December 8, 2023 15:22
@nstankov-bg nstankov-bg requested a review from a team as a code owner December 8, 2023 15:22
Comment on lines +101 to +104
// If the port is missing, use the host as is and set a default port, if desired
host = endpoints[0]
// Example: set a default port, or you can choose to handle this differently
port = "6379" // Default Redis port
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like something we should do via a validateConfig function before passing the config to the client creation

@dannykopping I think you worked on the caching code the most recently, any thoughts here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you would like me to approach this differently. I would be happy to contribute.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on this @dannykopping and @cstyan

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have a new function that's called before deriveEndpoints in NewRedisClient that logs a warning for every endpoint that doesn't have a port set clarifying that the default port will be used. Alternatively, this new function could be called before NewRedisClient in cache.go New.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants