Sentinel reset node

c9x0cxw0  于 2021-11-29  发布在  Java
关注(0)|答案(3)|浏览(305)

Issue Description

I use sentinel to implement resiliency for by web services.
I found it is very difficult to write multiple tests for the same resource with different rules because sentinel keeps context from the previous test.
For example sentinel_block_requests_total is already not null when the second test is running.

How to reset/clean all sentinel counts before each test using public API?
I use the following code:
ClusterNode node = ClusterBuilderSlot.getClusterNode(nodeName);
if (node!=null) {
node.reset();
node.metrics().clear();
node.metrics().values().clear();
}
But it does not help
I still see that node.totalExceptiopnI() is not set to 0

Describe what happened (or what feature you want)

I need to reset all counters to null

Describe what you expected to happen

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

java web services

Anything else we need to know?

63lcw9qa

63lcw9qa1#

Hi, if you're resetting the metrics of resources, you may just use ClusterBuilderSlot.getClusterNodeMap().clear() to clear the ClusterNode map.

7rfyedvj

7rfyedvj2#

Thanks for the response. It breaks all next tests since no resources exist anymore. For example if I call such method,ClusterBuilderSlot.getClusterNodeMap().clear(), then when I run my tests the code fails on NPE because the line below returns null: ClusterNode node = ClusterBuilderSlot.getClusterNode(nodeName); So I need to reload all rules for all resources and to allow to get cluster node by resource name I run ClusterBuilderSlot.resetClusterNodes(); but it does not help - still getting NPE because ClusterBuilderSlot.getClusterNode(nodeName) is null. Do you know how to resolve it?…

On Mon, Jan 25, 2021 at 10:27 PM Eric Zhao***@***.***> wrote: Hi, if you're resetting the metrics of resources, you may just use ClusterBuilderSlot.getClusterNodeMap().clear() to clear the ClusterNode map. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#1984 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AEW3G6JR3FBFNQ27534UG3LS3ZOGFANCNFSM4WS37JSA> .

f87krz0w

f87krz0w3#

Hi Eric,
please update if you have a fix to reset all counters to 0 when ClusterBuilderSlot.getClusterNodeMap().clear() is called

相关问题