Skip to content

Commit 0ee238d

Browse files
author
Mark
committed
get/clear slow queries
1 parent fd191fb commit 0ee238d

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

src/main/java/com/arangodb/ArangoDatabase.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,65 @@ private Request getCurrentlyRunningQueriesRequest() {
718718
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_QUERY_CURRENT);
719719
}
720720

721+
/**
722+
* Returns a list of slow running AQL queries
723+
*
724+
* @see <a href=
725+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#returns-the-list-of-slow-aql-queries">API
726+
* Documentation</a>
727+
* @return a list of slow running AQL queries
728+
* @throws ArangoDBException
729+
*/
730+
public Collection<QueryEntity> getSlowQueries() throws ArangoDBException {
731+
return executeSync(getSlowQueriesRequest(), new Type<Collection<QueryEntity>>() {
732+
}.getType());
733+
}
734+
735+
/**
736+
* Returns a list of slow running AQL queries
737+
*
738+
* @see <a href=
739+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#returns-the-list-of-slow-aql-queries">API
740+
* Documentation</a>
741+
* @return a list of slow running AQL queries
742+
*/
743+
public CompletableFuture<Collection<QueryEntity>> getSlowQueriesAsync() {
744+
return executeAsync(getSlowQueriesRequest(), new Type<Collection<QueryEntity>>() {
745+
}.getType());
746+
}
747+
748+
private Request getSlowQueriesRequest() {
749+
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_QUERY_SLOW);
750+
}
751+
752+
/**
753+
* Clears the list of slow AQL queries
754+
*
755+
* @see <a href=
756+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#clears-the-list-of-slow-aql-queries">API
757+
* Documentation</a>
758+
* @throws ArangoDBException
759+
*/
760+
public void clearSlowQueries() throws ArangoDBException {
761+
executeSync(clearSlowQueriesRequest(), Void.class);
762+
}
763+
764+
/**
765+
* Clears the list of slow AQL queries
766+
*
767+
* @see <a href=
768+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#clears-the-list-of-slow-aql-queries">API
769+
* Documentation</a>
770+
* @return void
771+
*/
772+
public CompletableFuture<Void> clearSlowQueriesAsync() {
773+
return executeAsync(clearSlowQueriesRequest(), Void.class);
774+
}
775+
776+
private Request clearSlowQueriesRequest() {
777+
return new Request(name, RequestType.DELETE, ArangoDBConstants.PATH_API_QUERY_SLOW);
778+
}
779+
721780
/**
722781
* Create a new AQL user function
723782
*

src/main/java/com/arangodb/internal/ArangoDBConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class ArangoDBConstants {
5151
public static final String PATH_API_QUERY_CACHE_PROPERTIES = "/_api/query-cache/properties";
5252
public static final String PATH_API_QUERY_PROPERTIES = "/_api/query/properties";
5353
public static final String PATH_API_QUERY_CURRENT = "/_api/query/current";
54+
public static final String PATH_API_QUERY_SLOW = "/_api/query/slow";
5455
public static final String PATH_API_TRAVERSAL = "/_api/traversal";
5556

5657
public static final String ENCRYPTION_PLAIN = "plain";

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,29 @@ public void getCurrentlyRunningQueries() throws InterruptedException, ExecutionE
587587
}
588588
}
589589

590+
@Test
591+
public void getAndClearSlowQueries() throws InterruptedException, ExecutionException {
592+
final QueryTrackingPropertiesEntity properties = db.getQueryTrackingProperties();
593+
final Long slowQueryThreshold = properties.getSlowQueryThreshold();
594+
try {
595+
properties.setSlowQueryThreshold(1L);
596+
db.setQueryTrackingProperties(properties);
597+
598+
db.query("return sleep(1.1)", null, null, Void.class);
599+
final Collection<QueryEntity> slowQueries = db.getSlowQueries();
600+
assertThat(slowQueries, is(notNullValue()));
601+
assertThat(slowQueries.size(), is(1));
602+
final QueryEntity queryEntity = slowQueries.stream().findFirst().get();
603+
assertThat(queryEntity.getQuery(), is("return sleep(1.1)"));
604+
605+
db.clearSlowQueries();
606+
assertThat(db.getSlowQueries().size(), is(0));
607+
} finally {
608+
properties.setSlowQueryThreshold(slowQueryThreshold);
609+
db.setQueryTrackingProperties(properties);
610+
}
611+
}
612+
590613
@Test
591614
public void createGetDeleteAqlFunction() {
592615
final Collection<AqlFunctionEntity> aqlFunctionsInitial = db.getAqlFunctions(null);

0 commit comments

Comments
 (0)