Commit 82b8a9b0 authored by Dan Ramich's avatar Dan Ramich
Browse files

Vendor update remotedialer v0.2.5

parent 285ae221
Showing with 358 additions and 9 deletions
+358 -9
......@@ -68,14 +68,14 @@ require (
github.com/pborman/uuid v1.2.0
github.com/pierrec/lz4 v2.2.6+incompatible // indirect
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/client_golang v1.4.0
github.com/prometheus/common v0.6.0
github.com/rancher/kontainer-driver-metadata v0.0.0-20200125025425-eef1fdc7ca9c
github.com/rancher/kontainer-engine v0.0.4-dev.0.20191210052702-247063a5f1e8
github.com/rancher/machine v0.15.0-rancher25
github.com/rancher/norman v0.0.0-20191126011629-6269ccdbeace
github.com/rancher/rdns-server v0.0.0-20180802070304-bf662911db6a
github.com/rancher/remotedialer v0.2.3-0.20190906213150-8b3983d91ed6
github.com/rancher/remotedialer v0.2.5
github.com/rancher/rke v1.0.4
github.com/rancher/types v0.0.0-20191226170233-4d49bbf42146
github.com/rancher/wrangler v0.1.6-0.20190822171720-e78d8316ee95
......
......@@ -6,5 +6,9 @@ server that will actually do a net.Dial on the client and pipe all bytes back an
Fun times!
Refer to `server/` and `client/` how to use. Or don't.... This framework can hurt your head
Refer to [`server/`](server/) and [`client/`](client/) how to use. Or don't.... This framework can hurt your head
trying to conceptualize.
See also:
* [inlets.dev](https://inlets.dev) which uses the client and server components to form a tunnel for clients behind NAT or firewalls.
......@@ -23,7 +23,7 @@ func connectToProxy(rootCtx context.Context, proxyURL string, headers http.Heade
logrus.WithField("url", proxyURL).Info("Connecting to proxy")
if dialer == nil {
dialer = &websocket.Dialer{HandshakeTimeout:HandshakeTimeOut}
dialer = &websocket.Dialer{Proxy:http.ProxyFromEnvironment,HandshakeTimeout:HandshakeTimeOut}
}
ws, resp, err := dialer.Dial(proxyURL, headers)
if err != nil {
......
......@@ -7,6 +7,8 @@ import (
"net"
"sync"
"time"
"github.com/rancher/remotedialer/metrics"
)
type connection struct {
......@@ -33,10 +35,12 @@ func newConnection(connID int64, session *Session, proto, address string) *conne
session: session,
buf: make(chan []byte, 1024),
}
metrics.IncSMTotalAddConnectionsForWS(session.clientKey, proto, address)
return c
}
func (c *connection) tunnelClose(err error) {
metrics.IncSMTotalRemoveConnectionsForWS(c.session.clientKey, c.addr.Network(), c.addr.String())
c.writeErr(err)
c.doTunnelClose(err)
}
......@@ -79,6 +83,7 @@ func (c *connection) Read(b []byte) (int, error) {
n := c.copyData(b)
if n > 0 {
metrics.AddSMTotalReceiveBytesOnWS(c.session.clientKey, float64(n))
return n, nil
}
......@@ -95,6 +100,7 @@ func (c *connection) Read(b []byte) (int, error) {
c.readBuf = next
n = c.copyData(b)
metrics.AddSMTotalReceiveBytesOnWS(c.session.clientKey, float64(n))
return n, nil
}
......@@ -110,12 +116,16 @@ func (c *connection) Write(b []byte) (int, error) {
if !c.writeDeadline.IsZero() {
deadline = c.writeDeadline.Sub(time.Now()).Nanoseconds() / 1000000
}
return c.session.writeMessage(newMessage(c.connID, deadline, b))
msg := newMessage(c.connID, deadline, b)
metrics.AddSMTotalTransmitBytesOnWS(c.session.clientKey, float64(len(msg.Bytes())))
return c.session.writeMessage(msg)
}
func (c *connection) writeErr(err error) {
if err != nil {
c.session.writeMessage(newErrorMessage(c.connID, err))
msg := newErrorMessage(c.connID, err)
metrics.AddSMTotalTransmitErrorBytesOnWS(c.session.clientKey, float64(len(msg.Bytes())))
c.session.writeMessage(msg)
}
}
......
......@@ -6,5 +6,6 @@ require (
github.com/gorilla/mux v1.7.3
github.com/gorilla/websocket v1.4.0
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.4.0
github.com/sirupsen/logrus v1.4.2
)
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.4.0 h1:YVIb/fVcOTMSqtqZWSKnHpSLBxu8DKgxq8z6RuBZwqI=
github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U=
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
package metrics
import (
"os"
"github.com/prometheus/client_golang/prometheus"
)
const metricsEnv = "CATTLE_PROMETHEUS_METRICS"
var prometheusMetrics = false
var (
TotalAddWS = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_add_websocket_session",
Help: "Total count of added websocket sessions",
},
[]string{"clientkey", "peer"})
TotalRemoveWS = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_remove_websocket_session",
Help: "Total count of removed websocket sessions",
},
[]string{"clientkey", "peer"})
TotalAddConnectionsForWS = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_add_connections",
Help: "Total count of added connections",
},
[]string{"clientkey", "proto", "addr"},
)
TotalRemoveConnectionsForWS = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_remove_connections",
Help: "Total count of removed connections",
},
[]string{"clientkey", "proto", "addr"},
)
TotalTransmitBytesOnWS = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_transmit_bytes",
Help: "Total bytes transmited",
},
[]string{"clientkey"},
)
TotalTransmitErrorBytesOnWS = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_transmit_error_bytes",
Help: "Total error bytes transmited",
},
[]string{"clientkey"},
)
TotalReceiveBytesOnWS = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_receive_bytes",
Help: "Total bytes recieved",
},
[]string{"clientkey"},
)
TotalAddPeerAttempt = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_peer_ws_attempt",
Help: "Total count of attempts to establish websocket session to other rancher-server",
},
[]string{"peer"},
)
TotalPeerConnected = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_peer_ws_connected",
Help: "Total count of connected websocket sessions to other rancher-server",
},
[]string{"peer"},
)
TotalPeerDisConnected = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "session_server",
Name: "total_peer_ws_disconnected",
Help: "Total count of disconnected websocket sessions from other rancher-server",
},
[]string{"peer"},
)
)
func init() {
if os.Getenv(metricsEnv) == "true" {
prometheusMetrics = true
// Session metrics
prometheus.MustRegister(TotalAddWS)
prometheus.MustRegister(TotalRemoveWS)
prometheus.MustRegister(TotalAddConnectionsForWS)
prometheus.MustRegister(TotalRemoveConnectionsForWS)
prometheus.MustRegister(TotalTransmitBytesOnWS)
prometheus.MustRegister(TotalTransmitErrorBytesOnWS)
prometheus.MustRegister(TotalReceiveBytesOnWS)
prometheus.MustRegister(TotalAddPeerAttempt)
prometheus.MustRegister(TotalPeerConnected)
prometheus.MustRegister(TotalPeerDisConnected)
}
}
func IncSMTotalAddWS(clientKey string, peer bool) {
var peerStr string
if peer {
peerStr = "true"
} else {
peerStr = "false"
}
if prometheusMetrics {
TotalAddWS.With(
prometheus.Labels{
"clientkey": clientKey,
"peer": peerStr,
}).Inc()
}
}
func IncSMTotalRemoveWS(clientKey string, peer bool) {
var peerStr string
if prometheusMetrics {
if peer {
peerStr = "true"
} else {
peerStr = "false"
}
TotalRemoveWS.With(
prometheus.Labels{
"clientkey": clientKey,
"peer": peerStr,
}).Inc()
}
}
func AddSMTotalTransmitErrorBytesOnWS(clientKey string, size float64) {
if prometheusMetrics {
TotalTransmitErrorBytesOnWS.With(
prometheus.Labels{
"clientkey": clientKey,
}).Add(size)
}
}
func AddSMTotalTransmitBytesOnWS(clientKey string, size float64) {
if prometheusMetrics {
TotalTransmitBytesOnWS.With(
prometheus.Labels{
"clientkey": clientKey,
}).Add(size)
}
}
func AddSMTotalReceiveBytesOnWS(clientKey string, size float64) {
if prometheusMetrics {
TotalReceiveBytesOnWS.With(
prometheus.Labels{
"clientkey": clientKey,
}).Add(size)
}
}
func IncSMTotalAddConnectionsForWS(clientKey, proto, addr string) {
if prometheusMetrics {
TotalAddConnectionsForWS.With(
prometheus.Labels{
"clientkey": clientKey,
"proto": proto,
"addr": addr,
}).Inc()
}
}
func IncSMTotalRemoveConnectionsForWS(clientKey, proto, addr string) {
if prometheusMetrics {
TotalRemoveConnectionsForWS.With(
prometheus.Labels{
"clientkey": clientKey,
"proto": proto,
"addr": addr,
}).Inc()
}
}
func IncSMTotalAddPeerAttempt(peer string) {
if prometheusMetrics {
TotalAddPeerAttempt.With(
prometheus.Labels{
"peer": peer,
}).Inc()
}
}
func IncSMTotalPeerConnected(peer string) {
if prometheusMetrics {
TotalPeerConnected.With(
prometheus.Labels{
"peer": peer,
}).Inc()
}
}
func IncSMTotalPeerDisConnected(peer string) {
if prometheusMetrics {
TotalPeerDisConnected.With(
prometheus.Labels{
"peer": peer,
}).Inc()
}
}
......@@ -10,6 +10,7 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/rancher/remotedialer/metrics"
"github.com/sirupsen/logrus"
)
......@@ -90,12 +91,14 @@ outer:
default:
}
metrics.IncSMTotalAddPeerAttempt(p.id)
ws, _, err := dialer.Dial(p.url, headers)
if err != nil {
logrus.Errorf("Failed to connect to peer %s [local ID=%s]: %v", p.url, s.PeerID, err)
time.Sleep(5 * time.Second)
continue
}
metrics.IncSMTotalPeerConnected(p.id)
session := NewClientSession(func(string, string) bool { return true }, ws)
session.dialer = func(network, address string) (net.Conn, error) {
......
......@@ -8,6 +8,7 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/rancher/remotedialer/metrics"
)
type sessionListener interface {
......@@ -100,6 +101,7 @@ func (sm *sessionManager) add(clientKey string, conn *websocket.Conn, peer bool)
} else {
sm.clients[clientKey] = append(sm.clients[clientKey], session)
}
metrics.IncSMTotalAddWS(clientKey, peer)
for l := range sm.listeners {
l.sessionAdded(clientKey, session.sessionKey)
......@@ -109,14 +111,21 @@ func (sm *sessionManager) add(clientKey string, conn *websocket.Conn, peer bool)
}
func (sm *sessionManager) remove(s *Session) {
var isPeer bool
sm.Lock()
defer sm.Unlock()
for _, store := range []map[string][]*Session{sm.clients, sm.peers} {
for i, store := range []map[string][]*Session{sm.clients, sm.peers} {
var newSessions []*Session
for _, v := range store[s.clientKey] {
if v.sessionKey == s.sessionKey {
if i == 0 {
isPeer = false
} else {
isPeer = true
}
metrics.IncSMTotalRemoveWS(s.clientKey, isPeer)
continue
}
newSessions = append(newSessions, v)
......
......@@ -272,7 +272,7 @@ github.com/pborman/uuid
github.com/pkg/errors
# github.com/pmezard/go-difflib v1.0.0
github.com/pmezard/go-difflib/difflib
# github.com/prometheus/client_golang v1.1.0 => github.com/prometheus/client_golang v0.9.3
# github.com/prometheus/client_golang v1.4.0 => github.com/prometheus/client_golang v0.9.3
github.com/prometheus/client_golang/api
github.com/prometheus/client_golang/api/prometheus/v1
github.com/prometheus/client_golang/prometheus
......@@ -361,8 +361,9 @@ github.com/rancher/norman/types/values
github.com/rancher/norman/urlbuilder
# github.com/rancher/rdns-server v0.0.0-20180802070304-bf662911db6a
github.com/rancher/rdns-server/model
# github.com/rancher/remotedialer v0.2.3-0.20190906213150-8b3983d91ed6
# github.com/rancher/remotedialer v0.2.5
github.com/rancher/remotedialer
github.com/rancher/remotedialer/metrics
# github.com/rancher/rke v1.0.4
github.com/rancher/rke/addons
github.com/rancher/rke/authz
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment