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

services: Set Nomad's User-Agent by default on HTTP checks for nomad services #16248

Merged
merged 1 commit into from
Feb 23, 2023

Conversation

shoenig
Copy link
Member

@shoenig shoenig commented Feb 23, 2023

This PR sets the default User-Agent on checks of nomad services to the common UA for Nomad stuff (e.g. "Nomad/1.5.0-dev (+https://www.nomadproject.io/; go1.20)"). If the user supplies a UA that one takes precedence.

@shoenig
Copy link
Member Author

shoenig commented Feb 23, 2023

Spot check

job without setting User-Agent header

job "ua" {
  group "group" {

    network {
      mode = "bridge"
      port "http" { to = 9090 }
    }

    service {
      name     = "fakeservice"
      port     = "http"
      provider = "nomad"
      check {
        name = "check"
        type     = "http"
        path     = "/"
        interval = "5s"
        timeout  = "1s"
      }
    }

    task "nj" {
      driver = "docker"

      config {
        image = "nicholasjackson/fake-service:v0.23.1"
        ports = ["http"]
      }

      env {
        LISTEN_ADDR = "0.0.0.0:9090"
        LOG_FORMAT  = "text"
      }

      resources {
        cpu    = 10
        memory = 32
      }
    }
  }
}

logs

2023-02-23T13:10:09.747Z [INFO]  Handle inbound request: request="GET / HTTP/1.1
Host: 127.0.0.1:29784
user-agent: Nomad/1.5.0-dev (+https://www.nomadproject.io/; go1.20)
accept-encoding: gzip"
2023-02-23T13:10:09.747Z [INFO]  Finished handling request: duration=71.256µs

now with User-Agent header set

check {
  name = "check"
  type     = "http"
  path     = "/"
  interval = "5s"
  timeout  = "1s"
  header {
    User-Agent = ["my-custom-agent"]
  }
}

logs

2023-02-23T13:11:45.642Z [INFO]  Handle inbound request: request="GET / HTTP/1.1
Host: 127.0.0.1:23390
user-agent: my-custom-agent
accept-encoding: gzip"
2023-02-23T13:11:45.642Z [INFO]  Finished handling request: duration=70.718µs

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +11 to +15
const (
// Header is the User-Agent header key
// https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3
Header = `User-Agent`
)
Copy link
Member

Choose a reason for hiding this comment

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

Augh, the lack of common headers in net/http constants!

@shoenig shoenig merged commit 1ff1132 into main Feb 23, 2023
@shoenig shoenig deleted the nsd-check-useragent branch February 23, 2023 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants