|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.contrib.jmxmetrics.target_systems; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.entry; |
| 9 | + |
| 10 | +import io.opentelemetry.contrib.jmxmetrics.AbstractIntegrationTest; |
| 11 | +import io.opentelemetry.proto.metrics.v1.Metric; |
| 12 | +import java.time.Duration; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | +import org.testcontainers.containers.GenericContainer; |
| 15 | +import org.testcontainers.containers.Network; |
| 16 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 17 | +import org.testcontainers.junit.jupiter.Container; |
| 18 | + |
| 19 | +class SolrIntegrationTest extends AbstractIntegrationTest { |
| 20 | + |
| 21 | + SolrIntegrationTest() { |
| 22 | + super(/* configFromStdin= */ false, "target-systems/solr.properties"); |
| 23 | + } |
| 24 | + |
| 25 | + @Container |
| 26 | + GenericContainer<?> solr = |
| 27 | + new GenericContainer<>("solr:8.8.2") |
| 28 | + .withNetwork(Network.SHARED) |
| 29 | + .withEnv("LOCAL_JMX", "no") |
| 30 | + .withEnv("ENABLE_REMOTE_JMX_OPTS", "true") |
| 31 | + .withEnv("RMI_PORT", "9990") |
| 32 | + .withCommand("solr-precreate", "gettingstarted") |
| 33 | + .withNetworkAliases("solr") |
| 34 | + .withExposedPorts(9990) |
| 35 | + .withStartupTimeout(Duration.ofMinutes(2)) |
| 36 | + .waitingFor(Wait.forListeningPort()); |
| 37 | + |
| 38 | + @Test |
| 39 | + void endToEnd() { |
| 40 | + waitAndAssertMetrics( |
| 41 | + metric -> |
| 42 | + assertSumWithAttributes( |
| 43 | + metric, |
| 44 | + "solr.document.count", |
| 45 | + "The total number of indexed documents.", |
| 46 | + "{documents}", |
| 47 | + attrs -> attrs.containsOnly(entry("core", "gettingstarted"))), |
| 48 | + metric -> |
| 49 | + assertSumWithAttributes( |
| 50 | + metric, |
| 51 | + "solr.index.size", |
| 52 | + "The total index size.", |
| 53 | + "by", |
| 54 | + attrs -> attrs.containsOnly(entry("core", "gettingstarted"))), |
| 55 | + metric -> |
| 56 | + assertSolrRequestSumMetric( |
| 57 | + metric, "solr.request.count", "The number of queries made.", "{queries}"), |
| 58 | + metric -> |
| 59 | + assertSolrRequestGaugeMetric( |
| 60 | + metric, |
| 61 | + "solr.request.time.average", |
| 62 | + "The average time of a query, based on Solr's histogram configuration.", |
| 63 | + "ms"), |
| 64 | + metric -> |
| 65 | + assertSolrRequestSumMetric( |
| 66 | + metric, |
| 67 | + "solr.request.error.count", |
| 68 | + "The number of queries resulting in an error.", |
| 69 | + "{queries}"), |
| 70 | + metric -> |
| 71 | + assertSolrRequestSumMetric( |
| 72 | + metric, |
| 73 | + "solr.request.timeout.count", |
| 74 | + "The number of queries resulting in a timeout.", |
| 75 | + "{queries}"), |
| 76 | + metric -> |
| 77 | + assertSolrCacheSumMetric( |
| 78 | + metric, |
| 79 | + "solr.cache.eviction.count", |
| 80 | + "The number of evictions from a cache.", |
| 81 | + "{evictions}"), |
| 82 | + metric -> |
| 83 | + assertSolrCacheSumMetric( |
| 84 | + metric, "solr.cache.hit.count", "The number of hits for a cache.", "{hits}"), |
| 85 | + metric -> |
| 86 | + assertSolrCacheSumMetric( |
| 87 | + metric, |
| 88 | + "solr.cache.insert.count", |
| 89 | + "The number of inserts to a cache.", |
| 90 | + "{inserts}"), |
| 91 | + metric -> |
| 92 | + assertSolrCacheSumMetric( |
| 93 | + metric, |
| 94 | + "solr.cache.lookup.count", |
| 95 | + "The number of lookups to a cache.", |
| 96 | + "{lookups}"), |
| 97 | + metric -> |
| 98 | + assertSolrCacheSumMetric( |
| 99 | + metric, "solr.cache.size", "The size of the cache occupied in memory.", "by")); |
| 100 | + } |
| 101 | + |
| 102 | + private void assertSolrRequestSumMetric( |
| 103 | + Metric metric, String name, String description, String unit) { |
| 104 | + assertSumWithAttributes( |
| 105 | + metric, |
| 106 | + name, |
| 107 | + description, |
| 108 | + unit, |
| 109 | + attrs -> |
| 110 | + attrs.containsExactly( |
| 111 | + entry("core", "gettingstarted"), entry("handler", "/get"), entry("type", "QUERY")), |
| 112 | + attrs -> |
| 113 | + attrs.containsExactly( |
| 114 | + entry("core", "gettingstarted"), |
| 115 | + entry("handler", "/update/csv"), |
| 116 | + entry("type", "UPDATE")), |
| 117 | + attrs -> |
| 118 | + attrs.containsExactly( |
| 119 | + entry("core", "gettingstarted"), |
| 120 | + entry("handler", "/query"), |
| 121 | + entry("type", "QUERY")), |
| 122 | + attrs -> |
| 123 | + attrs.containsExactly( |
| 124 | + entry("core", "gettingstarted"), |
| 125 | + entry("handler", "/graph"), |
| 126 | + entry("type", "QUERY")), |
| 127 | + attrs -> |
| 128 | + attrs.containsExactly( |
| 129 | + entry("core", "gettingstarted"), |
| 130 | + entry("handler", "update"), |
| 131 | + entry("type", "UPDATE")), |
| 132 | + attrs -> |
| 133 | + attrs.containsExactly( |
| 134 | + entry("core", "gettingstarted"), |
| 135 | + entry("handler", "/update"), |
| 136 | + entry("type", "UPDATE")), |
| 137 | + attrs -> |
| 138 | + attrs.containsExactly( |
| 139 | + entry("core", "gettingstarted"), |
| 140 | + entry("handler", "/debug/dump"), |
| 141 | + entry("type", "QUERY")), |
| 142 | + attrs -> |
| 143 | + attrs.containsExactly( |
| 144 | + entry("core", "gettingstarted"), |
| 145 | + entry("handler", "/update/json"), |
| 146 | + entry("type", "UPDATE")), |
| 147 | + attrs -> |
| 148 | + attrs.containsExactly( |
| 149 | + entry("core", "gettingstarted"), |
| 150 | + entry("handler", "/stream"), |
| 151 | + entry("type", "QUERY")), |
| 152 | + attrs -> |
| 153 | + attrs.containsExactly( |
| 154 | + entry("core", "gettingstarted"), |
| 155 | + entry("handler", "/export"), |
| 156 | + entry("type", "QUERY")), |
| 157 | + attrs -> |
| 158 | + attrs.containsExactly( |
| 159 | + entry("core", "gettingstarted"), |
| 160 | + entry("handler", "/update/json/docs"), |
| 161 | + entry("type", "UPDATE")), |
| 162 | + attrs -> |
| 163 | + attrs.containsExactly( |
| 164 | + entry("core", "gettingstarted"), entry("handler", "/sql"), entry("type", "QUERY")), |
| 165 | + attrs -> |
| 166 | + attrs.containsExactly( |
| 167 | + entry("core", "gettingstarted"), |
| 168 | + entry("handler", "/select"), |
| 169 | + entry("type", "QUERY"))); |
| 170 | + } |
| 171 | + |
| 172 | + private void assertSolrRequestGaugeMetric( |
| 173 | + Metric metric, String name, String description, String unit) { |
| 174 | + assertGaugeWithAttributes( |
| 175 | + metric, |
| 176 | + name, |
| 177 | + description, |
| 178 | + unit, |
| 179 | + attrs -> |
| 180 | + attrs.containsExactly( |
| 181 | + entry("core", "gettingstarted"), entry("handler", "/get"), entry("type", "QUERY")), |
| 182 | + attrs -> |
| 183 | + attrs.containsExactly( |
| 184 | + entry("core", "gettingstarted"), |
| 185 | + entry("handler", "/update/csv"), |
| 186 | + entry("type", "UPDATE")), |
| 187 | + attrs -> |
| 188 | + attrs.containsExactly( |
| 189 | + entry("core", "gettingstarted"), |
| 190 | + entry("handler", "/query"), |
| 191 | + entry("type", "QUERY")), |
| 192 | + attrs -> |
| 193 | + attrs.containsExactly( |
| 194 | + entry("core", "gettingstarted"), |
| 195 | + entry("handler", "/graph"), |
| 196 | + entry("type", "QUERY")), |
| 197 | + attrs -> |
| 198 | + attrs.containsExactly( |
| 199 | + entry("core", "gettingstarted"), |
| 200 | + entry("handler", "update"), |
| 201 | + entry("type", "UPDATE")), |
| 202 | + attrs -> |
| 203 | + attrs.containsExactly( |
| 204 | + entry("core", "gettingstarted"), |
| 205 | + entry("handler", "/update"), |
| 206 | + entry("type", "UPDATE")), |
| 207 | + attrs -> |
| 208 | + attrs.containsExactly( |
| 209 | + entry("core", "gettingstarted"), |
| 210 | + entry("handler", "/debug/dump"), |
| 211 | + entry("type", "QUERY")), |
| 212 | + attrs -> |
| 213 | + attrs.containsExactly( |
| 214 | + entry("core", "gettingstarted"), |
| 215 | + entry("handler", "/update/json"), |
| 216 | + entry("type", "UPDATE")), |
| 217 | + attrs -> |
| 218 | + attrs.containsExactly( |
| 219 | + entry("core", "gettingstarted"), |
| 220 | + entry("handler", "/stream"), |
| 221 | + entry("type", "QUERY")), |
| 222 | + attrs -> |
| 223 | + attrs.containsExactly( |
| 224 | + entry("core", "gettingstarted"), |
| 225 | + entry("handler", "/export"), |
| 226 | + entry("type", "QUERY")), |
| 227 | + attrs -> |
| 228 | + attrs.containsExactly( |
| 229 | + entry("core", "gettingstarted"), |
| 230 | + entry("handler", "/update/json/docs"), |
| 231 | + entry("type", "UPDATE")), |
| 232 | + attrs -> |
| 233 | + attrs.containsExactly( |
| 234 | + entry("core", "gettingstarted"), entry("handler", "/sql"), entry("type", "QUERY")), |
| 235 | + attrs -> |
| 236 | + attrs.containsExactly( |
| 237 | + entry("core", "gettingstarted"), |
| 238 | + entry("handler", "/select"), |
| 239 | + entry("type", "QUERY"))); |
| 240 | + } |
| 241 | + |
| 242 | + private void assertSolrCacheSumMetric( |
| 243 | + Metric metric, String name, String description, String unit) { |
| 244 | + assertSumWithAttributes( |
| 245 | + metric, |
| 246 | + name, |
| 247 | + description, |
| 248 | + unit, |
| 249 | + attrs -> |
| 250 | + attrs.containsExactly(entry("core", "gettingstarted"), entry("cache", "searcher"))); |
| 251 | + } |
| 252 | +} |
0 commit comments