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

Added pkg directory to host importable packages #69

Merged
merged 1 commit into from
Jun 28, 2019
Merged

Added pkg directory to host importable packages #69

merged 1 commit into from
Jun 28, 2019

Conversation

owais
Copy link
Contributor

@owais owais commented Jun 28, 2019

Added a new pkg sub-directory that hosts code intended to be imported by
3rd party packages.

Packages with internal in their import path cannot be imported by
other Go programs. This is enforced by the compiler. Some of the code
currently hosted by the internal director needs to be made available to
other programs so additional exporters, receivers and processors can be
easily implemented independently.

As an alternative to /pkg we can also move them to project root but a lot of packages there might add clutter. I'm fine with either approach.

@codecov-io
Copy link

codecov-io commented Jun 28, 2019

Codecov Report

Merging #69 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #69   +/-   ##
=======================================
  Coverage   71.37%   71.37%           
=======================================
  Files          91       91           
  Lines        6022     6022           
=======================================
  Hits         4298     4298           
  Misses       1500     1500           
  Partials      224      224
Impacted Files Coverage Δ
cmd/occollector/app/builder/receivers_builder.go 85.18% <ø> (ø) ⬆️
cmd/occollector/app/builder/exporters_builder.go 92.64% <ø> (ø) ⬆️
pkg/configv2/configv2.go 98.64% <ø> (ø)
processor/addattributesprocessor/factory.go 100% <ø> (ø) ⬆️
receiver/jaegerreceiver/factory.go 100% <ø> (ø) ⬆️
pkg/configv2/test_helpers.go 50% <ø> (ø)
receiver/prometheusreceiver/factory.go 72.09% <ø> (ø) ⬆️
cmd/occollector/app/collector/collector.go 79.26% <ø> (ø) ⬆️
pkg/configmodels/configmodels.go 0% <ø> (ø)
exporter/opencensusexporter/factory.go 87.32% <ø> (ø) ⬆️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb2f08b...ffe6d64. Read the comment docs.

tigrannajaryan
tigrannajaryan previously approved these changes Jun 28, 2019
Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

LGTM

songy23
songy23 previously approved these changes Jun 28, 2019
Copy link
Member

@songy23 songy23 left a comment

Choose a reason for hiding this comment

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

Please rebase.

@flands flands added this to the 0.1.0 milestone Jun 28, 2019
flands
flands previously approved these changes Jun 28, 2019
Copy link
Contributor

@flands flands left a comment

Choose a reason for hiding this comment

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

LGTM

@owais owais dismissed stale reviews from flands, songy23, and tigrannajaryan via 1ffd628 June 28, 2019 16:56
@owais
Copy link
Contributor Author

owais commented Jun 28, 2019

@songy23 done, thanks.

songy23
songy23 previously approved these changes Jun 28, 2019
tigrannajaryan
tigrannajaryan previously approved these changes Jun 28, 2019
Added a new pkg sub-directory that hosts code intended to be imported by
3rd party packages.

Packages with `internal` in their import path cannot be imported by
other Go programs. This is enforced by the compiler. Some of the code
currently hosted by the internal director needs to be made available to
other programs so additional exporters, receivers and processors can be
easily implemented independently.
@owais owais dismissed stale reviews from tigrannajaryan and songy23 via ffe6d64 June 28, 2019 19:16
@flands flands merged commit 2e07643 into open-telemetry:master Jun 28, 2019
@bogdandrutu
Copy link
Member

I think there was a long conversation about using pkg. And we decided to not do that.

@tigrannajaryan
Copy link
Member

@bogdandrutu can you please point to the discussion or if you remember the arguments post here?

@bogdandrutu
Copy link
Member

@tigrannajaryan
Copy link
Member

@owais I tend to agree with some of the arguments against pkg. It looks superfluous to me and unnecessarily lengthens import path. With internal being the convention for stuff that is not for external use I think "every else is public" is not a bad rule.

I do not see much benefits in pkg provided that the public packages are properly and clearly organized. Perhaps this effort is better spent in cleaning up the package structure that we have, I think it could use some improvement.

I'd like to know what you think about this.

We probably need a broader discussion about code organization. I think the codebase could generally benefit from better organization (something along the clean architecture lines: https://medium.com/@eminetto/clean-architecture-using-golang-b63587aa5e3f - so a layered organization with one clear direction of dependencies).

@owais
Copy link
Contributor Author

owais commented Jun 28, 2019

I don't have any strong preference for pkg. I thought it shows clear intent that the code inside is meant to be consumed by other projects. Totally fine if we want to invert that by treating internal as strictly private and everything else (probably except cmd) as public.

@bogdandrutu
Copy link
Member

If you need the code to be "public" put it in a directory directly in the root project not in internal.

@tigrannajaryan
Copy link
Member

My understanding is that internal is enforced by the compiler. You cannot import it from a code that is in a different tree. So you don't just treat it as private it is enforced to be private.

It then leaves everything else to be public. Even cmd I think is fine. If you have stuff that is exportable from cmd package I do not see a reason why it should not be possible (or be prohibited by convention) to import.

@owais
Copy link
Contributor Author

owais commented Jun 28, 2019

I'll move it all outside but have a question about the config packages. We could move the config packages to the project root or we could create a config package at root and host configmodels and configv2 inside it. So the structure would look like:

- config
    - v2
    - models

I like that everything related to config will be inside the config "container".

I don't like that the import path lies about the package name. I mean when importing opentelemetry-service/config/v2, the package would still be accessible in code with configv2 which can be a bit surprising. We could change the package identifier to v2 but that would make code importing the package more cryptic as it wouldn't be obvious what v2 is when reading the code.

Option 1.

- factories
- config
     - v2         // imported as configv2
     - models     // imported as configmodels

Option 2.

- factories
- configv2 
- configmodels

Interested in hearing what everyone thinks.

@owais owais deleted the importable-package branch June 28, 2019 21:15
@tigrannajaryan
Copy link
Member

I would move all models to a separate package. Granted, we currently have only config models but there can be more. I find that it is reasonable that models are a separate package. They are the glue that holds other packages together and they should be importable from any other package. At the same time other package should be more careful about importing each other.

So I would do this:

- cmd
- models (config models are here)
- factory (this can be split into 3 parts and go into the corresponding packages)
- configv2 (should be later renamed to config when cleaning up, maybe even now is the time)
- exporter
- receiver
- processor
- internal

@owais
Copy link
Contributor Author

owais commented Jun 28, 2019

Moved out of pkg #73

jjackson-s pushed a commit to jjackson-s/opentelemetry-collector that referenced this pull request Jul 1, 2021
User formatting assistance and user error checking
MovieStoreGuy pushed a commit to atlassian-forks/opentelemetry-collector that referenced this pull request Nov 11, 2021
hughesjj pushed a commit to hughesjj/opentelemetry-collector that referenced this pull request Apr 27, 2023
Troels51 pushed a commit to Troels51/opentelemetry-collector that referenced this pull request Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants