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

Merged
merged 4 commits into from
Nov 21, 2024

Conversation

nabokihms
Copy link
Contributor

Summary

By default, Vector uses the hostname returned by the gethostname. However, in cases when Vector is running in containers, it is meaningless because hostname is always the name of the container, e.g., the name of a pod in Kubernetes cluster.

This commit adds the way to override a hostname by using the env variable. In Kubernetes it can be used like this to see the name of a node where the Vector process is running (which is more meaningful).

env:
- name: VECTOR_HOSTNAME
  valueFrom:
    fieldRef:
      fieldPath: spec.nodeName

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

Tested manually in the kubernetes cluster.

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

  • Please read our Vector contributor resources.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run dd-rust-license-tool write to regenerate the license inventory and commit the changes (if any). More details here.

References

Closes #20481

By default, Vector uses the hostname returned by the gethostname. However, in cases when Vector is running in containers, it is meaningless because hostname is always the name of the container, e.g., the name of a pod in Kubernetes cluster.

This commit adds the way to override a hostname by using the env variable. In Kubernetes it can be used like this to see the name of a node where the Vector process is running (which is more meaningful).

```
env:
- name: VECTOR_HOSTNAME
  valueFrom:
    fieldRef:
      fieldPath: spec.nodeName
```

Signed-off-by: maksim.nabokikh <[email protected]>
@nabokihms nabokihms requested a review from a team as a code owner November 13, 2024 22:32
Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nabokihms, thank you for this enhancement. Please also document this new env var in website/cue/reference/cli.cue.

(Tangential to this PR: #21794)

src/lib.rs Outdated Show resolved Hide resolved
@nabokihms nabokihms requested review from a team as code owners November 15, 2024 07:06
@github-actions github-actions bot added the domain: external docs Anything related to Vector's external, public documentation label Nov 15, 2024
@nabokihms nabokihms force-pushed the vector-hostname-env-variable branch from 353fa41 to 270821a Compare November 15, 2024 07:07
@nabokihms nabokihms requested a review from pront November 15, 2024 10:56
@nabokihms nabokihms force-pushed the vector-hostname-env-variable branch from 270821a to 98b1f3b Compare November 15, 2024 10:58
Copy link
Contributor

@urseberry urseberry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a suggestion about a grammar nit.

src/lib.rs Outdated Show resolved Hide resolved
- Fix cue formatting
- Use the variable value if set but empty

Signed-off-by: maksim.nabokikh <[email protected]>
Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I'll let @pront approve too since he was looking at it before.

I think we could (potentially) add this as a global option in the config file too (hostname: foo) but only if the hostname isn't fetched before global configuration is loaded.

Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good call on not treating empty strings values as special.

@pront
Copy link
Member

pront commented Nov 19, 2024

I think we could (potentially) add this as a global option in the config file too (hostname: foo) but only if the hostname isn't fetched before global configuration is loaded.

Would be a nice follow-up to this.

@nabokihms nabokihms requested a review from jszwedko November 20, 2024 10:32
@jszwedko jszwedko added this pull request to the merge queue Nov 21, 2024
Merged via the queue into vectordotdev:master with commit 1f02dfb Nov 21, 2024
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: external docs Anything related to Vector's external, public documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use VECTOR_SELF_NODE_NAME for internal_metrics
4 participants