You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposal: add the ability for the client to connect to unix sockets
Current behavior:PR#7315 added the ability for the server to listen over unix sockets, but the client doesn't have a method to connect to them.
Desired behavior: add a method to the client that connects to a unix socket.
Use case: when running telegraf on local systems and an application wants to send metrics to telegraf it shouldn't require a tcp/udp connection because of the client library doesn't support unix sockets.
I've hacked together a unix client for my software, but it'd be nice for this functionality to be
in the clients themselves.
// unixClient - client for connecting to influxdb through unix sockets.
type unixClient struct {
address string
net.Conn
m *sync.RWMutex
}
func (t *unixClient) Query(q client.Query) (*client.Response, error) {
return nil, errors.New("query is not available with the unix client")
}
// Ping checks that status of cluster, and will always return 0 time and no
// error for UDP clients.
func (t *unixClient) Ping(timeout time.Duration) (time.Duration, string, error) {
return time.Duration(0), "", nil
}
// Write takes a BatchPoints object and writes all Points to InfluxDB.
func (t *unixClient) Write(bp client.BatchPoints) error {
var (
err error
conn net.Conn
b bytes.Buffer
)
for _, p := range bp.Points() {
if _, err = b.WriteString(p.PrecisionString(bp.Precision())); err != nil {
return err
}
if err = b.WriteByte('\n'); err != nil {
return err
}
}
if conn, err = t.conn(); err != nil {
return err
}
_, err = conn.Write(b.Bytes())
return t.badConn(err)
}
func (t *unixClient) conn() (c net.Conn, err error) {
if c = t.getConn(); c == nil {
return t.newConn()
}
return c, nil
}
func (t *unixClient) newConn() (_ignored net.Conn, err error) {
t.m.Lock()
defer t.m.Unlock()
// recheck incase another thread beat us to creating a conn.
if t.Conn != nil {
return t.Conn, nil
}
if t.Conn, err = net.Dial("unix", t.address); err != nil {
return nil, errors.WithStack(err)
}
return t.Conn, nil
}
func (t *unixClient) getConn() net.Conn {
t.m.RLock()
defer t.m.RUnlock()
return t.Conn
}
func (t *unixClient) badConn(err error) error {
if err == nil {
return err
}
_ = t.Close()
return err
}
func (t *unixClient) Close() (err error) {
t.m.Lock()
defer t.m.Unlock()
// ignore error
if err = t.Conn.Close(); err != nil {
return errors.WithStack(err)
}
t.Conn = nil
return nil
}
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because it has not had recent activity. Please reopen if this issue is still important to you. Thank you for your contributions.
Proposal: add the ability for the client to connect to unix sockets
Current behavior: PR #7315 added the ability for the server to listen over unix sockets, but the client doesn't have a method to connect to them.
Desired behavior: add a method to the client that connects to a unix socket.
Use case: when running telegraf on local systems and an application wants to send metrics to telegraf it shouldn't require a tcp/udp connection because of the client library doesn't support unix sockets.
I've hacked together a unix client for my software, but it'd be nice for this functionality to be
in the clients themselves.
The text was updated successfully, but these errors were encountered: