Skip to content

Duplicate get_hostname implementations #14819

Closed

Description

@lukesteensen

We have one implementation of get_hostname for Vector itself, and a separate one for the VRL stdlib. It's not a huge deal since they're both quite small and currently the same, but when we introduce changes like allowing hostname to be overridden by an env var we don't want them to get out of sync.

Activity

  1. added
    type: tech debtA code change that does not add user value.
    domain: vrlAnything related to the Vector Remap Language
    vrl: stdlibchanges to VRL's standard library.
    on Oct 12, 2022
  2. added a commit that references this issue on Oct 12, 2022
    49605fa
  3. tobz commented on Oct 12, 2022

    @tobz
    Contributor

    We should de-duplicate those, yes. One way to avoid circular dependencies would be to force VRL to take stubs to anything that performs "external" I/O, such as getting the hostname. We would simply configure it when Vector initializes the VRL runtime, or something to that effect.

    This would allow deduplicating without circular dependencies, and could be a potential model to expand upon for exposing "external" I/O through controlled interfaces.

  4. bruceg commented on Oct 12, 2022

    @bruceg
    Member

    We should de-duplicate those, yes. One way to avoid circular dependencies would be to force VRL to take stubs

    Or just move it to vector_common

  5. tobz commented on Oct 12, 2022

    @tobz
    Contributor

    Perhaps. That's definitely easier in the short term.

  6. lukesteensen commented on Oct 12, 2022

    @lukesteensen
    MemberAuthor

    Good point, vector_common is a reasonable short-term fix here. I still don't love that arrangement in general, but that's a different issue.

  7. JeanMertz commented on Oct 13, 2022

    @JeanMertz
    Contributor

    Yeah, I'd be happy with moving it to vector_common for now, and we can provide an actual public API/trait in VRL in the future, when we need VRL to be completely separate from Vector.

  8. added a commit that references this issue on Mar 24, 2023
    70cd01d
  9. Captain1653 commented on Oct 12, 2026

    @Captain1653
    Contributor

    I looked into this issue to see if the duplication still exists. It seems this has already been resolved in the current codebase.

    The centralized implementation resides in src/lib.rs and properly handles the VECTOR_HOSTNAME override:

    // src/lib.rs
    pub fn get_hostname() -> std::io::Result<String> {
        Ok(if let Ok(hostname) = std::env::var("VECTOR_HOSTNAME") {
            hostname
        } else {
            hostname::get()?.to_string_lossy().into_owned()
        })
    }

    The implementation in src/sources/exec/mod.rs no longer duplicates any logic — it simply delegates directly to crate::get_hostname() while converting the Result to an Option:

    // src/sources/exec/mod.rs
    fn get_hostname() -> Option<String> {
        crate::get_hostname().ok()
    }

    Since the logic is centralized and there is no remaining duplication within Vector, I believe this issue can be safely closed.

  10. pront commented on Oct 13, 2026

    @pront
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    domain: vrlAnything related to the Vector Remap Languagetype: tech debtA code change that does not add user value.vrl: stdlibchanges to VRL's standard library.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions