66 "github.com/rs/zerolog"
77
88 "github.com/cloudflare/cloudflared/edgediscovery/allregions"
9+ "github.com/cloudflare/cloudflared/management"
910)
1011
1112const (
@@ -74,33 +75,35 @@ func (ed *Edge) GetAddrForRPC() (*allregions.EdgeAddr, error) {
7475
7576// GetAddr gives this proxy connection an edge Addr. Prefer Addrs this connection has already used.
7677func (ed * Edge ) GetAddr (connIndex int ) (* allregions.EdgeAddr , error ) {
77- log := ed .log .With ().Int (LogFieldConnIndex , connIndex ).Logger ()
78+ log := ed .log .With ().
79+ Int (LogFieldConnIndex , connIndex ).
80+ Int (management .EventTypeKey , int (management .Cloudflared )).
81+ Logger ()
7882 ed .Lock ()
7983 defer ed .Unlock ()
8084
8185 // If this connection has already used an edge addr, return it.
8286 if addr := ed .regions .AddrUsedBy (connIndex ); addr != nil {
83- log .Debug ().Msg ("edgediscovery - GetAddr: Returning same address back to proxy connection " )
87+ log .Debug ().IPAddr ( LogFieldIPAddress , addr . UDP . IP ). Msg ("edge discovery: returning same edge address back to pool " )
8488 return addr , nil
8589 }
8690
8791 // Otherwise, give it an unused one
8892 addr := ed .regions .GetUnusedAddr (nil , connIndex )
8993 if addr == nil {
90- log .Debug ().Msg ("edgediscovery - GetAddr: No addresses left to give proxy connection" )
94+ log .Debug ().Msg ("edge discovery: no addresses left in pool to give proxy connection" )
9195 return nil , errNoAddressesLeft
9296 }
93- log = ed .log .With ().
94- Int (LogFieldConnIndex , connIndex ).
95- IPAddr (LogFieldIPAddress , addr .UDP .IP ).Logger ()
96- log .Debug ().Msgf ("edgediscovery - GetAddr: Giving connection its new address" )
97+ log .Debug ().IPAddr (LogFieldIPAddress , addr .UDP .IP ).Msg ("edge discovery: giving new address to connection" )
9798 return addr , nil
9899}
99100
100101// GetDifferentAddr gives back the proxy connection's edge Addr and uses a new one.
101102func (ed * Edge ) GetDifferentAddr (connIndex int , hasConnectivityError bool ) (* allregions.EdgeAddr , error ) {
102- log := ed .log .With ().Int (LogFieldConnIndex , connIndex ).Logger ()
103-
103+ log := ed .log .With ().
104+ Int (LogFieldConnIndex , connIndex ).
105+ Int (management .EventTypeKey , int (management .Cloudflared )).
106+ Logger ()
104107 ed .Lock ()
105108 defer ed .Unlock ()
106109
@@ -110,14 +113,14 @@ func (ed *Edge) GetDifferentAddr(connIndex int, hasConnectivityError bool) (*all
110113 }
111114 addr := ed .regions .GetUnusedAddr (oldAddr , connIndex )
112115 if addr == nil {
113- log .Debug ().Msg ("edgediscovery - GetDifferentAddr: No addresses left to give proxy connection" )
116+ log .Debug ().Msg ("edge discovery: no addresses left in pool to give proxy connection" )
114117 // note: if oldAddr were not nil, it will become available on the next iteration
115118 return nil , errNoAddressesLeft
116119 }
117- log = ed . log . With ().
118- Int ( LogFieldConnIndex , connIndex ).
119- IPAddr ( LogFieldIPAddress , addr . UDP . IP ). Logger ()
120- log . Debug (). Msgf ( "edgediscovery - GetDifferentAddr: Giving connection its new address from the address list: %v" , ed . regions . AvailableAddrs () )
120+ log . Debug ().
121+ IPAddr ( LogFieldIPAddress , addr . UDP . IP ).
122+ Int ( "available" , ed . regions . AvailableAddrs ()).
123+ Msg ( "edge discovery: giving new address to connection" )
121124 return addr , nil
122125}
123126
@@ -133,8 +136,9 @@ func (ed *Edge) AvailableAddrs() int {
133136func (ed * Edge ) GiveBack (addr * allregions.EdgeAddr , hasConnectivityError bool ) bool {
134137 ed .Lock ()
135138 defer ed .Unlock ()
136- log := ed .log .With ().
137- IPAddr (LogFieldIPAddress , addr .UDP .IP ).Logger ()
138- log .Debug ().Msgf ("edgediscovery - GiveBack: Address now unused" )
139+ ed .log .Debug ().
140+ Int (management .EventTypeKey , int (management .Cloudflared )).
141+ IPAddr (LogFieldIPAddress , addr .UDP .IP ).
142+ Msg ("edge discovery: gave back address to the pool" )
139143 return ed .regions .GiveBack (addr , hasConnectivityError )
140144}
0 commit comments