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

Add constants for known ecs fields for code efficiency when you log #38

Open
Fr33Radical opened this issue Oct 7, 2019 · 7 comments
Open
Labels
agent-java community Issues and PRs created by the community

Comments

@Fr33Radical
Copy link

Hi,
I'd like to have the ability to contribute to the project. It would be the first time I do it, so I am not sure if I can create a branch or anything. Would that be possible?

I'd like juste to create a Constants.java class that would have all the ECS fields so it would be accessible from any project and that would be more efficient.

Plus, it would be more easy to look at which fields already exist.

@felixbarny
Copy link
Member

Hi and welcome!

We have some ideas around auto-generating a typed object hierarchy based on the generated ECS yaml file: https://github.com/elastic/ecs/blob/master/generated/ecs/ecs_nested.yml.

That would have the benefit that the fields are not only named but also that the types correspond to those used in ECS. Combine that with a fluent API and you could do something like:

logger.info(EcsMessage
    .withMessage("Hello World")
    .withUser()
        .withId(42)
        .withName("Jon Doe")
        .and()
    .withGeo()
        .withCountry("Canada"));
ThreadContext.putAll(EcsMessage.withUser().withId(42).withName("Jon Doe").toFlatMap()):

@Fr33Radical
Copy link
Author

I understand the example is not implemented yet.
Do you have some kind of target date or any news about this feature?

Thank you, much appreciated.

@felixbarny
Copy link
Member

It's just an idea at the moment and there's no timeline for that.

@Fr33Radical
Copy link
Author

Fr33Radical commented Dec 18, 2019

I'd like to implement it.

Do you have some details about where I should start to auto-generate "a typed object hierarchy based on the generated ECS yaml"?

What would the input? How do you see it works?

I'm not sure about the specifications but I really like this feature and I would enjoy to implement it myself.

Is it to parse the yaml to create constant in a enum that we could instantiate with numbers?

@felixbarny
Copy link
Member

These are the fields from ECS: https://github.com/elastic/ecs/blob/master/generated/ecs/ecs_flat.yml.

See also https://github.com/elastic/ecs-dotnet for how a typed object hierarchy is generated for .NET.

@Fr33Radical
Copy link
Author

Hello,
I looked at ecs-dotnet and so far I understood that they use YamlDotNet.Serialization to create the source file. In java, this article is what I found that would be similar to ecs-dotnet : https://www.freecodecamp.org/news/how-to-generate-data-classes-in-java-fead8fa354a2/

For jackson, this example shows how to create instances of an object but not the java class definition. https://www.baeldung.com/jackson-yaml

I have been recommend to use swagger and I think it would really be the way to go.
The issue is that swagger works with a yaml format that does not fit expressively with ecs_nested.yml or ecs_flat.yml.
See the swagger editor for an example: https://editor.swagger.io/
See this example of swagger for generating java source files: https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen-maven-plugin. You can simply download the project and run mvn clean install to see the generated-sources folder.

In the image, we can see that from the yaml file, we can describe the java classes, their members, getters and setters.
Screenshot 2021-08-29 160738

Can elastic create a ecs_nested.yml file that fit the swagger format?
Does the ECS yaml file can be written in that format?

@felixbarny
Copy link
Member

Not sure that swagger would be the way to go. It's about specifying HTTP-based APIs. On the plus side, it does come with a wide range of generators for different languages.
The best place to propose that would be https://github.com/elastic/ecs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-java community Issues and PRs created by the community
Projects
None yet
Development

No branches or pull requests

3 participants