forked from TrueCloudLab/frostfs-sdk-go
[#338] pool: Support avg request time for ListContainerStream
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
749b4e9ab5
commit
fe5b28e6bf
2 changed files with 30 additions and 5 deletions
|
@ -90,6 +90,8 @@ func (m MethodIndex) String() string {
|
||||||
return "containerGet"
|
return "containerGet"
|
||||||
case methodContainerList:
|
case methodContainerList:
|
||||||
return "containerList"
|
return "containerList"
|
||||||
|
case methodContainerListStream:
|
||||||
|
return "containerListStream"
|
||||||
case methodContainerDelete:
|
case methodContainerDelete:
|
||||||
return "containerDelete"
|
return "containerDelete"
|
||||||
case methodEndpointInfo:
|
case methodEndpointInfo:
|
||||||
|
@ -457,13 +459,16 @@ type PrmListStream struct {
|
||||||
//
|
//
|
||||||
// Must be initialized using Pool.ListContainersStream, any other usage is unsafe.
|
// Must be initialized using Pool.ListContainersStream, any other usage is unsafe.
|
||||||
type ResListStream struct {
|
type ResListStream struct {
|
||||||
r *sdkClient.ContainerListReader
|
r *sdkClient.ContainerListReader
|
||||||
handleError func(context.Context, apistatus.Status, error) error
|
elapsedTimeCallback func(time.Duration)
|
||||||
|
handleError func(context.Context, apistatus.Status, error) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read reads another list of the container identifiers.
|
// Read reads another list of the container identifiers.
|
||||||
func (x *ResListStream) Read(buf []cid.ID) (int, error) {
|
func (x *ResListStream) Read(buf []cid.ID) (int, error) {
|
||||||
|
start := time.Now()
|
||||||
n, ok := x.r.Read(buf)
|
n, ok := x.r.Read(buf)
|
||||||
|
x.elapsedTimeCallback(time.Since(start))
|
||||||
if !ok {
|
if !ok {
|
||||||
res, err := x.r.Close()
|
res, err := x.r.Close()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -487,7 +492,14 @@ func (x *ResListStream) Read(buf []cid.ID) (int, error) {
|
||||||
//
|
//
|
||||||
// Returns an error if container can't be read.
|
// Returns an error if container can't be read.
|
||||||
func (x *ResListStream) Iterate(f func(cid.ID) bool) error {
|
func (x *ResListStream) Iterate(f func(cid.ID) bool) error {
|
||||||
return x.r.Iterate(f)
|
start := time.Now()
|
||||||
|
err := x.r.Iterate(func(id cid.ID) bool {
|
||||||
|
x.elapsedTimeCallback(time.Since(start))
|
||||||
|
stop := f(id)
|
||||||
|
start = time.Now()
|
||||||
|
return stop
|
||||||
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close ends reading list of the matched containers and returns the result of the operation
|
// Close ends reading list of the matched containers and returns the result of the operation
|
||||||
|
@ -508,11 +520,19 @@ func (c *clientWrapper) containerListStream(ctx context.Context, prm PrmListStre
|
||||||
Session: prm.Session,
|
Session: prm.Session,
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cl.ContainerListInit(ctx, cliPrm)
|
start := time.Now()
|
||||||
|
cnrRdr, err := cl.ContainerListInit(ctx, cliPrm)
|
||||||
|
c.incRequests(time.Since(start), methodContainerListStream)
|
||||||
if err = c.handleError(ctx, nil, err); err != nil {
|
if err = c.handleError(ctx, nil, err); err != nil {
|
||||||
return ResListStream{}, fmt.Errorf("init container listing on client: %w", err)
|
return ResListStream{}, fmt.Errorf("init container listing on client: %w", err)
|
||||||
}
|
}
|
||||||
return ResListStream{r: res, handleError: c.handleError}, nil
|
return ResListStream{
|
||||||
|
r: cnrRdr,
|
||||||
|
elapsedTimeCallback: func(elapsed time.Duration) {
|
||||||
|
c.incRequests(elapsed, methodContainerListStream)
|
||||||
|
},
|
||||||
|
handleError: c.handleError,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// containerDelete invokes sdkClient.ContainerDelete parse response status to error.
|
// containerDelete invokes sdkClient.ContainerDelete parse response status to error.
|
||||||
|
|
|
@ -97,6 +97,11 @@ func (n NodeStatistic) AverageListContainer() time.Duration {
|
||||||
return n.averageTime(methodContainerList)
|
return n.averageTime(methodContainerList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AverageListContainerStream returns average time to perform ContainerListStream request.
|
||||||
|
func (n NodeStatistic) AverageListContainerStream() time.Duration {
|
||||||
|
return n.averageTime(methodContainerListStream)
|
||||||
|
}
|
||||||
|
|
||||||
// AverageDeleteContainer returns average time to perform ContainerDelete request.
|
// AverageDeleteContainer returns average time to perform ContainerDelete request.
|
||||||
func (n NodeStatistic) AverageDeleteContainer() time.Duration {
|
func (n NodeStatistic) AverageDeleteContainer() time.Duration {
|
||||||
return n.averageTime(methodContainerDelete)
|
return n.averageTime(methodContainerDelete)
|
||||||
|
|
Loading…
Add table
Reference in a new issue