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

enable HTTP service over unix domain socket #7135

Merged
merged 1 commit into from
Aug 10, 2016

Conversation

oiooj
Copy link
Contributor

@oiooj oiooj commented Aug 10, 2016

  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated
  • Sign [CLA]

Feature Request in #7075 and #4877. Now you can use the http service over TCP and unix domain socket.

config

[http]
  enabled = true
  bind-address = ":8086"
  auth-enabled = false
  log-enabled = true
  write-tracing = false
  pprof-enabled = false
  https-enabled = false
  https-certificate = "/etc/ssl/influxdb.pem"
  ### Use a separate private key location.
  # https-private-key = ""
  max-row-limit = 10000
  realm = "InfluxDB"

  unix-socket-enabled = true # enable http service over unix domain socket
  bind-socket = "/var/run/influxdb.sock"

start

.....

[snapshot] 2016/08/10 14:30:42 Starting snapshot service
[admin] 2016/08/10 14:30:42 Starting admin service
[admin] 2016/08/10 14:30:42 Listening on HTTP: [::]:8083
[continuous_querier] 2016/08/10 14:30:42 Starting continuous query service
[httpd] 2016/08/10 14:30:42 Starting HTTP service
[httpd] 2016/08/10 14:30:42 Authentication enabled: false
[httpd] 2016/08/10 14:30:42 Listening on HTTP: [::]:8086
[httpd] 2016/08/10 14:30:42 Listening on unix socket: /tmp/test.sock
[retention] 2016/08/10 14:30:42 Starting retention policy enforcement service with check interval of 30m0s
[monitor] 2016/08/10 14:30:42 Storing statistics in database '_internal' retention policy 'monitor', at interval 10s
[run] 2016/08/10 14:30:42 Listening for signals

simple client


package main

import (
        "fmt"
        "io/ioutil"
        "net"
        "net/http"
        "net/url"
)

var sock = "/tmp/test.sock"

// all your client.Get or client.Post calls has to be a valid url (http://xxxx.xxx/path not unix://...),
// the domain name doesn't matter since it won't be used in connecting.
const URL = "http://test/"

func unixsocketDial(proto, addr string) (conn net.Conn, err error) {
        return net.Dial("unix", sock)
}

func main() {
        tr := &http.Transport{
                Dial: unixsocketDial,
        }

        client := &http.Client{Transport: tr}

        q := url.Values{}
        q.Set("db", "unixsocket")
        q.Set("q", "SELECT value FROM cpu WHERE region='us_west' LIMIT 10")

        req, err := http.NewRequest("GET", URL+"query?"+q.Encode(), nil)
        req.Header.Add("Content-Type", "application/json;charset=UTF-8")
        resp, err := client.Do(req)
        if err != nil {
                panic(err)
        }

        defer resp.Body.Close()

        body, err := ioutil.ReadAll(resp.Body)
        fmt.Println(string(body))
}

result

[root@LT test-unix-socket-client]# go run http-over-unixsocket.go               
{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["2016-08-09T06:44:25.606349352Z",0.64],["2016-08-09T06:44:26.606549012Z",0.64],["2016-08-09T06:44:27.606678699Z",0.64],["2016-08-09T06:44:28.60680961Z",0.64],["2016-08-09T06:44:29.606963202Z",0.64],["2016-08-09T06:44:30.60705227Z",0.64],["2016-08-09T06:44:31.60721017Z",0.64],["2016-08-09T06:44:32.60731221Z",0.64],["2016-08-09T06:44:33.607432441Z",0.64],["2016-08-09T06:44:34.607556441Z",0.64]]}]}]}

@mention-bot
Copy link

@oiooj, thanks for your PR! By analyzing the annotation information on this pull request, we identified @gunnaraasen and @e-dard to be potential reviewers

@@ -101,6 +109,26 @@ func (s *Service) Open() error {
s.ln = listener
}

// Open unix socket listener.
if s.unixSocket {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think Windows supports unix sockets. Can you check for if the OS is windows and return an error if somebody is trying to use unix sockets on Windows?

@oiooj oiooj force-pushed the unixsocket-feature branch from 412a357 to 1e91770 Compare August 10, 2016 17:40
@oiooj
Copy link
Contributor Author

oiooj commented Aug 10, 2016

@jsternberg updated

@jsternberg
Copy link
Contributor

👍 can you update the changelog and give yourself credit? I'll merge on green after that changelog is updated.

@jsternberg
Copy link
Contributor

Also remember to rebase your PR onto master.

@jsternberg jsternberg self-assigned this Aug 10, 2016
@oiooj oiooj force-pushed the unixsocket-feature branch from 1e91770 to f0c3f4f Compare August 10, 2016 17:56
@oiooj
Copy link
Contributor Author

oiooj commented Aug 10, 2016

@jsternberg CHANGELOG done.

@jsternberg
Copy link
Contributor

Can you rebase on master and put this in the 1.1 section for features? Unfortunately, this isn't going to make it into 1.0 as we closed that off on Monday and we weren't accepting feature requests into it before that. Sorry.

@oiooj oiooj force-pushed the unixsocket-feature branch from f0c3f4f to 6945655 Compare August 10, 2016 18:21
@oiooj
Copy link
Contributor Author

oiooj commented Aug 10, 2016

@jsternberg It's time and I want to go to bed. :P

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.

4 participants