-
Notifications
You must be signed in to change notification settings - Fork 528
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
Go modules #3296
Comments
Started looking into this. So far I've only had to make one minor code change, in I'm making my way through build-related changes now. A couple of early findings:
|
I modified our Makefile to set
Which causes "make" to flip out, trying to rebuild some Go files from YACC sources, deep inside the beats vendor dir. This is caused by the GOFILES = $(shell find . -type f -name '*.go' 2>/dev/null)
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "*/vendor/*" 2>/dev/null)
GOFILES_ALL = $(GOFILES) $(shell find $(ES_BEATS) -type f -name '*.go' 2>/dev/null)
GOPACKAGES_STRESSTESTS=$(shell find . -name '*.go' 2>/dev/null | xargs awk 'FNR>1 {nextfile} /\+build.*stresstest/ {print FILENAME; nextfile}' | xargs dirname | uniq)
...
${BEAT_NAME}: $(GOFILES_ALL) ## @build build the beat application
go build $(GOBUILD_FLAGS) I can't think of a good reason to have those dependencies there. There's a |
Hmm, so: one good reason is that embedding the build time in the binary causes it to be relinked, which is time consuming. IMO it's worth making that optional (off by default, enabled in CI) to avoid having to explicitly list source deps. |
Targets in beats/dev-tools/mage are passing |
I've created a WIP branch at https://github.com/axw/apm-server/tree/go-modules, which totally removes the apm-server/vendor and apm-server/_beats directories, and adds a
Main questions:
|
Diff for beats (go-modules branch): $ git diff
diff --git a/dev-tools/mage/fields.go b/dev-tools/mage/fields.go
index be6ce0285..880150a7d 100644
--- a/dev-tools/mage/fields.go
+++ b/dev-tools/mage/fields.go
@@ -101,7 +101,7 @@ func generateFieldsYAML(baseDir, output string, moduleDirs ...string) error {
return err
}
- globalFieldsCmd := sh.RunCmd("go", "run", "-mod", "vendor",
+ globalFieldsCmd := sh.RunCmd("go", "run", //"-mod", "vendor",
filepath.Join(beatsDir, globalFieldsCmdPath),
"-es_beats_path", beatsDir,
"-beat_path", baseDir,
diff --git a/dev-tools/mage/settings.go b/dev-tools/mage/settings.go
index dfe674326..efdda52b5 100644
--- a/dev-tools/mage/settings.go
+++ b/dev-tools/mage/settings.go
@@ -275,6 +275,10 @@ func findElasticBeatsDir() (string, error) {
return repo.RootDir, nil
}
+ if path := os.Getenv("ES_BEATS"); path != "" {
+ return path, nil
+ }
+
const devToolsImportPath = elasticBeatsImportPath + "/dev-tools/mage"
// Search in project vendor directories. Order is relevant |
pinging @kvch for visibility |
We decided to keep the vendor folder to avoid CI build failures if the modules cannot be downloaded e.g due to network errors. I am OK with making BTW from Go 1.14, this flag will become unnecessary anyway, because if there is a vendor folder in the repo, Go will automatically use the folder to compile the binary.
What do you mean? Is there a |
@kvch thanks for the input!
Fair enough. At least until we have an internal module mirror, APM Server will probably want to do the same.
Ah nice, I had missed that. Will Beats set the minimum Go version to 1.14, and remove the flag at that point? Go 1.14 is just around the corner, so it probably makes sense to just go straight to that, rather than adding configuration.
Perhaps I'm missing something. Rather than parsing modules.txt, can you instead parse the output of {
"Path": "sigs.k8s.io/yaml",
"Version": "v1.1.1-0.20190704183835-4cd0c284b15f",
"Time": "2019-07-04T18:38:35Z",
"Indirect": true,
"Dir": "/home/andrew/go/pkg/mod/sigs.k8s.io/yaml@v1.1.1-0.20190704183835-4cd0c284b15f",
"GoMod": "/home/andrew/go/pkg/mod/cache/download/sigs.k8s.io/yaml/@v/v1.1.1-0.20190704183835-4cd0c284b15f.mod",
"GoVersion": "1.12"
} You can then follow the |
After playing with that option a bit, we might not want to use modules.txt or go.mod, because of https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md#tools-as-dependencies. Some of the build tools we use have licenses incompatible with ours, but they're only used in dev or CI, so they don't actually taint the binaries. If you use The alternative would be to parse the output of |
@kvch I created a WIP branch following this line of thought: elastic/beats@go-modules...axw:go-modules If that looks like a reasonable approach, please let me know and I'll send a PR late next week or early the following one. |
The code looks good. Do you mind opening a PR agains go-modules? |
@kvch I was about to do that today, but then it occurred to me that going through all of the modules is probably the right thing to do -- but only when you do have a vendor directory. Otherwise there's a risk that unacceptably-licensed code ends up vendored in the tree, which is something we avoid as a policy, even when it's not linked into any distributed binaries. |
elastic/beats#15868 is getting close, APM Server will need to adapt soon after.
The text was updated successfully, but these errors were encountered: