|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.contrib.jmxscraper.target_systems; |
| 7 | + |
| 8 | +import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attribute; |
| 9 | +import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeGroup; |
| 10 | +import static io.opentelemetry.contrib.jmxscraper.assertions.DataPointAttributes.attributeWithAnyValue; |
| 11 | + |
| 12 | +import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; |
| 13 | +import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcher; |
| 14 | +import io.opentelemetry.contrib.jmxscraper.assertions.AttributeMatcherGroup; |
| 15 | +import java.nio.file.Path; |
| 16 | +import java.time.Duration; |
| 17 | +import org.testcontainers.containers.GenericContainer; |
| 18 | +import org.testcontainers.containers.Network; |
| 19 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 20 | + |
| 21 | +public class SolrIntegrationTest extends TargetSystemIntegrationTest { |
| 22 | + |
| 23 | + @Override |
| 24 | + protected GenericContainer<?> createTargetContainer(int jmxPort) { |
| 25 | + return new GenericContainer<>("solr:8.8.2") |
| 26 | + .withNetwork(Network.SHARED) |
| 27 | + .withEnv("LOCAL_JMX", "no") |
| 28 | + .withEnv("ENABLE_REMOTE_JMX_OPTS", "true") |
| 29 | + .withEnv("RMI_PORT", Integer.toString(jmxPort)) |
| 30 | + .withCommand("solr-precreate", "gettingstarted") |
| 31 | + .withExposedPorts(jmxPort) |
| 32 | + .withStartupTimeout(Duration.ofMinutes(2)) |
| 33 | + .waitingFor(Wait.forListeningPort()); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + protected JmxScraperContainer customizeScraperContainer( |
| 38 | + JmxScraperContainer scraper, GenericContainer<?> target, Path tempDir) { |
| 39 | + return scraper.withTargetSystem("solr"); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + protected MetricsVerifier createMetricsVerifier() { |
| 44 | + |
| 45 | + AttributeMatcher coreAttribute = attribute("core", "gettingstarted"); |
| 46 | + AttributeMatcherGroup[] requestAttributes = requestAttributes(coreAttribute); |
| 47 | + AttributeMatcherGroup cacheAttributes = |
| 48 | + attributeGroup(coreAttribute, attribute("cache", "searcher")); |
| 49 | + |
| 50 | + return MetricsVerifier.create() |
| 51 | + .add( |
| 52 | + "solr.document.count", |
| 53 | + metric -> |
| 54 | + metric |
| 55 | + .hasDescription("The total number of indexed documents.") |
| 56 | + .hasUnit("{document}") |
| 57 | + .isUpDownCounter() |
| 58 | + .hasDataPointsWithOneAttribute(coreAttribute)) |
| 59 | + .add( |
| 60 | + "solr.index.size", |
| 61 | + metric -> |
| 62 | + metric |
| 63 | + .hasDescription("The total index size.") |
| 64 | + .hasUnit("By") |
| 65 | + .isUpDownCounter() |
| 66 | + .hasDataPointsWithOneAttribute(coreAttribute)) |
| 67 | + .add( |
| 68 | + "solr.request.count", |
| 69 | + metric -> |
| 70 | + metric |
| 71 | + .hasDescription("The number of queries made.") |
| 72 | + .hasUnit("{query}") |
| 73 | + .isCounter() |
| 74 | + .hasDataPointsWithAttributes(requestAttributes)) |
| 75 | + .add( |
| 76 | + "solr.request.time.average", |
| 77 | + metric -> |
| 78 | + metric |
| 79 | + .hasDescription( |
| 80 | + "The average time of a query, based on Solr's histogram configuration.") |
| 81 | + .hasUnit("ms") |
| 82 | + .isGauge() |
| 83 | + .hasDataPointsWithAttributes(requestAttributes)) |
| 84 | + .add( |
| 85 | + "solr.request.error.count", |
| 86 | + metric -> |
| 87 | + metric |
| 88 | + .hasDescription("The number of queries resulting in an error.") |
| 89 | + .hasUnit("{query}") |
| 90 | + .isCounter() |
| 91 | + .hasDataPointsWithAttributes(requestAttributes)) |
| 92 | + .add( |
| 93 | + "solr.request.timeout.count", |
| 94 | + metric -> |
| 95 | + metric |
| 96 | + .hasDescription("The number of queries resulting in a timeout.") |
| 97 | + .hasUnit("{query}") |
| 98 | + .isCounter() |
| 99 | + .hasDataPointsWithAttributes(requestAttributes)) |
| 100 | + .add( |
| 101 | + "solr.cache.eviction.count", |
| 102 | + metric -> |
| 103 | + metric |
| 104 | + .hasDescription("The number of evictions from a cache.") |
| 105 | + .hasUnit("{eviction}") |
| 106 | + .isCounter() |
| 107 | + .hasDataPointsWithAttributes(cacheAttributes)) |
| 108 | + .add( |
| 109 | + "solr.cache.hit.count", |
| 110 | + metric -> |
| 111 | + metric |
| 112 | + .hasDescription("The number of hits for a cache.") |
| 113 | + .hasUnit("{hit}") |
| 114 | + .isCounter() |
| 115 | + .hasDataPointsWithAttributes(cacheAttributes)) |
| 116 | + .add( |
| 117 | + "solr.cache.insert.count", |
| 118 | + metric -> |
| 119 | + metric |
| 120 | + .hasDescription("The number of inserts to a cache.") |
| 121 | + .hasUnit("{insert}") |
| 122 | + .isCounter() |
| 123 | + .hasDataPointsWithAttributes(cacheAttributes)) |
| 124 | + .add( |
| 125 | + "solr.cache.lookup.count", |
| 126 | + metric -> |
| 127 | + metric |
| 128 | + .hasDescription("The number of lookups to a cache.") |
| 129 | + .hasUnit("{lookup}") |
| 130 | + .isCounter() |
| 131 | + .hasDataPointsWithAttributes(cacheAttributes)) |
| 132 | + .add( |
| 133 | + "solr.cache.size", |
| 134 | + metric -> |
| 135 | + metric |
| 136 | + .hasDescription("The size of the cache occupied in memory.") |
| 137 | + .hasUnit("By") |
| 138 | + .isUpDownCounter() |
| 139 | + .hasDataPointsWithAttributes(cacheAttributes)); |
| 140 | + } |
| 141 | + |
| 142 | + private static AttributeMatcherGroup[] requestAttributes(AttributeMatcher coreAttribute) { |
| 143 | + // ignore actual 'handler' values due to high cardinality (10+) and an exact matching makes test |
| 144 | + // flaky |
| 145 | + return new AttributeMatcherGroup[] { |
| 146 | + attributeGroup(coreAttribute, attributeWithAnyValue("handler"), attribute("type", "QUERY")), |
| 147 | + attributeGroup(coreAttribute, attributeWithAnyValue("handler"), attribute("type", "UPDATE")) |
| 148 | + }; |
| 149 | + } |
| 150 | +} |
0 commit comments