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

WIP: Generate go protobuf types/source from .proto files imported as git submodule #935

Closed
wants to merge 25 commits into from

Conversation

evantorrie
Copy link
Contributor

This PR addresses #793

  • Adds a git submodule at internal/opentelemetry-proto tied to a specific tagged release of open-telemetry/opentelemetry-proto.
  • Adds Makefile rules to generate protobuf types in internal/opentelemetry-proto-gen from the git submodule sources using docker image namely/protoc-all
  • Changes references to previously imported github.com/open-telemetry/opentelemetry-proto packages to now refer to local packages generated during the build at internal/opentelemetry-proto-gen.

Note: I expect that there will be some discussion on the approach taken since this implementation does not check in the generated .pb.go files, but instead generates them fresh on each build from the original source using protoc. This makes use of a docker image which has protoc and go plugin pre-installed, rather than trying to build/install protoc from scratch. As a result, the build now requires docker, even for a make precommit step on the developer's machine.

@lizthegrey
Copy link
Member

generates them fresh on each build from the original source using protoc. This makes use of a docker image which has protoc and go plugin pre-installed, rather than trying to build/install protoc from scratch. As a result, the build now requires docker, even for a make precommit step on the developer's machine.

I have some pretty strong feelings against this; requiring a binary blob to build feels like it is adding more dependencies and also potentially makes generated go documentation harder to access.. I'd strongly prefer running a script to update, ensuring that we can diff changes if we change the version of protoc or changing a dep...

@evantorrie evantorrie changed the title Generate go protobuf types/source from .proto files imported as git submodule WIP: Generate go protobuf types/source from .proto files imported as git submodule Jul 13, 2020
Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

This approach seems reasonable.

I'm not sure if we should be checking in the generated code or not. Not doing that is definitely going to increase our build times and potentially introduce inconsistent builds. On the other hand, checking in this code, a dependency, that is an entirely separate project seems like a poor choice as well. One that will cause a bloated history (especially since the generated code contains encoded binary data).

Comment on lines +13 to +14
- Protobuf sources are now imported as a git submodule from open-telemetry/opentelemetry-proto. (#935)
Makefile changed to build .go files from .proto sources using docker protoc image.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Protobuf sources are now imported as a git submodule from open-telemetry/opentelemetry-proto. (#935)
Makefile changed to build .go files from .proto sources using docker protoc image.
- Protobuf sources are now imported as a git submodule from open-telemetry/opentelemetry-proto.
Makefile changed to build .go files from .proto sources using docker protoc image. (#935)

Comment on lines +164 to +165
ORIG_PROTO_FILES := $(wildcard $(OTEL_PROTO_SUBMODULE)/opentelemetry/proto/*/v1/*.proto \
$(OTEL_PROTO_SUBMODULE)/opentelemetry/proto/collector/*/v1/*.proto)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to make the v1 version here a variable as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

.PHONY: protobuf-source
protobuf-source: $(SOURCE_PROTO_FILES) | $(PROTOBUF_SOURCE_DIR)/

# replace opentelemetry-proto v0.4.0 package name by repo-local version
Copy link
Contributor

Choose a reason for hiding this comment

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

How does the upgrade path look? Does it include bumping the submodule and going through all the go.mod files?

Also, might not want to include the version in the comment.

Suggested change
# replace opentelemetry-proto v0.4.0 package name by repo-local version
# replace opentelemetry-proto package name by repo-local version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the new PR #938, it will look as follows:

  • Bump git submodule ref at internal/opentelemetry-proto to a newer version
  • Check in just that change and open the PR.
  • The github action from Create protobuf generation GitHub action #938 will then run, creating updated *.pb.go files (if any) in internal/opentelemetry-proto-gen and checking those changes back into the same PR.
  • The normal CircleCI build process will run.
  • If any changes are required because of the .proto differences, these will need to be resolved by the opener of the PR and will typically be confined to exporters/otlp/.

github.com/kr/pretty v0.1.0 // indirect
github.com/open-telemetry/opentelemetry-proto v0.4.0
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems odd. Shouldn't the forced vendoring we are doing here alleviate the dependency on the Go code contained in github.com/open-telemetry/opentelemetry-proto?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is a result of running make precommit while having the git submodule directory populated.

endif

define exec-protoc-all
docker run $(VOLUMES_MOUNT) namely/protoc-all $(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

This container needs to be versioned to a tag so when latest is updated it doesn't break things.

E.g.

Suggested change
docker run $(VOLUMES_MOUNT) namely/protoc-all $(1)
docker run $(VOLUMES_MOUNT) namely/protoc-all:1.28_2 $(1)

Though, it probably makes sense to keep the version as a variable.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps better, pin the image to a digest:

namely/protoc-all@sha256:b3eaf5e5ed4f3d0848ba5f5eda16374eb1d73e1fdbf30b0f13d439d96da5b81e

@MrAlias
Copy link
Contributor

MrAlias commented Jul 14, 2020

generates them fresh on each build from the original source using protoc. This makes use of a docker image which has protoc and go plugin pre-installed, rather than trying to build/install protoc from scratch. As a result, the build now requires docker, even for a make precommit step on the developer's machine.

I have some pretty strong feelings against this; requiring a binary blob to build feels like it is adding more dependencies and also potentially makes generated go documentation harder to access.. I'd strongly prefer running a script to update, ensuring that we can diff changes if we change the version of protoc or changing a dep...

@lizthegrey what is the binary blob in this situation?

@lizthegrey
Copy link
Member

generates them fresh on each build from the original source using protoc. This makes use of a docker image which has protoc and go plugin pre-installed, rather than trying to build/install protoc from scratch. As a result, the build now requires docker, even for a make precommit step on the developer's machine.

I have some pretty strong feelings against this; requiring a binary blob to build feels like it is adding more dependencies and also potentially makes generated go documentation harder to access.. I'd strongly prefer running a script to update, ensuring that we can diff changes if we change the version of protoc or changing a dep...

@lizthegrey what is the binary blob in this situation?

A specific version of the protoc compiler (and docker image that in turn it's packaged in)

@MrAlias
Copy link
Contributor

MrAlias commented Jul 14, 2020

A specific version of the protoc compiler (and docker image that in turn it's packaged in)

@lizthegrey gotcha.

In your proposal to run a script to update, where is the protoc binary located? Like, is it checked in, or installed on the person who's running the scripts system?

Sorry, this is likely a dumb question, I'm just not seeing the workflow.

@lizthegrey
Copy link
Member

A specific version of the protoc compiler (and docker image that in turn it's packaged in)

@lizthegrey gotcha.

In your proposal to run a script to update, where is the protoc binary located? Like, is it checked in, or installed on the person who's running the scripts system?

Sorry, this is likely a dumb question, I'm just not seeing the workflow.

I'm fine with requiring a docker container to perform the update of the generated files, but not for subsequent builds where neither the proto nor protoc has changed. Does that make sense?

@evantorrie
Copy link
Contributor Author

Understand the comments.. I'm working on an alternative where the updates to *.pb.go files are done as part of a separate workflow and then checked in. Let me experiment for a bit, and leave this as WIP.

@MrAlias
Copy link
Contributor

MrAlias commented Jul 14, 2020

I'm fine with requiring a docker container to perform the update of the generated files, but not for subsequent builds where neither the proto nor protoc has changed. Does that make sense?

Ah, yeah, that makes things clearer. Thanks.

@evantorrie
Copy link
Contributor Author

I'll leave this open for a little while longer, but this is going to be closed in favor of #938 and a subsequent PR which will introduce the git submodule.

@evantorrie
Copy link
Contributor Author

Closed in favor of #938

@evantorrie evantorrie closed this Jul 15, 2020
@evantorrie evantorrie deleted the otlp-protogen branch July 15, 2020 23:11
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.

4 participants