dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

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

Open zhangyz-hd opened this issue 4 years ago • 2 comments

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.
  • [x] I have checked the FAQ 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
  1. Run a provider and a consumer, use oops monitor.
dubbo.monitor.address=oops://127.0.0.1
  1. 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<Monitor> 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<Monitor> 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

zhangyz-hd avatar Feb 08 '21 02:02 zhangyz-hd

fix at #7191

zhangyz-hd avatar Feb 16 '21 07:02 zhangyz-hd

assign to me

xiaonayue avatar Jan 27 '23 06:01 xiaonayue