-
Notifications
You must be signed in to change notification settings - Fork 638
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
Allow stacktrace path override for package sources #3307
base: master
Are you sure you want to change the base?
Conversation
60c72c3
to
afb47f9
Compare
732cc73
to
7e2117c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few thoughts:
-
A bit backward when we have to update
rules_go
to support a single IDE's feature. I think it's a nice change to have still, but it would be nice to show consideration on how this would work with other toolings in the same space: gopls, delve, ... OR observability vendors such as Datadog, Sentry etc... -
It seems like there is an assumption that there would be a GOPATH or GOMODCACHE path in use. That assumption is not always true for a Bazel setup and could use some documentation suggesting how to use
stackpath
. -
I was wondering what the correct "default" value of
stackpath
should be. For external dependencies, it seems like the external deps could be found at.
$(bazel info execution_root)/external/<dep-normalized-name>/<package-path/foo.go
In the PR description, you seem to be hinting toward external/src-org_golang_google_grpc
with the src-
prefix which I'm not quite sure if it's something specific to your setup.
tests/core/go_test/BUILD.bazel
Outdated
|
||
go_library( | ||
name = "stackpath_lib", | ||
srcs = ["stackpath_lib.go"], | ||
importpath = "stackpath_lib", | ||
stackpath = "foo", | ||
) | ||
|
||
go_test( | ||
name = "stackpath_test", | ||
srcs = [ | ||
"a/stackpath2_test.go", | ||
"stackpath_test.go", | ||
], | ||
stackpath = "bar", | ||
deps = [ | ||
":stackpath_lib", | ||
], | ||
) | ||
|
||
go_library( | ||
name = "stackpath_test_lib", | ||
srcs = [ | ||
"a/stackpath2_test.go", | ||
"stackpath_test.go", | ||
], | ||
importpath = "stackpath_test", | ||
stackpath = "bar", | ||
deps = [ | ||
":stackpath_lib", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "stackpath_embed_test", | ||
embed = [":stackpath_test_lib"], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test setup puzzled me a bit as I don't fully understand what's the differences between :stackpath_test
and :stackpath_embed_test
.
I am expecting 2-3 sets of tests to demonstrate:
- Default behaviors when
stackpath
is not set stackpath
is set only in teststackpath
is set in dep's libstackpath
is set in both dep's lib and test
I would suggest rename the test and add some docs into https://github.com/bazelbuild/rules_go/blob/master/tests/core/go_test/README.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stackpath
only affects the package itself. It does not affect or depend on deps
. But he can come via embed
(like: importpath
).
In our case, the pain was caused by the fact that we use The option itself is not IDE specific. Perhaps there will be different stack layouts. But they will be at the gazelle or similar utilities level.
Yes. Our stack trace layout is not fully portable: But it's good enough for us :) I'm not saying the current stacktrace layout is bad. I just want the ability to change it.
It seems to me that the current layout is ideal as the default option: it is meaningful in the case of a bazel build. I don't known about "universal" stacktrace layout. We try use
But we are giving our developers the opportunity to live without knowing about BUILD.bazel files, as it was before the build via bazel.
We generate |
I wrote a small example to illustrate the standard stacktrace: https://github.com/bozaro/testify-example/tree/master/trace It consists of two files: go.mod
cmd/trace/main.go
And launched it with the command:
There are three kinds of paths
It seems to me that this can be considered as a standard representation. Unfortunately, in my case, the IDE cannot recognize any file. In any case, the stacktrace path layout should be outside of |
Pull request is stuck. @sluongng, perhaps you are waiting something from me... |
16d2286
to
ad95a9c
Compare
I am not in a good position to review this PR. I don't use IntelliJ / GoLand enough in recent days to tell how this would impact the IDE. I also am not sure whether there is a more feasible approach (i.e. a wrapper that handles similar transition/conversion). I will yield the review to @linzhp who spoke about IDE support at Uber. @achew22 might have some thoughts as well. 🙇 |
I can review it later this week |
Since this is mapping to go's native Staying closer to the native implementation is always better. |
@JamyDev Just for my own understanding, are you suggesting a rename of |
I was suggesting we just expose the native functionality and use that. You can then have a custom rule outside of rules_go that provides |
Perhaps the name But it seems to me that using
It is very difficult to implement the format of the native parameter:
That is, in any case, the format of the parameter will differ from the native |
Thanks for clarifying @bozaro I think the main concerns I have here is: A. manually having to define the full stackpath for each library + version causes a lot of duplication in your library rules. It should be automatic. What I'm perceiving here is that you want go style output and support for go style builds, which doesn't fit with regards to how Now let's say I'm wrong and we're okay with providing The simpler solution IMO would be write a little tool that converts your stackpaths after the fact to the rules_go folder structure? |
Yes. It should be automatic. But this automation can be implemented somewhere at the For example: bazelbuild/bazel-gazelle#1379
I see only two options for the development process:
In our case, the ability to let developers use In addition, you still need to support the ability to So I admit that this way of using bazel is used not only by us.
At the For example, a version from
I think
The first thing we tried to do was to change the format of the paths before writing stack trace to the log. To do this, we sewed into the source file the correspondence of the prefix of paths from bazel and to the stack trace prefix. The code was very nasty, but it worked. Unfortunately, to generate paths, you need:
I see only one reliable way to implement an external utility: generate a file based on a BES file with matching paths for each source go file. The presence of input data from the assembly and trace greatly complicates the use of such a utility. But the most unpleasant thing is that this approach does not cover all the places where the source files appear. For example, |
I agree with @JamyDev. Supporting two build systems for a language at the same time is not the right way to go for a developer experience team. I agree there are gaps in integrating Bazel+Go+IDEs, but the community should work together to improve IDE plugins for Bazel+Go. Uber will continue to make our fair share of contribution by upstreaming our internal improvements to IDE plugins, Go package driver for Bazel, and possibly gopls too.
Go module system is still needed to populate go.mod file, but that doesn't mean we need the build system IDE plugins also allow you to resolve generated code without having to checking them in, reducing a step in developer workflow to generate code and make sure it's up-to-date. With a clear path forward, I don't think it's a good idea for rules_ to support such an invasive feature so that it produces the stack trace of another build system. |
In practice, this means that all packages (including the generated code) must exist in a working copy. In fact, it is synonymous with compilability.
When reading articles about the integration of basel and GoLang, I have not found a seamless combination of tools and processes. Everything is limited to hello world examples, but I didn't see a complete solution. Every time I use the plugin for basel in Idea I feel pain. I know we have developers who use vim as an IDE. So I have no faith in integrating all IDEs with bazel. At least in the perspective of the next two years. |
Rebased to v0.41.0 |
Rebased to v0.47.1 |
What type of PR is this?
Feature
What does this PR do? Why is it needed?
We use
go build
for local development andbazel build
for CI.Our IDE has Analyze Stack Trace feature for navigation to code from log traces.
So, we want to have more friendly logfile stack traces like:
instead of:
This PR adds ability to set package stack trace visible path with optional
stackpath
attribute.Stack trace path override example: