mirror of
https://github.com/openziti/zrok.git
synced 2025-05-31 07:07:14 +02:00
roughed-in metricsConn for backend (#74)
This commit is contained in:
parent
d87e4ace67
commit
a60449080b
@ -1,12 +1,14 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openziti-test-kitchen/zrok/util"
|
||||
"github.com/openziti/sdk-golang/ziti"
|
||||
"github.com/openziti/sdk-golang/ziti/config"
|
||||
"github.com/openziti/sdk-golang/ziti/edge"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
@ -67,7 +69,11 @@ func newReverseProxy(target string) (*httputil.ReverseProxy, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tpt := http.DefaultTransport.(*http.Transport).Clone()
|
||||
tpt.DialContext = metricsDial
|
||||
|
||||
proxy := httputil.NewSingleHostReverseProxy(targetURL)
|
||||
proxy.Transport = tpt
|
||||
director := proxy.Director
|
||||
proxy.Director = func(req *http.Request) {
|
||||
director(req)
|
||||
@ -80,3 +86,12 @@ func newReverseProxy(target string) (*httputil.ReverseProxy, error) {
|
||||
|
||||
return proxy, nil
|
||||
}
|
||||
|
||||
func metricsDial(_ context.Context, network string, addr string) (net.Conn, error) {
|
||||
conn, err := net.Dial(network, addr)
|
||||
if err != nil {
|
||||
return conn, err
|
||||
}
|
||||
logrus.Infof("returned wrapped metricsConn")
|
||||
return newMetricsConn("self", conn), nil
|
||||
}
|
||||
|
52
endpoints/backend/metrics.go
Normal file
52
endpoints/backend/metrics.go
Normal file
@ -0,0 +1,52 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type metricsConn struct {
|
||||
id string
|
||||
conn net.Conn
|
||||
}
|
||||
|
||||
func newMetricsConn(id string, conn net.Conn) *metricsConn {
|
||||
return &metricsConn{id, conn}
|
||||
}
|
||||
|
||||
func (mc *metricsConn) Read(b []byte) (n int, err error) {
|
||||
n, err = mc.conn.Read(b)
|
||||
logrus.Infof("[%v] => %d", mc.id, n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (mc *metricsConn) Write(b []byte) (n int, err error) {
|
||||
n, err = mc.conn.Write(b)
|
||||
logrus.Infof("[%v] <= %d", mc.id, n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (mc *metricsConn) Close() error {
|
||||
return mc.conn.Close()
|
||||
}
|
||||
|
||||
func (mc *metricsConn) LocalAddr() net.Addr {
|
||||
return mc.conn.LocalAddr()
|
||||
}
|
||||
|
||||
func (mc *metricsConn) RemoteAddr() net.Addr {
|
||||
return mc.conn.RemoteAddr()
|
||||
}
|
||||
|
||||
func (mc *metricsConn) SetDeadline(t time.Time) error {
|
||||
return mc.conn.SetDeadline(t)
|
||||
}
|
||||
|
||||
func (mc *metricsConn) SetReadDeadline(t time.Time) error {
|
||||
return mc.conn.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
func (mc *metricsConn) SetWriteDeadline(t time.Time) error {
|
||||
return mc.conn.SetWriteDeadline(t)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user