@@ -10,26 +10,34 @@ import (
1010
1111// driver makes driver with New publishing
1212func driver (config Config ) (t trace.Driver ) {
13+ config = config .WithSystem ("driver" )
14+ endpoints := config .WithSystem ("balancer" ).GaugeVec ("endpoints" , "local_dc" , "az" )
15+ balancersDiscoveries := config .WithSystem ("balancer" ).CounterVec ("discoveries" , "status" , "cause" )
16+ balancerUpdates := config .WithSystem ("balancer" ).CounterVec ("updates" , "cause" )
17+ conns := config .GaugeVec ("conns" , "endpoint" , "node_id" )
18+ banned := config .WithSystem ("conn" ).GaugeVec ("banned" , "endpoint" , "node_id" , "cause" )
19+ requests := config .WithSystem ("conn" ).CounterVec ("requests" , "status" , "method" , "endpoint" , "node_id" )
20+ tli := config .CounterVec ("transaction_locks_invalidated" )
21+
1322 type endpointKey struct {
1423 localDC bool
1524 az string
1625 }
17-
18- config = config .WithSystem ("driver" )
19- endpoints := config .WithSystem ("balancer" ).GaugeVec ("endpoints" , "local_dc" , "az" )
20- balancerUpdates := config .WithSystem ("balancer" ).CounterVec ("updates" , "force" )
21- conns := config .GaugeVec ("conns" , "address" , "node_id" )
22- banned := config .WithSystem ("conn" ).GaugeVec ("banned" , "address" , "node_id" , "cause" )
23- requests := config .WithSystem ("conn" ).CounterVec ("requests" , "status" , "method" )
24- tli := config .CounterVec ("transaction_locks_invalidated" )
2526 knownEndpoints := make (map [endpointKey ]struct {})
27+
2628 t .OnConnInvoke = func (info trace.DriverConnInvokeStartInfo ) func (trace.DriverConnInvokeDoneInfo ) {
27- method := info .Method
29+ var (
30+ method = info .Method
31+ endpoint = info .Endpoint .Address ()
32+ nodeID = info .Endpoint .NodeID ()
33+ )
2834 return func (info trace.DriverConnInvokeDoneInfo ) {
2935 if config .Details ()& trace .DriverConnEvents != 0 {
3036 requests .With (map [string ]string {
31- "status" : errorBrief (info .Error ),
32- "method" : string (method ),
37+ "status" : errorBrief (info .Error ),
38+ "method" : string (method ),
39+ "endpoint" : endpoint ,
40+ "node_id" : strconv .FormatUint (uint64 (nodeID ), 10 ),
3341 }).Inc ()
3442 if xerrors .IsOperationErrorTransactionLocksInvalidated (info .Error ) {
3543 tli .With (nil ).Inc ()
@@ -42,13 +50,19 @@ func driver(config Config) (t trace.Driver) {
4250 ) func (
4351 trace.DriverConnNewStreamDoneInfo ,
4452 ) {
45- method := info .Method
53+ var (
54+ method = info .Method
55+ endpoint = info .Endpoint .Address ()
56+ nodeID = info .Endpoint .NodeID ()
57+ )
4658 return func (info trace.DriverConnNewStreamRecvInfo ) func (trace.DriverConnNewStreamDoneInfo ) {
4759 return func (info trace.DriverConnNewStreamDoneInfo ) {
4860 if config .Details ()& trace .DriverConnEvents != 0 {
4961 requests .With (map [string ]string {
50- "status" : errorBrief (info .Error ),
51- "method" : string (method ),
62+ "status" : errorBrief (info .Error ),
63+ "method" : string (method ),
64+ "endpoint" : endpoint ,
65+ "node_id" : strconv .FormatUint (uint64 (nodeID ), 10 ),
5266 }).Inc ()
5367 }
5468 }
@@ -57,19 +71,30 @@ func driver(config Config) (t trace.Driver) {
5771 t .OnConnBan = func (info trace.DriverConnBanStartInfo ) func (trace.DriverConnBanDoneInfo ) {
5872 if config .Details ()& trace .DriverConnEvents != 0 {
5973 banned .With (map [string ]string {
60- "address " : info .Endpoint .Address (),
61- "node_id" : idToString (info .Endpoint .NodeID ()),
62- "cause" : errorBrief (info .Cause ),
74+ "endpoint " : info .Endpoint .Address (),
75+ "node_id" : idToString (info .Endpoint .NodeID ()),
76+ "cause" : errorBrief (info .Cause ),
6377 }).Add (1 )
6478 }
6579 return nil
6680 }
81+ t .OnBalancerClusterDiscoveryAttempt = func (info trace.DriverBalancerClusterDiscoveryAttemptStartInfo ) func (
82+ trace.DriverBalancerClusterDiscoveryAttemptDoneInfo ,
83+ ) {
84+ eventType := repeater .EventType (* info .Context )
85+ return func (info trace.DriverBalancerClusterDiscoveryAttemptDoneInfo ) {
86+ balancersDiscoveries .With (map [string ]string {
87+ "status" : errorBrief (info .Error ),
88+ "cause" : eventType ,
89+ }).Inc ()
90+ }
91+ }
6792 t .OnBalancerUpdate = func (info trace.DriverBalancerUpdateStartInfo ) func (trace.DriverBalancerUpdateDoneInfo ) {
6893 eventType := repeater .EventType (* info .Context )
6994 return func (info trace.DriverBalancerUpdateDoneInfo ) {
7095 if config .Details ()& trace .DriverBalancerEvents != 0 {
7196 balancerUpdates .With (map [string ]string {
72- "force " : strconv . FormatBool ( eventType == repeater . EventForce ) ,
97+ "cause " : eventType ,
7398 }).Inc ()
7499 newEndpoints := make (map [endpointKey ]int , len (info .Endpoints ))
75100 for _ , e := range info .Endpoints {
@@ -99,14 +124,14 @@ func driver(config Config) (t trace.Driver) {
99124 }
100125 }
101126 t .OnConnDial = func (info trace.DriverConnDialStartInfo ) func (trace.DriverConnDialDoneInfo ) {
102- address := info .Endpoint .Address ()
127+ endpoint := info .Endpoint .Address ()
103128 nodeID := info .Endpoint .NodeID ()
104129 return func (info trace.DriverConnDialDoneInfo ) {
105130 if config .Details ()& trace .DriverConnEvents != 0 {
106131 if info .Error == nil {
107132 conns .With (map [string ]string {
108- "address " : address ,
109- "node_id" : idToString (nodeID ),
133+ "endpoint " : endpoint ,
134+ "node_id" : idToString (nodeID ),
110135 }).Add (1 )
111136 }
112137 }
@@ -115,8 +140,8 @@ func driver(config Config) (t trace.Driver) {
115140 t .OnConnClose = func (info trace.DriverConnCloseStartInfo ) func (trace.DriverConnCloseDoneInfo ) {
116141 if config .Details ()& trace .DriverConnEvents != 0 {
117142 conns .With (map [string ]string {
118- "address " : info .Endpoint .Address (),
119- "node_id" : idToString (info .Endpoint .NodeID ()),
143+ "endpoint " : info .Endpoint .Address (),
144+ "node_id" : idToString (info .Endpoint .NodeID ()),
120145 }).Add (- 1 )
121146 }
122147 return nil
0 commit comments