Search in sources :

Example 1 with MetricExporterSpi

use of org.apache.ignite.spi.metric.MetricExporterSpi in project ignite by apache.

the class MetricsSelfTest method testAddBeforeRemoveCompletes.

/**
 */
@Test
public void testAddBeforeRemoveCompletes() throws Exception {
    MetricExporterSpi checkSpi = new NoopMetricExporterSpi() {

        private ReadOnlyMetricManager registry;

        private Set<String> names = new HashSet<>();

        @Override
        public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
            registry.addMetricRegistryCreationListener(mreg -> {
                assertFalse(mreg.name() + " should be unique", names.contains(mreg.name()));
                names.add(mreg.name());
            });
            registry.addMetricRegistryRemoveListener(mreg -> names.remove(mreg.name()));
        }

        @Override
        public void setMetricRegistry(ReadOnlyMetricManager registry) {
            this.registry = registry;
        }
    };
    CountDownLatch rmvStarted = new CountDownLatch(1);
    CountDownLatch rmvCompleted = new CountDownLatch(1);
    MetricExporterSpi blockingSpi = new NoopMetricExporterSpi() {

        private ReadOnlyMetricManager registry;

        @Override
        public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
            registry.addMetricRegistryRemoveListener(mreg -> {
                rmvStarted.countDown();
                try {
                    rmvCompleted.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
        }

        @Override
        public void setMetricRegistry(ReadOnlyMetricManager registry) {
            this.registry = registry;
        }
    };
    IgniteConfiguration cfg = new IgniteConfiguration().setMetricExporterSpi(blockingSpi, checkSpi);
    GridTestKernalContext ctx = new GridTestKernalContext(log(), cfg);
    ctx.start();
    // Add metric registry.
    ctx.metric().registry("test");
    // Removes it async, blockingSpi will block remove procedure.
    IgniteInternalFuture rmvFut = runAsync(() -> ctx.metric().remove("test"));
    rmvStarted.await();
    CountDownLatch addStarted = new CountDownLatch(1);
    IgniteInternalFuture addFut = runAsync(() -> {
        addStarted.countDown();
        ctx.metric().registry("test");
    });
    // Waiting for creation to start.
    addStarted.await();
    Thread.sleep(100);
    // Complete removal.
    rmvCompleted.countDown();
    rmvFut.get(getTestTimeout());
    addFut.get(getTestTimeout());
}
Also used : HashSet(java.util.HashSet) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) ReadOnlyMetricManager(org.apache.ignite.spi.metric.ReadOnlyMetricManager) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) MetricExporterSpi(org.apache.ignite.spi.metric.MetricExporterSpi) Nullable(org.jetbrains.annotations.Nullable) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with MetricExporterSpi

use of org.apache.ignite.spi.metric.MetricExporterSpi in project ignite by apache.

the class GridMetricManager method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    for (MetricExporterSpi spi : getSpis()) spi.setMetricRegistry(this);
    startSpi();
    // In case standalone kernal start.
    if (ctx.internalSubscriptionProcessor() == null)
        return;
    ctx.internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
            roMetastorage = metastorage;
            try {
                metastorage.iterate(HITRATE_CFG_PREFIX, (name, val) -> onHitRateConfigChanged(name.substring(HITRATE_CFG_PREFIX.length() + 1), (Long) val));
                metastorage.iterate(HISTOGRAM_CFG_PREFIX, (name, val) -> onHistogramConfigChanged(name.substring(HISTOGRAM_CFG_PREFIX.length() + 1), (long[]) val));
            } catch (IgniteCheckedException e) {
                throw new IgniteException(e);
            }
            metastorage.listen(n -> n.startsWith(HITRATE_CFG_PREFIX), (name, oldVal, newVal) -> onHitRateConfigChanged(name.substring(HITRATE_CFG_PREFIX.length() + 1), (Long) newVal));
            metastorage.listen(n -> n.startsWith(HISTOGRAM_CFG_PREFIX), (name, oldVal, newVal) -> onHistogramConfigChanged(name.substring(HISTOGRAM_CFG_PREFIX.length() + 1), (long[]) newVal));
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onReadyForWrite(DistributedMetaStorage metastorage) {
            GridMetricManager.this.metastorage = metastorage;
        }
    });
}
Also used : ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) Metric(org.apache.ignite.spi.metric.Metric) DistributedMetastorageLifecycleListener(org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) Supplier(java.util.function.Supplier) IgniteUtils.notifyListeners(org.apache.ignite.internal.util.IgniteUtils.notifyListeners) GridKernalContext(org.apache.ignite.internal.GridKernalContext) MemoryMXBean(java.lang.management.MemoryMXBean) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) GridManagerAdapter(org.apache.ignite.internal.managers.GridManagerAdapter) ATTR_PHY_RAM(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_PHY_RAM) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteComponentType(org.apache.ignite.internal.IgniteComponentType) MetricExporterSpi(org.apache.ignite.spi.metric.MetricExporterSpi) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) MemoryUsage(java.lang.management.MemoryUsage) ReadOnlyMetricManager(org.apache.ignite.spi.metric.ReadOnlyMetricManager) MetricUtils.fromFullName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.fromFullName) DoubleMetricImpl(org.apache.ignite.internal.processors.metric.impl.DoubleMetricImpl) RuntimeMXBean(java.lang.management.RuntimeMXBean) F(org.apache.ignite.internal.util.typedef.F) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) Iterator(java.util.Iterator) A(org.apache.ignite.internal.util.typedef.internal.A) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ThreadMXBean(java.lang.management.ThreadMXBean) Serializable(java.io.Serializable) T2(org.apache.ignite.internal.util.typedef.T2) Consumer(java.util.function.Consumer) ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) HitRateMetric(org.apache.ignite.internal.processors.metric.impl.HitRateMetric) NotNull(org.jetbrains.annotations.NotNull) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) DistributedMetastorageLifecycleListener(org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener) MetricExporterSpi(org.apache.ignite.spi.metric.MetricExporterSpi)

Aggregations

Serializable (java.io.Serializable)1 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)1 ManagementFactory (java.lang.management.ManagementFactory)1 MemoryMXBean (java.lang.management.MemoryMXBean)1 MemoryUsage (java.lang.management.MemoryUsage)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1