istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/loadbalancersim/network/connection.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package network 16 17 import ( 18 "istio.io/istio/pkg/test/loadbalancersim/timeseries" 19 ) 20 21 type Connection interface { 22 Name() string 23 Request(onDone func()) 24 TotalRequests() uint64 25 ActiveRequests() uint64 26 Latency() *timeseries.Instance 27 } 28 29 func NewConnection(name string, request func(onDone func())) Connection { 30 return &connection{ 31 request: request, 32 helper: NewConnectionHelper(name), 33 } 34 } 35 36 type connection struct { 37 request func(onDone func()) 38 helper *ConnectionHelper 39 } 40 41 func (c *connection) Name() string { 42 return c.helper.Name() 43 } 44 45 func (c *connection) TotalRequests() uint64 { 46 return c.helper.TotalRequests() 47 } 48 49 func (c *connection) ActiveRequests() uint64 { 50 return c.helper.ActiveRequests() 51 } 52 53 func (c *connection) Latency() *timeseries.Instance { 54 return c.helper.Latency() 55 } 56 57 func (c *connection) Request(onDone func()) { 58 c.helper.Request(c.request, onDone) 59 }