|
| 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.target_systems.MetricAssertions.assertGauge; |
| 9 | +import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSum; |
| 10 | +import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; |
| 11 | +import static org.assertj.core.api.Assertions.entry; |
| 12 | + |
| 13 | +import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; |
| 14 | +import java.time.Duration; |
| 15 | +import java.util.Arrays; |
| 16 | +import java.util.List; |
| 17 | +import java.util.function.Consumer; |
| 18 | +import org.assertj.core.api.MapAssert; |
| 19 | +import org.testcontainers.containers.GenericContainer; |
| 20 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 21 | +import org.testcontainers.images.builder.ImageFromDockerfile; |
| 22 | + |
| 23 | +public class CassandraIntegrationTest extends TargetSystemIntegrationTest { |
| 24 | + |
| 25 | + @Override |
| 26 | + protected GenericContainer<?> createTargetContainer(int jmxPort) { |
| 27 | + return new GenericContainer<>( |
| 28 | + new ImageFromDockerfile() |
| 29 | + .withDockerfileFromBuilder(builder -> builder.from("cassandra:5.0.2").build())) |
| 30 | + .withEnv( |
| 31 | + "JVM_EXTRA_OPTS", |
| 32 | + " -Dcassandra.jmx.remote.port=" |
| 33 | + + jmxPort |
| 34 | + + " -Dcom.sun.management.jmxremote.rmi.port=" |
| 35 | + + jmxPort |
| 36 | + + " -Dcom.sun.management.jmxremote.local.only=false" |
| 37 | + + " -Dcom.sun.management.jmxremote.ssl=false" |
| 38 | + + " -Dcom.sun.management.jmxremote.authenticate=false") |
| 39 | + .withStartupTimeout(Duration.ofMinutes(2)) |
| 40 | + .waitingFor(Wait.forLogMessage(".*Startup complete.*", 1)); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { |
| 45 | + return scraper.withTargetSystem("cassandra"); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + protected void verifyMetrics() { |
| 50 | + waitAndAssertMetrics( |
| 51 | + metric -> |
| 52 | + assertGauge( |
| 53 | + metric, |
| 54 | + "cassandra.client.request.range_slice.latency.50p", |
| 55 | + "Token range read request latency - 50th percentile", |
| 56 | + "us"), |
| 57 | + metric -> |
| 58 | + assertGauge( |
| 59 | + metric, |
| 60 | + "cassandra.client.request.range_slice.latency.99p", |
| 61 | + "Token range read request latency - 99th percentile", |
| 62 | + "us"), |
| 63 | + metric -> |
| 64 | + assertGauge( |
| 65 | + metric, |
| 66 | + "cassandra.client.request.range_slice.latency.max", |
| 67 | + "Maximum token range read request latency", |
| 68 | + "us"), |
| 69 | + metric -> |
| 70 | + assertGauge( |
| 71 | + metric, |
| 72 | + "cassandra.client.request.read.latency.50p", |
| 73 | + "Standard read request latency - 50th percentile", |
| 74 | + "us"), |
| 75 | + metric -> |
| 76 | + assertGauge( |
| 77 | + metric, |
| 78 | + "cassandra.client.request.read.latency.99p", |
| 79 | + "Standard read request latency - 99th percentile", |
| 80 | + "us"), |
| 81 | + metric -> |
| 82 | + assertGauge( |
| 83 | + metric, |
| 84 | + "cassandra.client.request.read.latency.max", |
| 85 | + "Maximum standard read request latency", |
| 86 | + "us"), |
| 87 | + metric -> |
| 88 | + assertGauge( |
| 89 | + metric, |
| 90 | + "cassandra.client.request.write.latency.50p", |
| 91 | + "Regular write request latency - 50th percentile", |
| 92 | + "us"), |
| 93 | + metric -> |
| 94 | + assertGauge( |
| 95 | + metric, |
| 96 | + "cassandra.client.request.write.latency.99p", |
| 97 | + "Regular write request latency - 99th percentile", |
| 98 | + "us"), |
| 99 | + metric -> |
| 100 | + assertGauge( |
| 101 | + metric, |
| 102 | + "cassandra.client.request.write.latency.max", |
| 103 | + "Maximum regular write request latency", |
| 104 | + "us"), |
| 105 | + metric -> |
| 106 | + assertSum( |
| 107 | + metric, |
| 108 | + "cassandra.compaction.tasks.completed", |
| 109 | + "Number of completed compactions since server [re]start", |
| 110 | + "1"), |
| 111 | + metric -> |
| 112 | + assertGauge( |
| 113 | + metric, |
| 114 | + "cassandra.compaction.tasks.pending", |
| 115 | + "Estimated number of compactions remaining to perform", |
| 116 | + "1"), |
| 117 | + metric -> |
| 118 | + assertSum( |
| 119 | + metric, |
| 120 | + "cassandra.storage.load.count", |
| 121 | + "Size of the on disk data size this node manages", |
| 122 | + "by", |
| 123 | + /* isMonotonic= */ false), |
| 124 | + metric -> |
| 125 | + assertSum( |
| 126 | + metric, |
| 127 | + "cassandra.storage.total_hints.count", |
| 128 | + "Number of hint messages written to this node since [re]start", |
| 129 | + "1"), |
| 130 | + metric -> |
| 131 | + assertSum( |
| 132 | + metric, |
| 133 | + "cassandra.storage.total_hints.in_progress.count", |
| 134 | + "Number of hints attempting to be sent currently", |
| 135 | + "1", |
| 136 | + /* isMonotonic= */ false), |
| 137 | + metric -> |
| 138 | + assertSumWithAttributes( |
| 139 | + metric, |
| 140 | + "cassandra.client.request.count", |
| 141 | + "Number of requests by operation", |
| 142 | + "1", |
| 143 | + attrs -> attrs.containsOnly(entry("operation", "RangeSlice")), |
| 144 | + attrs -> attrs.containsOnly(entry("operation", "Read")), |
| 145 | + attrs -> attrs.containsOnly(entry("operation", "Write"))), |
| 146 | + metric -> |
| 147 | + assertSumWithAttributes( |
| 148 | + metric, |
| 149 | + "cassandra.client.request.error.count", |
| 150 | + "Number of request errors by operation", |
| 151 | + "1", |
| 152 | + getRequestErrorCountAttributes())); |
| 153 | + } |
| 154 | + |
| 155 | + @SuppressWarnings("unchecked") |
| 156 | + private static Consumer<MapAssert<String, String>>[] getRequestErrorCountAttributes() { |
| 157 | + List<String> operations = Arrays.asList("RangeSlice", "Read", "Write"); |
| 158 | + List<String> statuses = Arrays.asList("Timeout", "Failure", "Unavailable"); |
| 159 | + |
| 160 | + return operations.stream() |
| 161 | + .flatMap( |
| 162 | + op -> |
| 163 | + statuses.stream() |
| 164 | + .map( |
| 165 | + st -> |
| 166 | + (Consumer<MapAssert<String, String>>) |
| 167 | + attrs -> |
| 168 | + attrs.containsOnly( |
| 169 | + entry("operation", op), entry("status", st)))) |
| 170 | + .toArray(Consumer[]::new); |
| 171 | + } |
| 172 | +} |
0 commit comments