-
Notifications
You must be signed in to change notification settings - Fork 96
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
feat: allow setting Datadog syslog.hostname attribute #87
Conversation
Hello @btkostner, I'm not sure about this one because it would be a breaking change for users of DataDog agents that rely on a hostname to be an Erlang one. How DD-agent hostname is different? Are you sure that we can't read it in the same way as DD-agent does and give you an option to override the hostname? |
The only time it differs is when running Elixir in a container, because it grabs the container hostname instead of the host's hostname. Sadly this isn't something I can overwrite in the agent configuration. |
@btkostner do you run it in Kubernetes or some other environment? |
@AndrewDryga Yes, this is in kubernetes. I can show some screenshots in Datadog of some different setups if you want more clarity of what's happening. |
@btkostner I think there is a way to do this without introducing breaking changes: you can expose the hostname using an environment variable and then read it and pass it to the logger (https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/) so that both DD-agent values and Logger one would be equal. In logger we can allow overriding the host with anything you want. |
@AndrewDryga That would work. We could also just make a bool to include the hostname and have it default to |
@btkostner Great! I can share the plan that I have in my head that should fit all the use-cases: We can add a
To make it work we probably would need to extend the behavior (https://github.com/Nebo15/logger_json/blob/master/lib/logger_json/formatter.ex) and add an When the backend initializes we can check if such an option was given and:
|
I know it shoulds like a lot, if you feel like it's too much I'll handle this myself but a bit later |
That looks like a solid well thought out plan. I'll start working on it today 👍 |
Alrighty, PR is updated. Let me know how it looks 👍 |
lib/logger_json/formatter.ex
Outdated
@@ -16,6 +23,7 @@ defmodule LoggerJSON.Formatter do | |||
msg :: Logger.message(), | |||
ts :: Logger.Formatter.time(), | |||
md :: [atom] | :all, | |||
state :: map | |||
state :: map, | |||
formatter_state :: Keyword.t() |
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 think we should use a map for the state. Keywords have higher complexity for reading operations because sometimes we need to traverse the full list to get a value, which would be harmful as the state grows. Maps are highly optimized for that in Erlang:
formatter_state :: Keyword.t() | |
formatter_state :: map() |
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.
One small change and looks good, thank you!
Hey @btkostner sorry for taking it so long, was distracted by life and work :). I think this still is a great change that can be used by other providers so let's merge it anyways, even with a workaround. |
@AndrewDryga No problem. I figured there was more important stuff happening in your life. No need to apologize. |
Thank you @btkostner, great work! Can you run this in your project and verify it's what you need? I'll release a new hex version once I get feedback from you and make sure it's stable. |
Alright. Aside from the small doc fix I opened above, it looks to be working for me. I'm going to put it up on our staging cluster to make sure there are no side effects, but it should be good from my end. |
What is breaking
When logging to Datadog from a kubernetes cluster, the syslog hostname is set to the container hostname. This means Datadog will try to use the container hostname as the actual host name for metrics, traces, etc. Because of this, nothing will link up successfully. Sadly you can't rewrite that or do some sort of pipeline fix for this.
Why this change fixes it
Removing the syslog hostname means that dd-agent will fall back to its native hostname logic. This will pick up the same hostname when running on a regular server (non containerized), and it will pick up the correct (node) host name when running in a container (kubernetes).