Search in sources :

Example 1 with BooleanMetric

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

the class NodeSslConnectionMetricTest method testDiscovery.

/**
 * Tests SSL discovery metrics produced by node connection.
 */
@Test
public void testDiscovery() throws Exception {
    MetricRegistry reg = mreg(startClusterNode(0), DISCO_METRICS);
    startGrid(nodeConfiguration(1, true, "client", "trustone", CIPHER_SUITE, "TLSv1.2"));
    assertTrue(reg.<BooleanMetric>findMetric("SslEnabled").value());
    assertEquals(0, reg.<IntMetric>findMetric("RejectedSslConnectionsCount").value());
    // Tests untrusted certificate.
    checkNodeJoinFails(2, true, "thinClient", "trusttwo", CIPHER_SUITE, "TLSv1.2");
    checkNodeJoinFails(2, false, "thinClient", "trusttwo", CIPHER_SUITE, "TLSv1.2");
    // Tests untrusted cipher suites.
    checkNodeJoinFails(2, true, "client", "trustone", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2");
    checkNodeJoinFails(2, false, "node01", "trustone", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2");
    // Tests mismatched protocol versions.
    checkNodeJoinFails(2, true, "client", "trustone", null, "TLSv1.1");
    checkNodeJoinFails(2, false, "node01", "trustone", null, "TLSv1.1");
    // In case of an SSL error, the client and server nodes make 2 additional connection attempts.
    assertTrue(waitForCondition(() -> 18 == reg.<IntMetric>findMetric("RejectedSslConnectionsCount").value(), getTestTimeout()));
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with BooleanMetric

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

the class NodeSslConnectionMetricTest method testSslDisabled.

/**
 * Checks the status of the SSL metric if SSL is not configured on the node.
 */
@Test
public void testSslDisabled() throws Exception {
    IgniteEx srv = startGrid();
    MetricRegistry discoReg = mreg(srv, DISCO_METRICS);
    assertFalse(discoReg.<BooleanMetric>findMetric("SslEnabled").value());
    assertEquals(0, discoReg.<IntMetric>findMetric("RejectedSslConnectionsCount").value());
    MetricRegistry commReg = mreg(srv, COMMUNICATION_METRICS_GROUP_NAME);
    assertFalse(commReg.<BooleanMetric>findMetric(SSL_ENABLED_METRIC_NAME).value());
    assertNull(commReg.<IntMetric>findMetric(SSL_REJECTED_SESSIONS_CNT_METRIC_NAME));
    assertNull(commReg.<HistogramMetric>findMetric(SSL_HANDSHAKE_DURATION_HISTOGRAM_METRIC_NAME));
    assertEquals(0, commReg.<IntMetric>findMetric(SESSIONS_CNT_METRIC_NAME).value());
    MetricRegistry cliConnReg = mreg(srv, CLIENT_CONNECTOR_METRICS);
    assertFalse(cliConnReg.<BooleanMetric>findMetric(SSL_ENABLED_METRIC_NAME).value());
    assertNull(cliConnReg.<IntMetric>findMetric(SSL_REJECTED_SESSIONS_CNT_METRIC_NAME));
    assertNull(cliConnReg.<HistogramMetric>findMetric(SSL_HANDSHAKE_DURATION_HISTOGRAM_METRIC_NAME));
    assertEquals(0, cliConnReg.<IntMetric>findMetric(SESSIONS_CNT_METRIC_NAME).value());
    MetricRegistry restConnReg = mreg(srv, REST_CONNECTOR_METRIC_REGISTRY_NAME);
    assertNull(restConnReg.<BooleanMetric>findMetric(SSL_ENABLED_METRIC_NAME));
    assertNull(restConnReg.<IntMetric>findMetric(SSL_REJECTED_SESSIONS_CNT_METRIC_NAME));
    assertNull(restConnReg.<HistogramMetric>findMetric(SSL_HANDSHAKE_DURATION_HISTOGRAM_METRIC_NAME));
    assertNull(restConnReg.<IntMetric>findMetric(SESSIONS_CNT_METRIC_NAME));
    stopAllGrids();
    srv = startGrid(getConfiguration().setConnectorConfiguration(new ConnectorConfiguration()));
    restConnReg = mreg(srv, REST_CONNECTOR_METRIC_REGISTRY_NAME);
    assertFalse(restConnReg.<BooleanMetric>findMetric(SSL_ENABLED_METRIC_NAME).value());
    assertEquals(0, restConnReg.<IntMetric>findMetric(SESSIONS_CNT_METRIC_NAME).value());
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with BooleanMetric

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

the class CacheGroupReencryptionTest method validateMetrics.

/**
 * @param node Grid.
 * @param finished Expected reencryption status.
 */
private void validateMetrics(IgniteEx node, boolean finished) throws IgniteInterruptedCheckedException {
    MetricRegistry registry = node.context().metric().registry(metricName(CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX, cacheName()));
    LongMetric bytesLeft = registry.findMetric("ReencryptionBytesLeft");
    if (finished)
        assertEquals(0, bytesLeft.value());
    else
        assertTrue(waitForCondition(() -> bytesLeft.value() > 0, MAX_AWAIT_MILLIS));
    BooleanMetric reencryptionFinished = registry.findMetric("ReencryptionFinished");
    assertEquals(finished, reencryptionFinished.value());
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric)

Example 4 with BooleanMetric

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

the class IndexMetricsTest method testIndexRebuildingMetric.

/**
 * @throws Exception If failed.
 */
@Test
public void testIndexRebuildingMetric() throws Exception {
    IgniteEx n = startGrid(0);
    n.cluster().active(true);
    String cacheName1 = "cache1";
    String cacheName2 = "cache2";
    IgniteCache<KeyClass, ValueClass> cache1 = n.getOrCreateCache(cacheConfiguration(cacheName1));
    IgniteCache<KeyClass, ValueClass> cache2 = n.getOrCreateCache(cacheConfiguration(cacheName2));
    int entryCnt1 = 100;
    int entryCnt2 = 200;
    for (int i = 0; i < entryCnt1; i++) cache1.put(new KeyClass(i), new ValueClass((long) i));
    for (int i = 0; i < entryCnt2; i++) cache2.put(new KeyClass(i), new ValueClass((long) i));
    List<Path> idxPaths = getIndexBinPaths(cacheName1);
    idxPaths.addAll(getIndexBinPaths(cacheName2));
    stopAllGrids();
    idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
    IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
    n = startGrid(0);
    BooleanMetric idxRebuildInProgress1 = indexRebuildMetric(n, cacheName1, "IsIndexRebuildInProgress");
    BooleanMetric idxRebuildInProgress2 = indexRebuildMetric(n, cacheName2, "IsIndexRebuildInProgress");
    LongAdderMetric idxRebuildKeyProcessed1 = indexRebuildMetric(n, cacheName1, "IndexRebuildKeyProcessed");
    LongAdderMetric idxRebuildKeyProcessed2 = indexRebuildMetric(n, cacheName2, "IndexRebuildKeyProcessed");
    CacheMetrics cacheMetrics1 = cacheMetrics(n, cacheName1);
    CacheMetrics cacheMetrics2 = cacheMetrics(n, cacheName2);
    CacheMetricsMXBean cacheMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheLocalMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheLocalMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheClusterMetricsMXBean1 = cacheMetricsMXBean(n, cacheName1, CacheClusterMetricsMXBeanImpl.class);
    CacheMetricsMXBean cacheClusterMetricsMXBean2 = cacheMetricsMXBean(n, cacheName2, CacheClusterMetricsMXBeanImpl.class);
    n.cluster().active(true);
    BooleanSupplier[] idxRebuildProgressCache1 = { idxRebuildInProgress1::value, cacheMetrics1::isIndexRebuildInProgress, cacheMetricsMXBean1::isIndexRebuildInProgress };
    BooleanSupplier[] idxRebuildProgressCache2 = { idxRebuildInProgress2::value, cacheMetrics2::isIndexRebuildInProgress, cacheMetricsMXBean2::isIndexRebuildInProgress };
    // It must always be false, because metric is only per node.
    BooleanSupplier[] idxRebuildProgressCluster = { cacheClusterMetricsMXBean1::isIndexRebuildInProgress, cacheClusterMetricsMXBean2::isIndexRebuildInProgress };
    LongSupplier[] idxRebuildKeyProcessedCache1 = { idxRebuildKeyProcessed1::value, cacheMetrics1::getIndexRebuildKeysProcessed, cacheMetricsMXBean1::getIndexRebuildKeysProcessed };
    LongSupplier[] idxRebuildKeyProcessedCache2 = { idxRebuildKeyProcessed2::value, cacheMetrics2::getIndexRebuildKeysProcessed, cacheMetricsMXBean2::getIndexRebuildKeysProcessed };
    // It must always be 0, because metric is only per node.
    LongSupplier[] idxRebuildKeyProcessedCluster = { cacheClusterMetricsMXBean1::getIndexRebuildKeysProcessed, cacheClusterMetricsMXBean2::getIndexRebuildKeysProcessed };
    assertEquals(true, idxRebuildProgressCache1);
    assertEquals(true, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(0, idxRebuildKeyProcessedCache1);
    assertEquals(0, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
    ((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName1);
    n.cache(cacheName1).indexReadyFuture().get(30_000);
    assertEquals(false, idxRebuildProgressCache1);
    assertEquals(true, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
    assertEquals(0, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
    ((BlockingIndexesRebuildTask) n.context().indexProcessor().idxRebuild()).stopBlock(cacheName2);
    n.cache(cacheName2).indexReadyFuture().get(30_000);
    assertEquals(false, idxRebuildProgressCache1);
    assertEquals(false, idxRebuildProgressCache2);
    assertEquals(false, idxRebuildProgressCluster);
    assertEquals(entryCnt1, idxRebuildKeyProcessedCache1);
    assertEquals(entryCnt2, idxRebuildKeyProcessedCache2);
    assertEquals(0, idxRebuildKeyProcessedCluster);
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) KeyClass(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.KeyClass) BooleanSupplier(java.util.function.BooleanSupplier) Path(java.nio.file.Path) CacheMetrics(org.apache.ignite.cache.CacheMetrics) CacheMetricsMXBean(org.apache.ignite.mxbean.CacheMetricsMXBean) ValueClass(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.ValueClass) IgniteEx(org.apache.ignite.internal.IgniteEx) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) LongSupplier(java.util.function.LongSupplier) Test(org.junit.Test)

Example 5 with BooleanMetric

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

the class OpenCensusMetricExporterSpi method export.

/**
 * {@inheritDoc}
 */
@Override
public void export() {
    StatsRecorder recorder = Stats.getStatsRecorder();
    try (Scope globalScope = tagScope()) {
        MeasureMap mmap = recorder.newMeasureMap();
        mreg.forEach(mreg -> {
            if (filter != null && !filter.test(mreg))
                return;
            mreg.forEach(metric -> {
                if (metric instanceof LongMetric || metric instanceof IntMetric || metric instanceof BooleanMetric || (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == Date.class) || (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == OffsetDateTime.class)) {
                    long val;
                    if (metric instanceof LongMetric)
                        val = ((LongMetric) metric).value();
                    else if (metric instanceof IntMetric)
                        val = ((IntMetric) metric).value();
                    else if (metric instanceof BooleanMetric)
                        val = ((BooleanMetric) metric).value() ? 1 : 0;
                    else if (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == Date.class)
                        val = ((ObjectMetric<Date>) metric).value().getTime();
                    else
                        val = ((ObjectMetric<OffsetDateTime>) metric).value().toInstant().toEpochMilli();
                    if (val < 0) {
                        if (log.isDebugEnabled())
                            log.debug("OpenCensus doesn't support negative values. Skip record of " + metric.name());
                        return;
                    }
                    MeasureLong msr = (MeasureLong) measures.computeIfAbsent(metric.name(), k -> createMeasure(metric, CREATE_LONG));
                    mmap.put(msr, val);
                } else if (metric instanceof DoubleMetric) {
                    double val = ((DoubleMetric) metric).value();
                    if (val < 0) {
                        if (log.isDebugEnabled())
                            log.debug("OpenCensus doesn't support negative values. Skip record of " + metric.name());
                        return;
                    }
                    MeasureDouble msr = (MeasureDouble) measures.computeIfAbsent(metric.name(), k -> createMeasure(metric, CREATE_DOUBLE));
                    mmap.put(msr, val);
                } else if (metric instanceof HistogramMetric) {
                    String[] names = histogramBucketNames((HistogramMetric) metric);
                    long[] vals = ((HistogramMetric) metric).value();
                    assert names.length == vals.length;
                    for (int i = 0; i < vals.length; i++) {
                        String name = names[i];
                        MeasureLong msr = (MeasureLong) measures.computeIfAbsent(name, k -> createMeasureLong(name, metric.description()));
                        mmap.put(msr, vals[i]);
                    }
                } else if (log.isDebugEnabled()) {
                    log.debug(metric.name() + "[" + metric.getClass() + "] not supported by Opencensus exporter");
                }
            });
        });
        mmap.record();
    }
}
Also used : StatsRecorder(io.opencensus.stats.StatsRecorder) TagContextBuilder(io.opencensus.tags.TagContextBuilder) StatsRecorder(io.opencensus.stats.StatsRecorder) IgniteSpiContext(org.apache.ignite.spi.IgniteSpiContext) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Metric(org.apache.ignite.spi.metric.Metric) Stats(io.opencensus.stats.Stats) Date(java.util.Date) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Function(java.util.function.Function) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) ArrayList(java.util.ArrayList) PushMetricsExporterAdapter(org.apache.ignite.internal.processors.metric.PushMetricsExporterAdapter) Measure(io.opencensus.stats.Measure) MeasureDouble(io.opencensus.stats.Measure.MeasureDouble) MeasureMap(io.opencensus.stats.MeasureMap) Map(java.util.Map) TagMetadata(io.opencensus.tags.TagMetadata) TagValue(io.opencensus.tags.TagValue) View(io.opencensus.stats.View) ReadOnlyMetricManager(org.apache.ignite.spi.metric.ReadOnlyMetricManager) Tags(io.opencensus.tags.Tags) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) Scope(io.opencensus.common.Scope) Name(io.opencensus.stats.View.Name) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LastValue(io.opencensus.stats.Aggregation.LastValue) MeasureLong(io.opencensus.stats.Measure.MeasureLong) T2(org.apache.ignite.internal.util.typedef.T2) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) TagKey(io.opencensus.tags.TagKey) MetricUtils(org.apache.ignite.internal.processors.metric.impl.MetricUtils) UNLIMITED_PROPAGATION(io.opencensus.tags.TagMetadata.TagTtl.UNLIMITED_PROPAGATION) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) LongMetric(org.apache.ignite.spi.metric.LongMetric) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) HistogramMetric(org.apache.ignite.spi.metric.HistogramMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric) MeasureDouble(io.opencensus.stats.Measure.MeasureDouble) MeasureMap(io.opencensus.stats.MeasureMap) Scope(io.opencensus.common.Scope) OffsetDateTime(java.time.OffsetDateTime) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) MeasureLong(io.opencensus.stats.Measure.MeasureLong) DoubleMetric(org.apache.ignite.spi.metric.DoubleMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric)

Aggregations

BooleanMetric (org.apache.ignite.spi.metric.BooleanMetric)6 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)4 Test (org.junit.Test)4 IgniteEx (org.apache.ignite.internal.IgniteEx)3 IntMetric (org.apache.ignite.spi.metric.IntMetric)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 LongMetric (org.apache.ignite.spi.metric.LongMetric)2 Scope (io.opencensus.common.Scope)1 LastValue (io.opencensus.stats.Aggregation.LastValue)1 Measure (io.opencensus.stats.Measure)1 MeasureDouble (io.opencensus.stats.Measure.MeasureDouble)1 MeasureLong (io.opencensus.stats.Measure.MeasureLong)1 MeasureMap (io.opencensus.stats.MeasureMap)1 Stats (io.opencensus.stats.Stats)1 StatsRecorder (io.opencensus.stats.StatsRecorder)1 View (io.opencensus.stats.View)1 Name (io.opencensus.stats.View.Name)1 TagContextBuilder (io.opencensus.tags.TagContextBuilder)1 TagKey (io.opencensus.tags.TagKey)1 TagMetadata (io.opencensus.tags.TagMetadata)1