Fix integration tests failure (#2067)
Fixed integration tests failure on Linux with Kernel 5.16.x Signed-off-by: Andrey Pleskach <ples@aiven.io>
This commit is contained in:
parent
892801a074
commit
27ed6fc82c
|
@ -51,6 +51,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -401,6 +402,7 @@ public class OsProbe {
|
||||||
long numberOfPeriods = -1;
|
long numberOfPeriods = -1;
|
||||||
long numberOfTimesThrottled = -1;
|
long numberOfTimesThrottled = -1;
|
||||||
long timeThrottledNanos = -1;
|
long timeThrottledNanos = -1;
|
||||||
|
|
||||||
for (final String line : lines) {
|
for (final String line : lines) {
|
||||||
final String[] fields = line.split("\\s+");
|
final String[] fields = line.split("\\s+");
|
||||||
switch (fields[0]) {
|
switch (fields[0]) {
|
||||||
|
@ -415,9 +417,17 @@ public class OsProbe {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert numberOfPeriods != -1;
|
if (isCpuStatWarningsLogged.getAndSet(true) == false) {
|
||||||
assert numberOfTimesThrottled != -1;
|
if (numberOfPeriods == -1) {
|
||||||
assert timeThrottledNanos != -1;
|
logger.warn("Expected to see nr_periods filed but found nothing");
|
||||||
|
}
|
||||||
|
if (numberOfTimesThrottled == -1) {
|
||||||
|
logger.warn("Expected to see nr_throttled filed but found nothing");
|
||||||
|
}
|
||||||
|
if (timeThrottledNanos == -1) {
|
||||||
|
logger.warn("Expected to see throttled_time filed but found nothing");
|
||||||
|
}
|
||||||
|
}
|
||||||
return new OsStats.Cgroup.CpuStat(numberOfPeriods, numberOfTimesThrottled, timeThrottledNanos);
|
return new OsStats.Cgroup.CpuStat(numberOfPeriods, numberOfTimesThrottled, timeThrottledNanos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +450,7 @@ public class OsProbe {
|
||||||
@SuppressForbidden(reason = "access /sys/fs/cgroup/cpu")
|
@SuppressForbidden(reason = "access /sys/fs/cgroup/cpu")
|
||||||
List<String> readSysFsCgroupCpuAcctCpuStat(final String controlGroup) throws IOException {
|
List<String> readSysFsCgroupCpuAcctCpuStat(final String controlGroup) throws IOException {
|
||||||
final List<String> lines = Files.readAllLines(PathUtils.get("/sys/fs/cgroup/cpu", controlGroup, "cpu.stat"));
|
final List<String> lines = Files.readAllLines(PathUtils.get("/sys/fs/cgroup/cpu", controlGroup, "cpu.stat"));
|
||||||
assert lines != null && lines.size() == 3;
|
assert lines != null && lines.isEmpty() == false;
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,11 +598,18 @@ public class OsProbe {
|
||||||
return OsProbeHolder.INSTANCE;
|
return OsProbeHolder.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
OsProbe() {
|
private final Logger logger;
|
||||||
|
|
||||||
|
private AtomicBoolean isCpuStatWarningsLogged = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
OsProbe() {
|
||||||
|
this(LogManager.getLogger(OsProbe.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Logger logger = LogManager.getLogger(getClass());
|
/*For testing purpose*/
|
||||||
|
OsProbe(final Logger logger) {
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
OsInfo osInfo(long refreshInterval, int allocatedProcessors) throws IOException {
|
OsInfo osInfo(long refreshInterval, int allocatedProcessors) throws IOException {
|
||||||
return new OsInfo(
|
return new OsInfo(
|
||||||
|
|
|
@ -50,9 +50,17 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.lucene.util.Constants;
|
import org.apache.lucene.util.Constants;
|
||||||
import org.opensearch.test.OpenSearchTestCase;
|
import org.opensearch.test.OpenSearchTestCase;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.reset;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
public class OsProbeTests extends OpenSearchTestCase {
|
public class OsProbeTests extends OpenSearchTestCase {
|
||||||
|
|
||||||
public void testOsInfo() throws IOException {
|
public void testOsInfo() throws IOException {
|
||||||
|
@ -277,6 +285,24 @@ public class OsProbeTests extends OpenSearchTestCase {
|
||||||
assertNull(cgroup);
|
assertNull(cgroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testLogWarnCpuMessageOnlyOnes() {
|
||||||
|
final Logger logger = mock(Logger.class);
|
||||||
|
|
||||||
|
final OsProbe noCpuStatsOsProbe = new OsProbe(logger) {
|
||||||
|
@Override
|
||||||
|
List<String> readSysFsCgroupCpuAcctCpuStat(String controlGroup) throws IOException {
|
||||||
|
return Collections.singletonList("nr_periods 1");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
noCpuStatsOsProbe.osStats();
|
||||||
|
// no nr_throttled and throttled_time
|
||||||
|
verify(logger, times(2)).warn(anyString());
|
||||||
|
reset(logger);
|
||||||
|
noCpuStatsOsProbe.osStats();
|
||||||
|
verify(logger, never()).warn(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
private static List<String> getProcSelfGroupLines(String hierarchy) {
|
private static List<String> getProcSelfGroupLines(String hierarchy) {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
"10:freezer:/",
|
"10:freezer:/",
|
||||||
|
@ -361,4 +387,5 @@ public class OsProbeTests extends OpenSearchTestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue