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

[jaeger-v2] Streamline storage initialization #5171

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

yurishkuro
Copy link
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

ext: s,
storageKind: "memory",
cfg: s.config.Memory,
// memory factory does not return an error, so need to wrap it
Copy link
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
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
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
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
35 of 36 checks passed
@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