-
Notifications
You must be signed in to change notification settings - Fork 431
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
Add code generator for Go #249
Conversation
Very interesting idea. We could do that for other languages too. I assume you plan to import the code directly from ECS so if it gets updated and you go to a new version, you also get the newest fields? |
// Version of the agent. | ||
Version string `ecs:"version"` | ||
|
||
// Name of the agent. |
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.
I really like this. Will make it really easy to look up descriptions during implementations.
// readable separation is needed on which Filebeat instance data is coming | ||
// from. | ||
// If no name is given, the name is often left empty. | ||
Name string `ecs:"name"` |
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.
Do you have some plans on how ecs
here could be used?
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.
I haven't made use of it yet, but it's there to, at minimum, make it possible to marshal/unmarshal these fields in a programatic manner (if you take the time to read the tag values). I can see a future enhancements to make this better.
@ruflin I updated the PR to include two README files. I also added
|
9afb8fa
to
35db6a5
Compare
Thanks for sumitting this! I'll look after the Beta 2 release, however ;-) |
Makefile
Outdated
@@ -47,4 +49,7 @@ fields: | |||
cat fields.tmp.yml >> fields.yml | |||
rm -f fields.tmp.yml fields.tmp.yml.bak | |||
|
|||
.PHONY: generate schemas fmt check setup clean readme template fields | |||
codegen: |
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.
We should probably also move to mage
on day ;-)
@urso I think it would be a good time to show your logger experiment because I believe its kinda linked to this generated code :) |
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// Code generated by scripts/gocodegen.go - DO NOT EDIT. |
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.
Not sure if the format is correct, but If possible we should have this at the top of the file. This way github will also hide the diff by default.
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.
If we move this to the top then the go-licenser is not happy.
code/go/ecs/user_agent.go: is missing the license header
The comment format here follows the format from https://golang.org/s/generatedcode.
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.
The ECS repo contains a whole lot of generated code or markup, and the tooling to generate it is still very basic at this point. So I'd say seeing the diffs for those files is ok. It's actually useful in some cases.
I'm curious if there's another way (perhaps a dotfile?) to instruct GitHub to ignore generated files, though. Could be useful for the files generated by the most solid tooling.
It would be nice if we could define a template to set how the output should look like. E.g. in my logging experiments I did come up with:
or:
One can add a field to an existing namespace and everything is typed + deduplicated when logging. More similar how zap/zerolog and other structured loggers work. The structures I create for this are like:
Nesting namespaces goes like this:
|
35db6a5
to
e803f7c
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.
This is very interesting! Thanks for submitting this.
Are we missing the Base fields, though?
Also two minor things to fix:
- company name in license
- separate the MIT licensed function from the Apache licensed code
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// Code generated by scripts/gocodegen.go - DO NOT EDIT. |
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.
The ECS repo contains a whole lot of generated code or markup, and the tooling to generate it is still very basic at this point. So I'd say seeing the diffs for those files is ok. It's actually useful in some cases.
I'm curious if there's another way (perhaps a dotfile?) to instruct GitHub to ignore generated files, though. Could be useful for the files generated by the most solid tooling.
scripts/gocodegen.go
Outdated
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2014 Mitchell Hashimoto | ||
func wrapString(s string, lim uint) string { |
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.
If I understand correctly, this single function is under the MIT license? I think for clarity we should move it to a distinct file, as we have other code immediately below this, whose status now becomes ambiguous.
As discussed elsewhere, the copyright holder should actually be "Elasticsearch B.V.", not "Elastic N.V." My other two review feedback points still stand, however:
|
This generates Go code based on the Elastic Common Schema.
e803f7c
to
8d061e0
Compare
@webmat Both points are addressed now. I'm glad you caught that we were missing the base fields. |
@andrewkroh Looking good! I wonder why you had |
|
Good catch on |
This generates Go code based on the Elastic Common Schema.
This generates Go code based on the Elastic Common Schema.
This generates Go code based on the Elastic Common Schema.
I find myself creating structs that match the schema so I thought why not generate some code.