buf fix ip count metrics (#9355)

* buf fix ip count metrics

* run ci

* run ci
This commit is contained in:
陈浩 Nineteen 2022-10-21 09:26:20 +08:00 committed by GitHub
parent 0bd589cb6d
commit 83855da734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 11 deletions

View File

@ -187,7 +187,7 @@ public abstract class AbstractClient implements Client {
MetricsMonitor.getIpCountMonitor().decrementAndGet();
}
}
MetricsMonitor.getIpCountMonitor().addAndGet(-1 * subscribers.size());
MetricsMonitor.getSubscriberCount().addAndGet(-1 * subscribers.size());
}
@Override

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.core.v2.client;
import com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo;
import com.alibaba.nacos.naming.core.v2.pojo.Service;
import com.alibaba.nacos.naming.monitor.MetricsMonitor;
import com.alibaba.nacos.naming.pojo.Subscriber;
import org.junit.Assert;
import org.junit.Before;
@ -45,16 +46,18 @@ public class AbstractClientTest {
instancePublishInfo = new InstancePublishInfo("127.0.0.1", 8890);
subscriber = new Subscriber("127.0.0.1:8848", "agent1", "appName", "127.0.0.1",
"ns1", "serviceName001", 9090);
addServiceInstance();
addServiceSubscriber();
MetricsMonitor.getIpCountMonitor().set(0);
MetricsMonitor.getSubscriberCount().set(0);
}
private void addServiceInstance() {
@Test
public void addServiceInstance() {
boolean result = abstractClient.addServiceInstance(service, instancePublishInfo);
Assert.assertTrue(result);
}
private void addServiceSubscriber() {
@Test
public void addServiceSubscriber() {
Assert.assertTrue(abstractClient.addServiceSubscriber(service, subscriber));
}
@ -65,12 +68,14 @@ public class AbstractClientTest {
@Test
public void removeServiceInstanceSuccess() {
addServiceInstance();
InstancePublishInfo publishInfo = abstractClient.removeServiceInstance(service);
Assert.assertNotNull(publishInfo);
}
@Test
public void getInstancePublishInfo() {
addServiceInstance();
InstancePublishInfo publishInfo = abstractClient.getInstancePublishInfo(service);
Assert.assertNotNull(publishInfo);
}
@ -89,6 +94,7 @@ public class AbstractClientTest {
@Test
public void getSubscriber() {
addServiceSubscriber();
Subscriber subscriber1 = abstractClient.getSubscriber(service);
Assert.assertNotNull(subscriber1);
}
@ -107,11 +113,15 @@ public class AbstractClientTest {
@Test
public void release() {
try {
abstractClient.release();
} catch (Exception e) {
e.printStackTrace();
Assert.assertNotNull(e);
}
abstractClient.addServiceInstance(service, instancePublishInfo);
Assert.assertEquals(1, MetricsMonitor.getIpCountMonitor().get());
abstractClient.addServiceSubscriber(service, subscriber);
Assert.assertEquals(1, MetricsMonitor.getSubscriberCount().get());
abstractClient.release();
Assert.assertEquals(0, MetricsMonitor.getSubscriberCount().get());
Assert.assertEquals(0, MetricsMonitor.getIpCountMonitor().get());
}
}