Skip to content

QueryEntity updates (v6) #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2023
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
39 changes: 35 additions & 4 deletions src/main/java/com/arangodb/entity/QueryEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ public class QueryEntity implements Entity {
public static final String PROPERTY_STARTED = "started";

private String id;
private String database;
private String user;
private String query;
private Map<String, Object> bindVars;
private Date started;
private Double runTime;
private Map<String, Object> bindVars;
private Long peakMemoryUsage;
private QueryExecutionState state;
private Boolean stream;

public QueryEntity() {
super();
Expand All @@ -48,13 +52,34 @@ public String getId() {
return id;
}

/**
* @return the name of the database the query runs in
*/
public String getDatabase() {
return database;
}

/**
* @return the name of the user that started the query
*/
public String getUser() {
return user;
}

/**
* @return the query string (potentially truncated)
*/
public String getQuery() {
return query;
}

/**
* @return the bind parameter values used by the query
*/
public Map<String, Object> getBindVars() {
return bindVars;
}

/**
* @return the date and time when the query was started
*/
Expand All @@ -70,10 +95,10 @@ public Double getRunTime() {
}

/**
* @return the bind parameter values used by the query
* @return the query’s peak memory usage in bytes (in increments of 32KB)
*/
public Map<String, Object> getBindVars() {
return bindVars;
public Long getPeakMemoryUsage() {
return peakMemoryUsage;
}

/**
Expand All @@ -83,4 +108,10 @@ public QueryExecutionState getState() {
return state;
}

/**
* @return whether or not the query uses a streaming cursor
*/
public Boolean getStream() {
return stream;
}
}
24 changes: 22 additions & 2 deletions src/test/java/com/arangodb/ArangoDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,17 @@ void getCurrentlyRunningQueries(ArangoDatabase db) throws InterruptedException {
final Collection<QueryEntity> currentlyRunningQueries = db.getCurrentlyRunningQueries();
assertThat(currentlyRunningQueries).hasSize(1);
final QueryEntity queryEntity = currentlyRunningQueries.iterator().next();
assertThat(queryEntity.getId()).isNotNull();
assertThat(queryEntity.getDatabase()).isEqualTo(db.name());
assertThat(queryEntity.getUser()).isEqualTo("root");
assertThat(queryEntity.getQuery()).isEqualTo(query);
assertThat(queryEntity.getBindVars()).isEmpty();
assertThat(queryEntity.getRunTime()).isPositive();
if(isAtLeastVersion(3,11)){
assertThat(queryEntity.getPeakMemoryUsage()).isNotNull();
}
assertThat(queryEntity.getState()).isEqualTo(QueryExecutionState.EXECUTING);
assertThat(queryEntity.getStream()).isFalse();
t.join();
}

Expand Down Expand Up @@ -1164,11 +1173,22 @@ void getAndClearSlowQueries(ArangoDatabase db) {
properties.setSlowQueryThreshold(1L);
db.setQueryTrackingProperties(properties);

db.query("return sleep(1.1)", null, null, Void.class);
String query = "return sleep(1.1)";
db.query(query, Void.class);
final Collection<QueryEntity> slowQueries = db.getSlowQueries();
assertThat(slowQueries).hasSize(1);
final QueryEntity queryEntity = slowQueries.iterator().next();
assertThat(queryEntity.getQuery()).isEqualTo("return sleep(1.1)");
assertThat(queryEntity.getId()).isNotNull();
assertThat(queryEntity.getDatabase()).isEqualTo(db.name());
assertThat(queryEntity.getUser()).isEqualTo("root");
assertThat(queryEntity.getQuery()).isEqualTo(query);
assertThat(queryEntity.getBindVars()).isEmpty();
assertThat(queryEntity.getRunTime()).isPositive();
if(isAtLeastVersion(3,11)){
assertThat(queryEntity.getPeakMemoryUsage()).isNotNull();
}
assertThat(queryEntity.getState()).isEqualTo(QueryExecutionState.FINISHED);
assertThat(queryEntity.getStream()).isFalse();

db.clearSlowQueries();
assertThat(db.getSlowQueries()).isEmpty();
Expand Down