|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.instrumentation.jmx.rules; |
| 7 | + |
| 8 | +import static io.opentelemetry.instrumentation.jmx.rules.assertions.DataPointAttributes.attribute; |
| 9 | + |
| 10 | +import io.opentelemetry.instrumentation.jmx.rules.assertions.AttributeMatcher; |
| 11 | +import java.io.IOException; |
| 12 | +import java.net.URISyntaxException; |
| 13 | +import java.nio.file.Files; |
| 14 | +import java.nio.file.Path; |
| 15 | +import java.nio.file.Paths; |
| 16 | +import java.time.Duration; |
| 17 | +import java.util.Collections; |
| 18 | +import java.util.List; |
| 19 | +import java.util.stream.Collectors; |
| 20 | +import java.util.stream.Stream; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import org.testcontainers.containers.GenericContainer; |
| 23 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 24 | +import org.testcontainers.images.builder.Transferable; |
| 25 | + |
| 26 | +class HadoopTest extends TargetSystemTest { |
| 27 | + |
| 28 | + public static final String ENDPOINT_PLACEHOLDER = "<<ENDPOINT_PLACEHOLDER>>"; |
| 29 | + |
| 30 | + @Test |
| 31 | + void testMetrics_Hadoop2x() throws URISyntaxException, IOException { |
| 32 | + List<String> yamlFiles = Collections.singletonList("hadoop.yaml"); |
| 33 | + |
| 34 | + yamlFiles.forEach(this::validateYamlSyntax); |
| 35 | + |
| 36 | + // Hadoop startup script does not propagate env vars to launched hadoop daemons, |
| 37 | + // so all the env vars needs to be embedded inside the hadoop-env.sh file |
| 38 | + GenericContainer<?> target = |
| 39 | + new GenericContainer<>("bmedora/hadoop:2.9-base") |
| 40 | + .withCopyToContainer( |
| 41 | + Transferable.of(readAndPreprocessEnvFile("hadoop2-env.sh")), |
| 42 | + "/hadoop/etc/hadoop/hadoop-env.sh") |
| 43 | + .withCreateContainerCmdModifier(cmd -> cmd.withHostName("test-host")) |
| 44 | + .withStartupTimeout(Duration.ofMinutes(3)) |
| 45 | + .withExposedPorts(50070) |
| 46 | + .waitingFor(Wait.forListeningPorts(50070)); |
| 47 | + |
| 48 | + copyAgentToTarget(target); |
| 49 | + copyYamlFilesToTarget(target, yamlFiles); |
| 50 | + |
| 51 | + startTarget(target); |
| 52 | + |
| 53 | + verifyMetrics(createMetricsVerifier()); |
| 54 | + } |
| 55 | + |
| 56 | + private String readAndPreprocessEnvFile(String fileName) throws URISyntaxException, IOException { |
| 57 | + Path path = Paths.get(getClass().getClassLoader().getResource(fileName).toURI()); |
| 58 | + |
| 59 | + String data; |
| 60 | + try (Stream<String> lines = Files.lines(path)) { |
| 61 | + data = |
| 62 | + lines |
| 63 | + .map(line -> line.replace(ENDPOINT_PLACEHOLDER, getOtlpEndpoint())) |
| 64 | + .collect(Collectors.joining("\n")); |
| 65 | + } |
| 66 | + |
| 67 | + return data; |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + void testMetrics_Hadoop3x() throws URISyntaxException, IOException { |
| 72 | + List<String> yamlFiles = Collections.singletonList("hadoop.yaml"); |
| 73 | + |
| 74 | + yamlFiles.forEach(this::validateYamlSyntax); |
| 75 | + |
| 76 | + // Hadoop startup script does not propagate env vars to launched hadoop daemons, |
| 77 | + // so all the env vars needs to be embedded inside the hadoop-env.sh file |
| 78 | + GenericContainer<?> target = |
| 79 | + new GenericContainer<>("loum/hadoop-pseudo:3.3.6") |
| 80 | + .withExposedPorts(9870, 9000) |
| 81 | + .withCopyToContainer( |
| 82 | + Transferable.of(readAndPreprocessEnvFile("hadoop3-env.sh")), |
| 83 | + "/opt/hadoop/etc/hadoop/hadoop-env.sh") |
| 84 | + .withCreateContainerCmdModifier(cmd -> cmd.withHostName("test-host")) |
| 85 | + .waitingFor( |
| 86 | + Wait.forListeningPorts(9870, 9000).withStartupTimeout(Duration.ofMinutes(3))); |
| 87 | + |
| 88 | + copyAgentToTarget(target); |
| 89 | + copyYamlFilesToTarget(target, yamlFiles); |
| 90 | + |
| 91 | + startTarget(target); |
| 92 | + |
| 93 | + verifyMetrics(createMetricsVerifier()); |
| 94 | + } |
| 95 | + |
| 96 | + private static MetricsVerifier createMetricsVerifier() { |
| 97 | + AttributeMatcher nodeNameAttribute = attribute("hadoop.node.name", "test-host"); |
| 98 | + |
| 99 | + return MetricsVerifier.create() |
| 100 | + .disableStrictMode() |
| 101 | + .add( |
| 102 | + "hadoop.dfs.capacity.limit", |
| 103 | + metric -> |
| 104 | + metric |
| 105 | + .hasDescription("Current raw capacity of DataNodes.") |
| 106 | + .hasUnit("By") |
| 107 | + .isUpDownCounter() |
| 108 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 109 | + .add( |
| 110 | + "hadoop.dfs.capacity.used", |
| 111 | + metric -> |
| 112 | + metric |
| 113 | + .hasDescription("Current used capacity across all DataNodes.") |
| 114 | + .hasUnit("By") |
| 115 | + .isUpDownCounter() |
| 116 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 117 | + .add( |
| 118 | + "hadoop.dfs.block.count", |
| 119 | + metric -> |
| 120 | + metric |
| 121 | + .hasDescription("Current number of allocated blocks in the system.") |
| 122 | + .hasUnit("{block}") |
| 123 | + .isUpDownCounter() |
| 124 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 125 | + .add( |
| 126 | + "hadoop.dfs.block.missing", |
| 127 | + metric -> |
| 128 | + metric |
| 129 | + .hasDescription("Current number of missing blocks.") |
| 130 | + .hasUnit("{block}") |
| 131 | + .isUpDownCounter() |
| 132 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 133 | + .add( |
| 134 | + "hadoop.dfs.block.corrupt", |
| 135 | + metric -> |
| 136 | + metric |
| 137 | + .hasDescription("Current number of blocks with corrupt replicas.") |
| 138 | + .hasUnit("{block}") |
| 139 | + .isUpDownCounter() |
| 140 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 141 | + .add( |
| 142 | + "hadoop.dfs.volume.failure.count", |
| 143 | + metric -> |
| 144 | + metric |
| 145 | + .hasDescription("Total number of volume failures across all DataNodes.") |
| 146 | + .hasUnit("{failure}") |
| 147 | + .isCounter() |
| 148 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 149 | + .add( |
| 150 | + "hadoop.dfs.file.count", |
| 151 | + metric -> |
| 152 | + metric |
| 153 | + .hasDescription("Current number of files and directories.") |
| 154 | + .hasUnit("{file}") |
| 155 | + .isUpDownCounter() |
| 156 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 157 | + .add( |
| 158 | + "hadoop.dfs.connection.count", |
| 159 | + metric -> |
| 160 | + metric |
| 161 | + .hasDescription("Current number of connections.") |
| 162 | + .hasUnit("{connection}") |
| 163 | + .isUpDownCounter() |
| 164 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 165 | + .add( |
| 166 | + "hadoop.datanode.live", |
| 167 | + metric -> |
| 168 | + metric |
| 169 | + .hasDescription("Number of data nodes which are currently live.") |
| 170 | + .hasUnit("{node}") |
| 171 | + .isUpDownCounter() |
| 172 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)) |
| 173 | + .add( |
| 174 | + "hadoop.datanode.dead", |
| 175 | + metric -> |
| 176 | + metric |
| 177 | + .hasDescription("Number of data nodes which are currently dead.") |
| 178 | + .hasUnit("{node}") |
| 179 | + .isUpDownCounter() |
| 180 | + .hasDataPointsWithOneAttribute(nodeNameAttribute)); |
| 181 | + } |
| 182 | +} |
0 commit comments