Skip to content

[jaeger-v2] Streamline storage initialization#5171

Merged
yurishkuro merged 1 commit intojaegertracing:mainfrom
yurishkuro:simplify
Feb 6, 2024
Merged

[jaeger-v2] Streamline storage initialization#5171
yurishkuro merged 1 commit intojaegertracing:mainfrom
yurishkuro:simplify

Conversation

@yurishkuro
Copy link
Copy Markdown
Member

Which problem is this PR solving?

  • There is duplicated code in the extension Start, which is being copy/pasted in other PRs

Description of the changes

  • Refactor Start to avoid duplication and to make testing simpler (no need to test all edge cases for every storage type)
  • Clean-up tests

How was this change tested?

Checklist

Signed-off-by: Yuri Shkuro <github@ysh.us>
ext: s,
storageKind: "memory",
cfg: s.config.Memory,
// memory factory does not return an error, so need to wrap it
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not change memory.NewFactoryWithConfig to return the error? It doesn't look like it's used anywhere else, so it shouldn't be a large breaking change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because I hate functions that are declared with errors but always return nil. The caller either has to ignore the error, or it has no easy way of unit testing the error handing path (which will never be used). Lose-lose. I think if the function can never return an error it should never declare it as a possibility (unless you're dealing with an interface where there's no choice).

for name, b := range s.config.Badger {
if _, ok := s.factories[name]; ok {
return fmt.Errorf("duplicate badger storage name %s", name)
func (s *starter[Config, Factory]) build(ctx context.Context, host component.Host) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Internal state isn't persisted between method calls so all methods are effectively read-only; we could assert this by using value receivers instead of pointer receivers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

true, but makes no difference in this context since the code runs exactly once. Don't want to reset the approval just for this fix :-)

@yurishkuro yurishkuro merged commit 6b2afd1 into jaegertracing:main Feb 6, 2024
@yurishkuro yurishkuro deleted the simplify branch February 6, 2024 20:57
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