apache / apache/dubbo

When MonitorFilter invoked for the first time, no statistics is collected

Open
#7,181 2 comments 0 reactions 1 assignee Claimed by @xiaonayue View on GitHub
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

- [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
- [x] I have checked the [FAQ](https://github.com/apache/dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.

### Environment

* Dubbo version: 2.7.8
* Operating System version: ANY
* Java version: openjdk version "1.8.0_275"

### Steps to reproduce this issue

1. Implements OopsMonitor and OopsMonitorFactory (extends AbstractMonitorFactory), and add to SPI configuration file.
```
oops=org.apache.dubbo.demo.monitor.OopsMonitorFactory
```
2. Run a provider and a consumer, use oops monitor.
```
dubbo.monitor.address=oops://127.0.0.1
```
3. Let consumer call provider's service, "org.apache.dubbo.demo.monitor.OopsMonitor#collect" is not executed at the first service call.

### Reproduce this issue:
https://github.com/zhangyz-hd/dubbo-issues/tree/main/7181

### Reason:
AbstractMonitorFactory#createMonitor() is executed asynchronously, so AbstractMonitorFactory#getMonitor() always return null for the first time.
```
@Override
public Monitor getMonitor(URL url) {
url = url.setPath(MonitorService.class.getName()).addParameter(INTERFACE_KEY, MonitorService.class.getName());
String key = url.toServiceStringWithoutResolving();
Monitor monitor = MONITORS.get(key);
Future future = FUTURES.get(key);
if (monitor != null || future != null) {
return monitor;
}

LOCK.lock();
try {
monitor = MONITORS.get(key);
future = FUTURES.get(key);
if (monitor != null || future != null) {
return monitor;
}

final URL monitorUrl = url;
final CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> AbstractMonitorFactory.this.createMonitor(monitorUrl));
FUTURES.put(key, completableFuture);
completableFuture.thenRunAsync(new MonitorListener(key), EXECUTOR);

return null; //<-HERE(≧∇≦)
} finally {
// unlock
LOCK.unlock();
}
}
```

### Consumer Log:
```
[08/02/21 10:21:37:185 CST] main INFO consumer.Consumer: [DUBBO] ROUND=1, result=Hello world, response from provider: 192.168.3.41:20881, dubbo version: 2.7.8, current host: 192.168.3.41
[08/02/21 10:21:38:194 CST] main INFO monitor.OopsMonitor: [DUBBO] Oops~collect:ROUND=2, dubbo version: 2.7.8, current host: 192.168.3.41
[08/02/21 10:21:38:194 CST] main INFO consumer.Consumer: [DUBBO] ROUND=2, result=Hello world, response from provider: 192.168.3.41:20881, dubbo version: 2.7.8, current host: 192.168.3.41
[08/02/21 10:21:39:201 CST] main INFO monitor.OopsMonitor: [DUBBO] Oops~collect:ROUND=3, dubbo version: 2.7.8, current host: 192.168.3.41
[08/02/21 10:21:39:201 CST] main INFO consumer.Consumer: [DUBBO] ROUND=3, result=Hello world, response from provider: 192.168.3.41:20881, dubbo version: 2.7.8, current host: 192.168.3.41
[08/02/21 10:21:40:208 CST] main INFO monitor.OopsMonitor: [DUBBO] Oops~collect:ROUND=4, dubbo version: 2.7.8, current host: 192.168.3.41
[08/02/21 10:21:40:208 CST] main INFO consumer.Consumer: [DUBBO] ROUND=4, result=Hello world, response from provider: 192.168.3.41:20881, dubbo version: 2.7.8, current host: 192.168.3.41
[08/02/21 10:21:41:212 CST] main INFO monitor.OopsMonitor: [DUBBO] Oops~collect:ROUND=5, dubbo version: 2.7.8, current host: 192.168.3.41
[08/02/21 10:21:41:212 CST] main INFO consumer.Consumer: [DUBBO] ROUND=5, result=Hello world, response from provider: 192.168.3.41:20881, dubbo version: 2.7.8, current host: 192.168.3.41

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.