InternalDistributedSystemMetricsService implements MetricsService { @Override public MeterRegistry getMeterRegistry() { return meterRegistry; } @VisibleForTesting  InternalDistributedSystemMetricsService(MetricsService.Builder builder, Logger logger,
      CollectingServiceLoader<MetricsPublishingService> publishingServiceLoader,
      CompositeMeterRegistry metricsServiceMeterRegistry,
      Collection<MeterRegistry> persistentMeterRegistries, CloseableMeterBinder binder,
      InternalDistributedSystem system, boolean isClient, boolean hasLocator,
      boolean hasCacheServer); @Override void start(); @Override MeterRegistry getMeterRegistry(); @Override MetricsService.Builder getRebuilder(); @Override void stop(); @Override void addSubregistry(MeterRegistry subregistry); @Override void removeSubregistry(MeterRegistry subregistry);  }
@Test public void remembersMetricsServiceMeterRegistry() { CompositeMeterRegistry theMetricsServiceMeterRegistry = new CompositeMeterRegistry(); metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, theMetricsServiceMeterRegistry, emptyList(), meterBinder, system, false, false, true); assertThat(metricsService.getMeterRegistry()) .isSameAs(theMetricsServiceMeterRegistry); }
@Test public void meterRegistry_registerMeter_addsMemberTagWithSystemName_ifSystemNameIsNotEmpty() { String theSystemName = "non-empty-system-name"; when(system.getName()).thenReturn(theSystemName); MetricsService metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, false, false, true); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasTag("member", theSystemName); }
@Test public void meterRegistry_registerMeter_addsNoMemberTag_ifSystemNameIsEmpty() { when(system.getName()).thenReturn(""); MetricsService metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, false, false, true); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasNoTag("member"); }
@Test public void meterRegistry_registerMeter_addsHostTagWithMemberHostName_ifHostNameIsNotEmpty() { String theHostName = "non-empty-host-name"; when(system.getDistributedMember().getHost()) .thenReturn(theHostName); metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, false, false, true); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasTag("host", theHostName); }
@Test public void meterRegistry_registerMeter_addsClusterTagWithSystemId_ifIsNotClient() { int theSystemId = 21; when(system.getConfig().getDistributedSystemId()) .thenReturn(theSystemId); MetricsService metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, false, false, true); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasTag("cluster", String.valueOf(theSystemId)); }
@Test public void meterRegistry_registerMeter_addsNoClusterTag_ifIsClient() { when(system.getConfig().getDistributedSystemId()) .thenReturn(312); MetricsService metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, true, false, true); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasNoTag("cluster"); }
@Test public void meterRegistry_registerMeter_addsLocatorMemberTypeTag_ifHasLocatorAndHasNoCacheServer() { boolean hasCacheServer = false; boolean hasLocator = true; MetricsService metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, true, hasLocator, hasCacheServer); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasTag("member.type", "locator"); }
@Test public void meterRegistry_registerMeter_addsServerMemberTypeTag_ifHasCacheServerAndHasNoLocator() { boolean hasCacheServer = true; boolean hasLocator = false; MetricsService metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, true, hasLocator, hasCacheServer); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasTag("member.type", "server"); }
@Test public void meterRegistry_registerMeter_addsEmbeddedCacheMemberTypeTag_ifHasNoCacheServerAndHasNoLocator() { boolean hasCacheServer = false; boolean hasLocator = false; MetricsService metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, true, hasLocator, hasCacheServer); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasTag("member.type", "embedded-cache"); }
@Test public void meterRegistry_registerMeter_addsServerLocatorMemberTypeTag_ifHasLocatorAndHasCacheServer() { boolean hasLocator = true; boolean hasCacheServer = true; MetricsService metricsService = new InternalDistributedSystemMetricsService(metricsServiceBuilder, logger, publishingServiceLoader, metricsServiceMeterRegistry, emptyList(), meterBinder, system, true, hasLocator, hasCacheServer); Meter meter = metricsService.getMeterRegistry() .counter("my.meter"); assertThat(meter) .hasTag("member.type", "server-locator"); }