-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add server connection count metric (#464)
* add server connection count metric * add error check for open metric * update to noop on false * update metric name * make transport wrapper private * Update thriftbp/server_transport.go Co-authored-by: Kyle Lemons <[email protected]> * Update config.go * switch for gauge for connection metrics * remove metrics config flag * update docs Co-authored-by: Kyle Lemons <[email protected]>
- Loading branch information
1 parent
71d3d5e
commit 2c2736a
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package thriftbp | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/apache/thrift/lib/go/thrift" | ||
"github.com/go-kit/kit/metrics" | ||
|
||
"github.com/reddit/baseplate.go/metricsbp" | ||
) | ||
|
||
const meterNameTransportConnCounter = "thrift.connections" | ||
|
||
type CountedTServerTransport struct { | ||
thrift.TServerTransport | ||
} | ||
|
||
func (m *CountedTServerTransport) Accept() (thrift.TTransport, error) { | ||
transport, err := m.TServerTransport.Accept() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return newCountedTTransport(transport), nil | ||
} | ||
|
||
type countedTTransport struct { | ||
thrift.TTransport | ||
|
||
gauge metrics.Gauge | ||
closeOnce sync.Once | ||
} | ||
|
||
func newCountedTTransport(transport thrift.TTransport) thrift.TTransport { | ||
return &countedTTransport{ | ||
TTransport: transport, | ||
gauge: metricsbp.M.RuntimeGauge(meterNameTransportConnCounter), | ||
} | ||
} | ||
|
||
func (m *countedTTransport) Close() error { | ||
m.closeOnce.Do(func() { | ||
m.gauge.Add(-1) | ||
}) | ||
return m.TTransport.Close() | ||
} | ||
|
||
func (m *countedTTransport) Open() error { | ||
if err := m.TTransport.Open(); err != nil { | ||
return err | ||
} | ||
m.gauge.Add(1) | ||
return nil | ||
} |