-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extended interface for metric extension hook to support distingui…
…shing traffic type (#1665) - Add EntryType args to all hook methods
- Loading branch information
1 parent
dae4621
commit 8643dac
Showing
6 changed files
with
285 additions
and
35 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...core/src/main/java/com/alibaba/csp/sentinel/metric/extension/AdvancedMetricExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.alibaba.csp.sentinel.metric.extension; | ||
|
||
import com.alibaba.csp.sentinel.EntryType; | ||
import com.alibaba.csp.sentinel.slots.block.BlockException; | ||
|
||
/** | ||
* Advanced {@link MetricExtension} extending input parameters of each metric | ||
* collection method with the name of {@link EntryType}. | ||
* | ||
* @author bill_yip | ||
* @since 1.8.0 | ||
*/ | ||
public interface AdvancedMetricExtension extends MetricExtension { | ||
/** | ||
* Add current pass count of the resource name. | ||
* | ||
* @param n count to add | ||
* @param resource resource name | ||
* @param entryType {@link EntryType} name, [IN] as provider, [OUT] as consumer. | ||
* @param args additional arguments of the resource, eg. if the resource is | ||
* a method name, the args will be the parameters of the | ||
* method. | ||
*/ | ||
void addPass(String resource, String entryType, int n, Object... args); | ||
|
||
/** | ||
* Add current block count of the resource name. | ||
* | ||
* @param n count to add | ||
* @param resource resource name | ||
* @param entryType {@link EntryType} name, [IN] as provider, [OUT] as | ||
* consumer. | ||
* @param origin the original invoker. | ||
* @param blockException block exception related. | ||
* @param args additional arguments of the resource, eg. if the | ||
* resource is a method name, the args will be the | ||
* parameters of the method. | ||
*/ | ||
void addBlock(String resource, String entryType, int n, String origin, BlockException blockException, | ||
Object... args); | ||
|
||
/** | ||
* Add current completed count of the resource name. | ||
* | ||
* @param n count to add | ||
* @param resource resource name | ||
* @param entryType {@link EntryType} name, [IN] as provider, [OUT] as consumer. | ||
* @param args additional arguments of the resource, eg. if the resource is | ||
* a method name, the args will be the parameters of the | ||
* method. | ||
*/ | ||
void addSuccess(String resource, String entryType, int n, Object... args); | ||
|
||
/** | ||
* Add current exception count of the resource name. | ||
* | ||
* @param n count to add | ||
* @param resource resource name | ||
* @param entryType {@link EntryType} name, [IN] as provider, [OUT] as consumer. | ||
* @param throwable exception related. | ||
*/ | ||
void addException(String resource, String entryType, int n, Throwable throwable); | ||
|
||
/** | ||
* Add response time of the resource name. | ||
* | ||
* @param rt response time in millisecond | ||
* @param resource resource name | ||
* @param entryType {@link EntryType} name, [IN] as provider, [OUT] as consumer. | ||
* @param args additional arguments of the resource, eg. if the resource is | ||
* a method name, the args will be the parameters of the | ||
* method. | ||
*/ | ||
void addRt(String resource, String entryTypeTag, long rt, Object... args); | ||
|
||
/** | ||
* Increase current thread count of the resource name. | ||
* | ||
* @param resource resource name | ||
* @param entryType {@link EntryType} name, [IN] as provider, [OUT] as consumer. | ||
* @param args additional arguments of the resource, eg. if the resource is | ||
* a method name, the args will be the parameters of the | ||
* method. | ||
*/ | ||
void increaseThreadNum(String resource, String entryType, Object... args); | ||
|
||
/** | ||
* Decrease current thread count of the resource name. | ||
* | ||
* @param resource resource name | ||
* @param entryType {@link EntryType} name, [IN] as provider, [OUT] as consumer. | ||
* @param args additional arguments of the resource, eg. if the resource is | ||
* a method name, the args will be the parameters of the | ||
* method. | ||
*/ | ||
void decreaseThreadNum(String resource, String entryType, Object... args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
.../java/com/alibaba/csp/sentinel/metric/extension/callback/FakeAdvancedMetricExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.alibaba.csp.sentinel.metric.extension.callback; | ||
|
||
import com.alibaba.csp.sentinel.metric.extension.AdvancedMetricExtension; | ||
import com.alibaba.csp.sentinel.slots.block.BlockException; | ||
|
||
class FakeAdvancedMetricExtension implements AdvancedMetricExtension { | ||
long pass = 0; | ||
long block = 0; | ||
long success = 0; | ||
long exception = 0; | ||
long rt = 0; | ||
long thread = 0; | ||
|
||
@Override | ||
public void addPass(String resource, int n, Object... args) { | ||
// Do nothing because of using the enhanced one | ||
} | ||
|
||
@Override | ||
public void addBlock(String resource, int n, String origin, BlockException blockException, Object... args) { | ||
// Do nothing because of using the enhanced one | ||
} | ||
|
||
@Override | ||
public void addSuccess(String resource, int n, Object... args) { | ||
// Do nothing because of using the enhanced one | ||
} | ||
|
||
@Override | ||
public void addException(String resource, int n, Throwable throwable) { | ||
// Do nothing because of using the enhanced one | ||
} | ||
|
||
@Override | ||
public void addRt(String resource, long rt, Object... args) { | ||
// Do nothing because of using the enhanced one | ||
} | ||
|
||
@Override | ||
public void increaseThreadNum(String resource, Object... args) { | ||
// Do nothing because of using the enhanced one | ||
} | ||
|
||
@Override | ||
public void decreaseThreadNum(String resource, Object... args) { | ||
// Do nothing because of using the enhanced one | ||
} | ||
|
||
@Override | ||
public void addPass(String resource, String entryType, int n, Object... args) { | ||
pass += n; | ||
} | ||
|
||
@Override | ||
public void addBlock(String resource, String entryType, int n, String origin, BlockException blockException, | ||
Object... args) { | ||
block += n; | ||
} | ||
|
||
@Override | ||
public void addSuccess(String resource, String entryType, int n, Object... args) { | ||
success += n; | ||
} | ||
|
||
@Override | ||
public void addException(String resource, String entryType, int n, Throwable throwable) { | ||
exception += n; | ||
} | ||
|
||
@Override | ||
public void addRt(String resource, String entryTypeTag, long rt, Object... args) { | ||
this.rt += rt; | ||
} | ||
|
||
@Override | ||
public void increaseThreadNum(String resource, String entryType, Object... args) { | ||
thread ++; | ||
} | ||
|
||
@Override | ||
public void decreaseThreadNum(String resource, String entryType, Object... args) { | ||
thread --; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters