Skip to content

Commit bf70e43

Browse files
authored
fix TopUtil concurrency problems and http reporter support dynamic filtering configurations
fix TopUtili bug (#54) Http reporter support dynamic filtering configurations #55
1 parent e8cba52 commit bf70e43

File tree

35 files changed

+543
-56
lines changed

35 files changed

+543
-56
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ SOFALookout 是一个利用多维度的 metrics 对目标系统进行度量和
3232
- 服务器端代码编译,进入server子目录,Maven 3.2.5+, JDK Version 1.8+;
3333
## 样例工程
3434

35-
样例工程演示了如何快速使用 SOFALookout,[详细可参考](https://github.com/alipay/sofa-lookout/wiki/useguide-samples)
35+
样例工程演示了如何快速使用 SOFALookout,[详细可参考](https://github.com/sofastack/sofa-lookout/wiki/useguide-samples)
3636

3737
## 贡献
3838
如何参与 SOFALookout [代码贡献](./CONTRIBUTING.md)
3939

4040
## 开源许可
41-
SOFALookout 基于 [Apache License 2.0](./LICENSE) 协议,SOFALookout 依赖了一些三方组件,它们的开源协议参见[依赖组件版权说明](https://github.com/alipay/sofa-lookout/wiki/NOTICE)
41+
SOFALookout 基于 [Apache License 2.0](./LICENSE) 协议,SOFALookout 依赖了一些三方组件,它们的开源协议参见[依赖组件版权说明](https://github.com/sofastack/sofa-lookout/wiki/NOTICE)

README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
![license](https://img.shields.io/badge/license-Apache--2.0-green.svg)
66
![maven](https://img.shields.io/github/release/alipay/sofa-lookout.svg)
77

8-
Visit [WIKI](https://github.com/alipay/sofa-lookout/wiki) for the full documentation, examples, and guides.
8+
Visit [WIKI](https://github.com/sofastack/sofa-lookout/wiki) for the full documentation, examples, and guides.
99

1010
Lookout can help you to measure and monitor the status of the target system with its multi-dimensional metrics.
1111
Lookout's multi-dimensional metrics refer to the [Metrics 2.0](http://metrics20.org/) standard.

client/lookout-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa.lookout</groupId>
77
<artifactId>lookout-client-parent</artifactId>
8-
<version>1.5.3</version>
8+
<version>1.5.4</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

client/lookout-api/src/main/java/com/alipay/lookout/common/top/AbstractTopMetric.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import java.util.Comparator;
2323
import java.util.TreeSet;
24+
import java.util.concurrent.locks.Lock;
25+
import java.util.concurrent.locks.ReentrantLock;
2426

2527
/**
2628
* Created by [email protected] on 2017/3/31.
@@ -44,6 +46,7 @@ public int compare(TopUtil.Entry<Id, Long> o1,
4446
};
4547
private final TopUtil.Order order;
4648
private long lastRolledStamp = -1l;
49+
private final Lock lock = new ReentrantLock();
4750

4851
AbstractTopMetric(Registry registry, Id id, int maxNumber, TopUtil.Order order) {
4952
this.maxNumber = maxNumber;
@@ -57,32 +60,35 @@ protected void pushAsync(Long value, Id timerId) {
5760
TopUtil.executor.execute(new Runnable() {
5861
@Override
5962
public void run() {
60-
pushSafe(set, entry);
63+
lock.lock();
64+
try {
65+
pushSafe(set, entry);
66+
} finally {
67+
lock.unlock();
68+
}
6169
}
6270
});
6371
}
6472

6573
private void pushSafe(TreeSet<TopUtil.Entry<Id, Long>> set, TopUtil.Entry<Id, Long> e) {
66-
synchronized (set) {
67-
if (!set.isEmpty()) {
68-
boolean replaceable = false;
69-
TopUtil.Entry<Id, Long> boundaryTarget = null;
70-
if (order == TopUtil.Order.DESC) {
71-
boundaryTarget = set.first();
72-
replaceable = boundaryTarget.getValue() < e.getValue();
73-
} else {
74-
boundaryTarget = set.last();
75-
replaceable = boundaryTarget.getValue() > e.getValue();
76-
}
77-
if (replaceable & set.size() >= maxNumber) {
78-
remove(set, boundaryTarget);
79-
}
80-
if (!replaceable & set.size() >= maxNumber) {
81-
return;//不add
82-
}
74+
if (!set.isEmpty()) {
75+
boolean replaceable = false;
76+
TopUtil.Entry<Id, Long> boundaryTarget = null;
77+
if (order == TopUtil.Order.DESC) {
78+
boundaryTarget = set.first();
79+
replaceable = boundaryTarget.getValue() < e.getValue();
80+
} else {
81+
boundaryTarget = set.last();
82+
replaceable = boundaryTarget.getValue() > e.getValue();
83+
}
84+
if (replaceable & set.size() >= maxNumber) {
85+
remove(set, boundaryTarget);
86+
}
87+
if (!replaceable & set.size() >= maxNumber) {
88+
return;//不add
8389
}
84-
add(set, e);
8590
}
91+
add(set, e);
8692
}
8793

8894
private void remove(TreeSet<TopUtil.Entry<Id, Long>> set, TopUtil.Entry<Id, Long> boundaryTarget) {

client/lookout-api/src/main/java/com/alipay/lookout/common/top/TopUtil.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public static TopGauger topGauger(final Registry registry, final Id id, final in
7373
if (registry instanceof NoopRegistry || (id == NoopRegistry.INSTANCE.createId(null))) {
7474
return NoopTopGauger.INSTANCE;
7575
}
76-
Id key = id.withTag(TOP_NUM_TAG_KEY, String.valueOf(maxNumber));
76+
final Id key = id.withTag(TOP_NUM_TAG_KEY, String.valueOf(maxNumber));
7777
TopGauger topGauger = computeIfAbsent(cache, key, new Function<Object, TopGauger>() {
7878
@Override
7979
public TopGauger apply(Object obj) {
80-
return new DefaultTopGauger(registry, id, maxNumber, order);
80+
return new DefaultTopGauger(registry, key, maxNumber, order);
8181
}
8282
});
8383
return topGauger == null ? NoopTopGauger.INSTANCE : topGauger;
@@ -109,9 +109,7 @@ public enum Order {
109109
* @param <K>
110110
* @param <V>
111111
*/
112-
static class Entry<K, V>
113-
114-
{
112+
static class Entry<K, V> {
115113
private final K key;
116114
private V value;
117115

client/lookout-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alipay.sofa.lookout</groupId>
88
<artifactId>lookout-client-parent</artifactId>
9-
<version>1.5.3</version>
9+
<version>1.5.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

client/lookout-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alipay.sofa.lookout</groupId>
88
<artifactId>lookout-client-parent</artifactId>
9-
<version>1.5.3</version>
9+
<version>1.5.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

client/lookout-common/src/test/java/com/alipay/lookout/common/utils/ClassUtilTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ public void testNewInstance() {
3535
new Object[] { 5 });
3636
Assert.assertEquals("5", integer.toString());
3737
}
38+
39+
@Test(expected = IllegalStateException.class)
40+
public void testNewInstanceException() {
41+
ClassUtil.newInstance(ArrayList.class.getName() + "x", null, null);
42+
}
3843
}

client/lookout-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alipay.sofa.lookout</groupId>
88
<artifactId>lookout-client-parent</artifactId>
9-
<version>1.5.3</version>
9+
<version>1.5.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

client/lookout-ext-jvm/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alipay.sofa.lookout</groupId>
88
<artifactId>lookout-client-parent</artifactId>
9-
<version>1.5.3</version>
9+
<version>1.5.4</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

0 commit comments

Comments
 (0)