ARTEMIS-2699 Warn if queue stats are limited by default maxRows

Print a warning if the queues are greater than the max rows value.
This commit is contained in:
brusdev 2020-04-06 19:37:28 +02:00 committed by Clebert Suconic
parent ee29b4be10
commit 68e493029b
2 changed files with 94 additions and 6 deletions

View File

@ -54,6 +54,8 @@ public class StatQueue extends AbstractAction {
CONTAINS, EQUALS, GREATER_THAN, LESS_THAN
}
public static final int DEFAULT_MAX_ROWS = 50;
@Option(name = "--queueName", description = "display queue stats for queue(s) with names containing this string.")
private String queueName;
@ -67,7 +69,7 @@ public class StatQueue extends AbstractAction {
private String value;
@Option(name = "--maxRows", description = "max number of queues displayed. Default is 50.")
private int maxRows = 50;
private int maxRows = DEFAULT_MAX_ROWS;
//easier for testing
public StatQueue setQueueName(String queueName) {
@ -114,11 +116,11 @@ public class StatQueue extends AbstractAction {
context.out.println("filter is '" + filter + "'");
context.out.println("maxRows='" + maxRows + "'");
}
printStats(context, filter, maxRows);
printStats(context, filter);
return null;
}
private void printStats(final ActionContext context, final String filter, int maxRows) throws Exception {
private void printStats(final ActionContext context, final String filter) throws Exception {
performCoreManagement(new ManagementCallback<ClientMessage>() {
@Override
public void setUpInvocation(ClientMessage message) throws Exception {
@ -151,11 +153,16 @@ public class StatQueue extends AbstractAction {
}
JsonObject queuesAsJsonObject = JsonUtil.readJsonObject(result);
JsonArray array = (JsonArray) queuesAsJsonObject.get("data");
int count = queuesAsJsonObject.getInt("count");
JsonArray array = queuesAsJsonObject.getJsonArray("data");
for (int i = 0; i < array.size(); i++) {
printQueueStats(array.getJsonObject(i));
}
if (count > maxRows) {
context.out.println(String.format("WARNING: the displayed queues are %d/%d, set maxRows to display more queues.", maxRows, count));
}
}
private void printHeadings() {

View File

@ -1243,8 +1243,8 @@ public class ArtemisTest extends CliTestBase {
statQueue.setMaxRows(1);
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 1 queue only
Assert.assertEquals("rows returned by maxRows=1", 2, lines.size());
// Header line + 1 queue only + warning line
Assert.assertEquals("rows returned by maxRows=1", 3, lines.size());
} finally {
stopServer();
@ -1355,6 +1355,87 @@ public class ArtemisTest extends CliTestBase {
}
@Test
public void testQstatWarnings() throws Exception {
File instanceQstat = new File(temporaryFolder.getRoot(), "instanceQStat");
setupAuth(instanceQstat);
Run.setEmbedded(true);
Artemis.main("create", instanceQstat.getAbsolutePath(), "--silent", "--no-fsync", "--no-autotune", "--no-web", "--require-login");
System.setProperty("artemis.instance", instanceQstat.getAbsolutePath());
Artemis.internalExecute("run");
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = cf.createConnection("admin", "admin");) {
TestActionContext context;
StatQueue statQueue;
ArrayList<String> lines;
//set up some queues with messages and consumers
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
for (int i = 0; i < StatQueue.DEFAULT_MAX_ROWS; i++) {
sendMessages(session, "Test" + i, 1);
}
//check all queues containing "Test" are displayed
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("Test");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + DEFAULT_MAX_ROWS queues + warning line
Assert.assertEquals("rows returned using queueName=Test", 1 + StatQueue.DEFAULT_MAX_ROWS, lines.size());
Assert.assertFalse(lines.get(lines.size() - 1).startsWith("WARNING"));
//check all queues containing "Test" are displayed
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("Test");
statQueue.setMaxRows(StatQueue.DEFAULT_MAX_ROWS);
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + DEFAULT_MAX_ROWS queues
Assert.assertEquals("rows returned using queueName=Test", 1 + StatQueue.DEFAULT_MAX_ROWS, lines.size());
Assert.assertFalse(lines.get(lines.size() - 1).startsWith("WARNING"));
sendMessages(session, "Test" + StatQueue.DEFAULT_MAX_ROWS, 1);
//check all queues containing "Test" are displayed
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("Test");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + DEFAULT_MAX_ROWS queues + warning line
Assert.assertEquals("rows returned using queueName=Test", 1 + StatQueue.DEFAULT_MAX_ROWS + 1, lines.size());
Assert.assertTrue(lines.get(lines.size() - 1).startsWith("WARNING"));
//check all queues containing "Test" are displayed
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("Test");
statQueue.setMaxRows(StatQueue.DEFAULT_MAX_ROWS);
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + DEFAULT_MAX_ROWS queues + warning line
Assert.assertEquals("rows returned using queueName=Test", 1 + StatQueue.DEFAULT_MAX_ROWS + 1, lines.size());
Assert.assertTrue(lines.get(lines.size() - 1).startsWith("WARNING"));
} finally {
stopServer();
}
}
//read individual lines from byteStream
public static ArrayList<String> getOutputLines(TestActionContext context, boolean errorOutput) throws IOException {
byte[] bytes;