Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ using [GraalVM Community Edition](https://github.com/graalvm/graalvm-ce-builds/r
dependencies and can be run as is.

A pure Java version in jar form (meshmonitor.jar) is also available. The Java version should work on
any platform with Java 17 or later installed (although it has only been tested on Linux).
any platform with Java 8 or later installed (although it has only been tested on Linux).

# Using Meshmonitor

Expand Down Expand Up @@ -230,11 +230,11 @@ Use the following command to run meshmonitor from the jar file:
java -jar meshmonitor.jar <ARGS>
```

It requires at least Java 17 to run.
Java 8 is enough to run it but Java 11 is required to build and execute tests.

## Building

Java SDK is required to build and test the Meshmonitor. Version 17 or above.
Java SDK is required to build and test the Meshmonitor. Version 11 or above.
Maven is used as a build system but does not need to be installed locally.

The `mvnw` script (or `mvnw.cmd` on Windows) is used to bootstrap the build
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>

<maven.compiler.testSource>17</maven.compiler.testSource>
<maven.compiler.testTarget>17</maven.compiler.testTarget>
<maven.compiler.testSource>11</maven.compiler.testSource>
<maven.compiler.testTarget>11</maven.compiler.testTarget>

<imageName>meshmonitor</imageName>
<mainClass>org.voltdb.meshmonitor.cli.MeshMonitorCommand</mainClass>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/voltdb/meshmonitor/ConsoleLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ private void log(String hostAddress, LogLevel logLevel, String message, Object..
String colourfulDateTime = CommandLine.Help.Ansi.AUTO.string(String.format("@|%s %s|@", logLevel, dateTime));
String colourfulHostAddress = CommandLine.Help.Ansi.AUTO.string(String.format("@|%s [%15s]|@", logLevel, hostAddress));

out.println(colourfulDateTime + " " + colourfulHostAddress + " " + message.formatted(args));
out.println(colourfulDateTime + " " + colourfulHostAddress + " " + String.format(message, args));
}

public void debug(InetSocketAddress socketAddress, String format, Object... args) {
String hostAddress = socketAddress.getAddress().getHostAddress();

if (enableDebugLogging) {
log(hostAddress, LogLevel.INFO, format.formatted(args));
log(hostAddress, LogLevel.INFO, String.format(format, args));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public String getSimpleVersion() {
String maybeCommitId = Objects.toString(properties.get(GIT_COMMIT_ID_PROPERTY), "");

StringBuilder version = new StringBuilder();
if (!maybeTags.isBlank()) {
if (!maybeTags.trim().isEmpty()) {
version.append(maybeTags);
} else if (!maybeCommitId.isBlank()) {
} else if (!maybeCommitId.trim().isEmpty()) {
version.append(maybeCommitId);
} else {
version.append(VERSION_UNKNOWN);
}

if (!maybeBuildTime.isBlank()) {
if (!maybeBuildTime.trim().isEmpty()) {
version.append(" built on ").append(maybeBuildTime);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/voltdb/meshmonitor/HistogramLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ private String format(Histogram deltaHistogram, long minHiccupSizeMicroseconds)

private String getFormatWithColours(double value, double minHiccupSize) {
if (value > 999.9) {
String formatted = "%4.1fs".formatted(value / 1000.0);
String formatted = String.format("%4.1fs", value / 1000.0);
return CommandLine.Help.Ansi.AUTO.string("@|bold,red " + formatted + "|@");
}

String formatted = "%5.1f".formatted(value);
String formatted = String.format("%5.1f", value);
if (value > minHiccupSize) {
return CommandLine.Help.Ansi.AUTO.string("@|bold,yellow " + formatted + "|@");
}
Expand Down
58 changes: 53 additions & 5 deletions src/main/java/org/voltdb/meshmonitor/MeshMonitorTimings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Volt Active Data Inc.
* Copyright (C) 2024-2025 Volt Active Data Inc.
*
* Use of this source code is governed by an MIT
* license that can be found in the LICENSE file or at
Expand All @@ -9,13 +9,24 @@

import org.HdrHistogram.SynchronizedHistogram;

public record MeshMonitorTimings(
HistogramWithDelta receiveHistogram,
HistogramWithDelta sendHistogram,
HistogramWithDelta deltaHistogram) {
import java.util.Objects;

public final class MeshMonitorTimings {

public static final int NUMBER_OF_SIGNIFICANT_VALUE_DIGITS = 3;
public static final long HIGHEST_TRACKABLE_VALUE = 24 * 60 * 60 * 1000 * 1000L;
private final HistogramWithDelta receiveHistogram;
private final HistogramWithDelta sendHistogram;
private final HistogramWithDelta deltaHistogram;

public MeshMonitorTimings(
HistogramWithDelta receiveHistogram,
HistogramWithDelta sendHistogram,
HistogramWithDelta deltaHistogram) {
this.receiveHistogram = receiveHistogram;
this.sendHistogram = sendHistogram;
this.deltaHistogram = deltaHistogram;
}

public void pingReceived(long now, long lastReceiveTime, long timestampFromRemoteHost, long pingInterval) {
long valueToRecord = now - lastReceiveTime;
Expand All @@ -41,4 +52,41 @@ public static MeshMonitorTimings createDefault(ConsoleLogger logger) {
new HistogramWithDelta(logger, "delta", defaultHistogram())
);
}

public HistogramWithDelta receiveHistogram() {
return receiveHistogram;
}

public HistogramWithDelta sendHistogram() {
return sendHistogram;
}

public HistogramWithDelta deltaHistogram() {
return deltaHistogram;
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass())
return false;
MeshMonitorTimings that = (MeshMonitorTimings) obj;
return Objects.equals(this.receiveHistogram, that.receiveHistogram) &&
Objects.equals(this.sendHistogram, that.sendHistogram) &&
Objects.equals(this.deltaHistogram, that.deltaHistogram);
}

@Override
public int hashCode() {
return Objects.hash(receiveHistogram, sendHistogram, deltaHistogram);
}

@Override
public String toString() {
return "MeshMonitorTimings[" +
"receiveHistogram=" + receiveHistogram + ", " +
"sendHistogram=" + sendHistogram + ", " +
"deltaHistogram=" + deltaHistogram + ']';
}

}
5 changes: 3 additions & 2 deletions src/main/java/org/voltdb/meshmonitor/ServerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class ServerManager {

Expand All @@ -30,14 +31,14 @@ public ServerManager(ConsoleLogger consoleLogger, MonitorFactory monitorFactory,
public synchronized List<Monitor> getMonitors() {
return monitors.stream()
.filter(Monitor::isRunning)
.toList();
.collect(Collectors.toList());
}

public synchronized List<InetSocketAddress> getConnections() {
return monitors.stream()
.filter(Monitor::isRunning)
.map(Monitor::getRemoteId)
.toList();
.collect(Collectors.toList());
}

public synchronized boolean createNewMonitorIfNotAlreadyPresent(SocketChannel channel, MeshMonitor meshMonitor, InetSocketAddress remoteId) {
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/org/voltdb/meshmonitor/cli/MeshMonitorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ public Integer call() {

System.out.println(
CommandLine.Help.Ansi.AUTO.string(
"""
@|green __ ___ __ _ __ \s
/ |/ /__ _____/ /_ ____ ___ ____ ____ (_) /_____ _____
/ /|_/ / _ \\/ ___/ __ \\/ __ `__ \\/ __ \\/ __ \\/ / __/ __ \\/ ___/
/ / / / __(__ ) / / / / / / / / /_/ / / / / / /_/ /_/ / / \s
/_/ /_/\\___/____/_/ /_/_/ /_/ /_/\\____/_/ /_/_/\\__/\\____/_/ \s
|@ %s
""".formatted(new GitPropertiesVersionProvider().getSimpleVersion())));
String.format(
"@|green __ ___ __ _ __ \n" +
" / |/ /__ _____/ /_ ____ ___ ____ ____ (_) /_____ _____\n" +
" / /|_/ / _ \\/ ___/ __ \\/ __ `__ \\/ __ \\/ __ \\/ / __/ __ \\/ ___/\n" +
" / / / / __(__ ) / / / / / / / / /_/ / / / / / /_/ /_/ / / \n" +
" /_/ /_/\\___/____/_/ /_/_/ /_/ /_/\\____/_/ /_/_/\\__/\\____/_/ \n" +
" |@ %s\n",
new GitPropertiesVersionProvider().getSimpleVersion()
)
)
);

ConsoleLogger consoleLogger = new ConsoleLogger(spec.commandLine().getOut(), enableDebugLogging);
ServerManager serverManager = new ServerManager(consoleLogger, Monitor::new, Duration.ofMillis(pingIntervalMilliseconds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,36 @@ public class GitPropertiesVersionProviderTest {
static Stream<Arguments> variousPropertiesContents() {
return Stream.of(
Arguments.of(
"""
git.tags=v1.0
git.build.time=2024-01-01
git.commit.id.abbrev=abc123
""",
"git.tags=v1.0\n" +
"git.build.time=2024-01-01\n" +
"git.commit.id.abbrev=abc123\n",
"version v1.0 built on 2024-01-01"
),
Arguments.of(
"""
git.tags=
git.build.time=2024-01-01
git.commit.id.abbrev=abc123
""",
"git.tags=\n" +
"git.build.time=2024-01-01\n" +
"git.commit.id.abbrev=abc123\n",
"version abc123 built on 2024-01-01"
),
Arguments.of(
"""
git.tags=
git.build.time=2024-01-01
git.commit.id.abbrev=
""",
"git.tags=\n" +
"git.build.time=2024-01-01\n" +
"git.commit.id.abbrev=\n",
"version unknown built on 2024-01-01"
),
Arguments.of(
"""
git.tags=
git.build.time=
git.commit.id.abbrev=
""",
"git.tags=\n" +
"git.build.time=\n" +
"git.commit.id.abbrev=\n",
"version unknown"
),
Arguments.of(
"""
git.build.time=2024-01-01
git.commit.id.abbrev=abc123
""",
"git.build.time=2024-01-01\n" +
"git.commit.id.abbrev=abc123\n",
"version abc123 built on 2024-01-01"
),
Arguments.of(
"""
git.build.time=2024-01-01
""",
"git.build.time=2024-01-01\n",
"version unknown built on 2024-01-01"
),
Arguments.of(
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/org/voltdb/meshmonitor/e2e/ContainerTestBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Volt Active Data Inc.
* Copyright (C) 2024-2025 Volt Active Data Inc.
*
* Use of this source code is governed by an MIT
* license that can be found in the LICENSE file or at
Expand Down Expand Up @@ -35,13 +35,12 @@ public class ContainerTestBase {

private static final ImageFromDockerfile IMAGE_WITH_JAR = new ImageFromDockerfile()
.withFileFromFile("/home/meshmonitor", new File(".").getAbsoluteFile().getParentFile())
.withFileFromString("/home/meshmonitor/meshmonitor", """
#!/bin/bash

java --enable-preview \\
-cp "/home/meshmonitor/target/meshmonitor-1.0.0-jar-with-dependencies.jar" \\
org.voltdb.meshmonitor.cli.MeshMonitorCommand -i 1 "$@"
""")
.withFileFromString("/home/meshmonitor/meshmonitor",
"#!/bin/bash\n" +
"java \\\n" +
" -cp \"/home/meshmonitor/target/meshmonitor-1.0.0-jar-with-dependencies.jar\" \\\n" +
" org.voltdb.meshmonitor.cli.MeshMonitorCommand -i 1 \"$@\"\n"
)
.withDockerfileFromBuilder(builder ->
builder
.from("ghcr.io/graalvm/graalvm-community:21.0.1-ol9-20231024")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;

import static org.voltdb.meshmonitor.testutils.FileChannelUtils.byteBufferAbsolutePut;

public class ByteBufferReadableByteChannel implements ReadableByteChannel {

private final ByteBuffer data;
Expand All @@ -21,7 +23,8 @@ public class ByteBufferReadableByteChannel implements ReadableByteChannel {
@Override
public int read(ByteBuffer dst) {
int remaining = dst.remaining();
dst.put(dst.position(), data, data.position(), remaining);

byteBufferAbsolutePut(dst, dst.position(), data, data.position(), remaining);

dst.position(dst.position() + remaining);
data.position(data.position() + remaining);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;

import static org.voltdb.meshmonitor.testutils.FileChannelUtils.byteBufferAbsolutePut;

public class FakeWritableByteChannel implements WritableByteChannel {

private final boolean isSlow;
Expand All @@ -30,7 +32,7 @@ public int write(ByteBuffer src) {
toBeWritten = 1;
}

dataWritten.put(dataWritten.position(), src, src.position(), toBeWritten);
byteBufferAbsolutePut(dataWritten, dataWritten.position(), src, src.position(), toBeWritten);
dataWritten.position(dataWritten.position() + toBeWritten);
src.position(src.position() + toBeWritten);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,24 @@ public static FakeWritableByteChannel newWritableChannel(boolean isSlowConnectio
public static ByteBufferReadableByteChannel newReadableChannel(ByteBuffer data) {
return new ByteBufferReadableByteChannel(data);
}

/**
* It simulates put method that is available only since Java 16:
* <p>
* public ByteBuffer put(int index, ByteBuffer src, int offset, int length);
*/
public static void byteBufferAbsolutePut(ByteBuffer dst, int index, ByteBuffer src, int offset, int length) {
if ((index < 0) || (offset < 0) || (length < 0) ||
(index > dst.limit() - length) ||
(offset > src.limit() - length)) {
throw new IndexOutOfBoundsException(
String.format("dst.limit()=%d, index=%d, src.limit()=%d, offset=%d, length=%d",
dst.limit(), index, src.limit(), offset, length)
);
}

for (int i = offset, j = index; i < offset + length; i++, j++) {
dst.put(j, src.get(i));
}
}
}
Loading