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

feat(internal): Add VECTOR_HOSTNAME env variable #21789

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add VECTOR_HOSTNAME env variable to override the hostname used in the Vector events and internal metrics.
This is useful when Vector is running on a system where the hostname is not meaningful, e.g., in a container (Kubernetes).

authors: nabokihms
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ pub mod built_info {

/// Returns the host name of the current system.
pub fn get_hostname() -> std::io::Result<String> {
Ok(hostname::get()?.to_string_lossy().into())
let hostname = option_env!("VECTOR_HOSTNAME").unwrap_or("");
Ok(if !hostname.is_empty() {
hostname.to_string()
} else {
hostname::get()?.to_string_lossy().into()
})
}

/// Spawn a task with the given name. The name is only used if
Expand Down
17 changes: 17 additions & 0 deletions website/cue/reference/cli.cue
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,23 @@ cli: {
"""
type: string: default: null
}
VECTOR_HOSTNAME: {
description: """
Overrides the hostname used in Vector's logs and metrics.
This is useful when running Vector in a container or on other systems where the hostname is not meaningful.

The example of how it can be used in Kubernetes pod template:

```yaml
env:
- name: VECTOR_HOSTNAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
```
"""
type: string: default: null
}
VECTOR_LOG: {
description: "Vector's log level. Each log level includes messages from higher priority levels."
type: string: {
Expand Down