Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pool statistics optional #453

Merged
merged 10 commits into from
Jul 6, 2023

Conversation

smallhive
Copy link
Contributor

close #431

@smallhive smallhive force-pushed the 431-make-pool-statistics-optional branch 3 times, most recently from 473b938 to bf18054 Compare June 20, 2023 11:30
@smallhive smallhive marked this pull request as ready for review June 20, 2023 12:04
Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I propose is to think more in line of #431 (comment) and #431 (comment)

It may look like an additional SetOperationCallback() for Client's (!) PrmInit. In the form of f func(nodekey []byte, endpoint string, method string, t time.Duration, err error). Endpoint is to be taken from Dial() parameters while nodekey is to be extracted from EndpointInfo() (which can be called instead of a Balance() in Client.Dial(). The rest of the things are pretty obvious, method names should be specified in the documentation.

The reason for endpoint/key is that there can be multiple nodes behind one address and we need to deal with it. This also makes the interface generic enough to be reused in exactly the same way in Pool.InitParameters.

Then there is going to be a stats package with a structure implementing this method (Statistic can be moved there), it has to be protected for concurrent access though. This package could be used both for client and pool. But node could reuse the same interface for its (kludgy) reputationClient (counting things it wants to count).

Then pool has to manage the health of its clients. Always. It has some knobs for it (like ErrorThreshold, but it's an internal pool thing, always there, always passed to clients. If it also has an externally-requested OperationCallback() then it's also called (kinda a proxied call). SetRequestCallback() can be removed, because it's the same thing, just with less parameters.

I think this scheme will cover all of our use cases and allow for some more.

pool/pool.go Outdated Show resolved Hide resolved
pool/pool.go Outdated Show resolved Hide resolved
pool/pool.go Outdated Show resolved Hide resolved
@smallhive smallhive force-pushed the 431-make-pool-statistics-optional branch from bf18054 to 8f4c375 Compare June 22, 2023 10:28
@smallhive smallhive marked this pull request as draft June 22, 2023 10:28
@smallhive smallhive force-pushed the 431-make-pool-statistics-optional branch 2 times, most recently from d5cea25 to 6ec5b2a Compare June 22, 2023 12:38
Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But looks OK otherwise.

stat/stat.go Outdated Show resolved Hide resolved
client/accounting.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
pool/pool.go Outdated
case methodContainerAnnounceUsedSpace:
return "containerAnnounceUsedSpace"
case methodSyncContainerWithNetwork:
return "syncContainerWithNetwork"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will be removed eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will remove it from stat

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean from the pool! All of the real client method should be covered. But syncContainer is not a proper method at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still there, container sync is not a client method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it uses the client but not it's part. Removed

pool/pool.go Outdated
return res, nil
}

func (c *clientWrapper) statisticMiddleware(nodeKey []byte, endpoint string, method stat.Method, duration time.Duration, err error) {
c.incRequests(duration, MethodIndex(method))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one won't be needed after default statistics decoupling from the pool.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still there and we still have Statistics which can be reworked into a stat thing (some structure that exposes the same interface to retrieve statistics and implements OperationCallback).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to stat package

@smallhive smallhive force-pushed the 431-make-pool-statistics-optional branch 5 times, most recently from 5620e71 to f2512e0 Compare June 26, 2023 09:22
@smallhive smallhive marked this pull request as ready for review June 26, 2023 09:49
stat/stat.go Outdated
MethodNetMapSnapshot
MethodObjectHash
MethodObjectSearch
methodLast
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have all client methods here? It should cover all of them even though the pool doesn't use some.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method list is updated, now we have all client methods

res accounting.Decimal
cc contextCall
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a useful change (moving var definition).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change removed

stat/stat.go Outdated
@@ -28,6 +28,7 @@ const (
MethodObjectSearch
MethodContainerAnnounceUsedSpace
MethodSyncContainerWithNetwork
// methodLast is no a valid method name, it's a system anchor for tests, etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is added in a separate commit from methodLast definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}
r.client = c
r.statisticCallback = func(duration time.Duration, err error) {
c.sendStatistic(stat.MethodObjectSearch, duration, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it counted like a MethodObjectSearch now in pool? I'd expect some separate name since it's not a real method, rather just reading from the stream.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with get/put.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extended with three new Method*

client/client.go Outdated
_, err := rpc.Balance(&c.c, new(v2accounting.BalanceRequest),
client.WithContext(prm.parentCtx),
)
endpointInfo, err := c.EndpointInfo(prm.parentCtx, PrmEndpointInfo{})
// return context errors since they signal about dial problem
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why do we still have these then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

pool/pool.go Outdated
return res, nil
}

func (c *clientWrapper) statisticMiddleware(nodeKey []byte, endpoint string, method stat.Method, duration time.Duration, err error) {
c.incRequests(duration, MethodIndex(method))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still there and we still have Statistics which can be reworked into a stat thing (some structure that exposes the same interface to retrieve statistics and implements OperationCallback).

pool/pool.go Outdated
case methodContainerAnnounceUsedSpace:
return "containerAnnounceUsedSpace"
case methodSyncContainerWithNetwork:
return "syncContainerWithNetwork"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still there, container sync is not a client method.

@smallhive smallhive force-pushed the 431-make-pool-statistics-optional branch 6 times, most recently from 2bae95b to a55bfbc Compare July 3, 2023 04:43
@smallhive smallhive force-pushed the 431-make-pool-statistics-optional branch from a55bfbc to 3ac0b0b Compare July 3, 2023 05:54
stat/stat.go Show resolved Hide resolved
client/client.go Show resolved Hide resolved
pool/pool.go Show resolved Hide resolved
client/accounting.go Outdated Show resolved Hide resolved
stat/stat.go Show resolved Hide resolved
stat/monitor.go Show resolved Hide resolved
@carpawell
Copy link
Member

Also, a general suggestion: add more details to commit messages. Some examples from node: nspcc-dev/neofs-node@00afc57, nspcc-dev/neofs-node@67bd9c2.

Changes are good, but the knowledge of why they were done allows speeding up reading and understanding.

@smallhive smallhive force-pushed the 431-make-pool-statistics-optional branch 2 times, most recently from 9fab285 to 1dabbc3 Compare July 4, 2023 06:19
@smallhive
Copy link
Contributor Author

Also, a general suggestion: add more details to commit messages. Some examples from node: nspcc-dev/neofs-node@00afc57, nspcc-dev/neofs-node@67bd9c2.

Changes are good, but the knowledge of why they were done allows speeding up reading and understanding.

It makes sense

@smallhive smallhive requested a review from carpawell July 4, 2023 06:23
@carpawell carpawell removed the request for review from notimetoname July 5, 2023 14:53
stat/stat.go Show resolved Hide resolved
stat/stat.go Show resolved Hide resolved
client/accounting.go Show resolved Hide resolved
stat/stat.go Show resolved Hide resolved
stat/pool.go Show resolved Hide resolved
Using EndpointInfo, instead of Balance have two advantages:
- Check the entrypoint is available;
- Get node public key for statistic purposes.

Any error now is a reason to return from the constructor and broke initialization.

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
…mands

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
@smallhive smallhive force-pushed the 431-make-pool-statistics-optional branch from 1dabbc3 to 41bd8e5 Compare July 6, 2023 05:10
@smallhive smallhive requested a review from carpawell July 6, 2023 05:12
@cthulhu-rider cthulhu-rider merged commit 6acff6a into master Jul 6, 2023
@cthulhu-rider cthulhu-rider deleted the 431-make-pool-statistics-optional branch July 6, 2023 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make pool statistics optional
5 participants