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

Return error on the getTSDB function when user is not found. #6565

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

Conversation

alanprot
Copy link
Member

@alanprot alanprot commented Jan 29, 2025

What this PR does:
Im proposing to return an error on the getTSDB function when the userDB is not found.

Everytime we invoke this function on the codebase we need to check if the return is nil but is very easy to forget to do so and cause problem like: #6518 #6521

Ex:

userDB := i.getTSDB(userID)
if userDB == nil {
continue
}

I think returning an error in such case will force us to always think about this case and prevent such scenarios in the future.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

if db != nil {
if err != nil {
level.Warn(i.logger).Log("msg", "error getting user DB but userDB is not null", "err", err, "userID", userID)
Copy link

Choose a reason for hiding this comment

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

why would this happen ?

Copy link
Member Author

Choose a reason for hiding this comment

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

it should never happen.. it does not change the fact that if it happens if good to have a log! maybe i can add a comment

Copy link

Choose a reason for hiding this comment

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

I was trying to understand if you had an edge case in mind. either comment or

if db != nil && err == nil
   return db, nil

works

@@ -2285,10 +2292,10 @@ func (i *Ingester) getOrCreateTSDB(userID string, force bool) (*userTSDB, error)

func (i *Ingester) blockChunkQuerierFunc(userId string) tsdb.BlockChunkQuerierFunc {
Copy link

Choose a reason for hiding this comment

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

[not a blocker] for the sake of following the same convention, should not this also return an error

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 29, 2025
@alanprot alanprot marked this pull request as ready for review January 30, 2025 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/ingester lgtm This PR has been approved by a maintainer size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants