Skip to content

BatchRegister cause instance count error. #11056

@KomachiSion

Description

@KomachiSion

Describe the bug
In AbstractClient, add Instance will add instance size to monitor count for instance when register batch Instance.

    @Override
    public boolean addServiceInstance(Service service, InstancePublishInfo instancePublishInfo) {
        if (null == publishers.put(service, instancePublishInfo)) {
            if (instancePublishInfo instanceof BatchInstancePublishInfo) {
                MetricsMonitor.incrementIpCountWithBatchRegister(instancePublishInfo);
            } else {
                MetricsMonitor.incrementInstanceCount();
            }
        }
        NotifyCenter.publishEvent(new ClientEvent.ClientChangedEvent(this));
        Loggers.SRV_LOG.info("Client change for service {}, {}", service, getClientId());
        return true;
    }

But the old only add the size for first time, when batch register second times, the count will not change. And when deregister the batch instance, the count will be more or less decrease.

Expected behavior
Count right.

Actually behavior
maybe count wrong

How to Reproduce
Steps to reproduce the behavior:

  1. Start any nacos service
  2. Register any size batch instance
  3. Register any other size batch instance for same service by same client.
  4. See the prometheus api and found ipCount is not expected.
  5. close the client, and the ipCount is not 0.

Desktop (please complete the following information):

  • OS: [e.g. Centos]
  • Version [e.g. nacos-server 1.3.1, nacos-client 1.3.1]
  • Module [e.g. naming/config]
  • SDK [e.g. original, spring-cloud-alibaba-nacos, dubbo]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

area/Namingkind/bugCategory issues or prs related to bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions