Skip to content

Commit fd191fb

Browse files
author
Mark
committed
query tracking get/set, getCurrentlyRunningQueries
1 parent a009736 commit fd191fb

File tree

8 files changed

+371
-0
lines changed

8 files changed

+371
-0
lines changed

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

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import com.arangodb.entity.IndexEntity;
3939
import com.arangodb.entity.PathEntity;
4040
import com.arangodb.entity.QueryCachePropertiesEntity;
41+
import com.arangodb.entity.QueryEntity;
42+
import com.arangodb.entity.QueryTrackingPropertiesEntity;
4143
import com.arangodb.entity.TraversalEntity;
4244
import com.arangodb.internal.ArangoDBConstants;
4345
import com.arangodb.internal.CollectionCache;
@@ -620,6 +622,102 @@ private Request setQueryCachePropertiesRequest(final QueryCachePropertiesEntity
620622
.setBody(serialize(properties));
621623
}
622624

625+
/**
626+
* Returns the configuration for the AQL query tracking
627+
*
628+
* @see <a href=
629+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#returns-the-properties-for-the-aql-query-tracking">API
630+
* Documentation</a>
631+
* @return configuration for the AQL query tracking
632+
* @throws ArangoDBException
633+
*/
634+
public QueryTrackingPropertiesEntity getQueryTrackingProperties() throws ArangoDBException {
635+
return executeSync(getQueryTrackingPropertiesRequest(), QueryTrackingPropertiesEntity.class);
636+
}
637+
638+
/**
639+
* Returns the configuration for the AQL query tracking
640+
*
641+
* @see <a href=
642+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#returns-the-properties-for-the-aql-query-tracking">API
643+
* Documentation</a>
644+
* @return configuration for the AQL query tracking
645+
*/
646+
public CompletableFuture<QueryTrackingPropertiesEntity> getQueryTrackingPropertiesAsync() {
647+
return executeAsync(getQueryTrackingPropertiesRequest(), QueryTrackingPropertiesEntity.class);
648+
}
649+
650+
private Request getQueryTrackingPropertiesRequest() {
651+
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_QUERY_PROPERTIES);
652+
}
653+
654+
/**
655+
* Changes the configuration for the AQL query tracking
656+
*
657+
* @see <a href=
658+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#changes-the-properties-for-the-aql-query-tracking">API
659+
* Documentation</a>
660+
* @param properties
661+
* properties to be set
662+
* @return current set of properties
663+
* @throws ArangoDBException
664+
*/
665+
public QueryTrackingPropertiesEntity setQueryTrackingProperties(final QueryTrackingPropertiesEntity properties)
666+
throws ArangoDBException {
667+
return executeSync(setQueryTrackingPropertiesRequest(properties), QueryTrackingPropertiesEntity.class);
668+
}
669+
670+
/**
671+
* Changes the configuration for the AQL query tracking
672+
*
673+
* @see <a href=
674+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#changes-the-properties-for-the-aql-query-tracking">API
675+
* Documentation</a>
676+
* @param properties
677+
* properties to be set
678+
* @return current set of properties
679+
*/
680+
public CompletableFuture<QueryTrackingPropertiesEntity> setQueryTrackingPropertiesAsync(
681+
final QueryTrackingPropertiesEntity properties) {
682+
return executeAsync(setQueryTrackingPropertiesRequest(properties), QueryTrackingPropertiesEntity.class);
683+
}
684+
685+
private Request setQueryTrackingPropertiesRequest(final QueryTrackingPropertiesEntity properties) {
686+
return new Request(name, RequestType.PUT, ArangoDBConstants.PATH_API_QUERY_PROPERTIES)
687+
.setBody(serialize(properties));
688+
}
689+
690+
/**
691+
* Returns a list of currently running AQL queries
692+
*
693+
* @see <a href=
694+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#returns-the-currently-running-aql-queries">API
695+
* Documentation</a>
696+
* @return a list of currently running AQL queries
697+
* @throws ArangoDBException
698+
*/
699+
public Collection<QueryEntity> getCurrentlyRunningQueries() throws ArangoDBException {
700+
return executeSync(getCurrentlyRunningQueriesRequest(), new Type<Collection<QueryEntity>>() {
701+
}.getType());
702+
}
703+
704+
/**
705+
* Returns a list of currently running AQL queries
706+
*
707+
* @see <a href=
708+
* "https://docs.arangodb.com/current/HTTP/AqlQuery/index.html#returns-the-currently-running-aql-queries">API
709+
* Documentation</a>
710+
* @return a list of currently running AQL queries
711+
*/
712+
public CompletableFuture<Collection<QueryEntity>> getCurrentlyRunningQueriesAsync() {
713+
return executeAsync(getCurrentlyRunningQueriesRequest(), new Type<Collection<QueryEntity>>() {
714+
}.getType());
715+
}
716+
717+
private Request getCurrentlyRunningQueriesRequest() {
718+
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_QUERY_CURRENT);
719+
}
720+
623721
/**
624722
* Create a new AQL user function
625723
*

src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public QueryCachePropertiesEntity() {
4040
super();
4141
}
4242

43+
/**
44+
* @return the mode the AQL query cache operates in. The mode is one of the following values: off, on or demand
45+
*/
4346
public CacheMode getMode() {
4447
return mode;
4548
}
@@ -52,6 +55,9 @@ public void setMode(final CacheMode mode) {
5255
this.mode = mode;
5356
}
5457

58+
/**
59+
* @return the maximum number of query results that will be stored per database-specific cache
60+
*/
5561
public Long getMaxResults() {
5662
return maxResults;
5763
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
import java.util.Date;
24+
25+
/**
26+
* @author Mark - mark at arangodb.com
27+
*
28+
*/
29+
public class QueryEntity {
30+
31+
public static final String PROPERTY_STARTED = "started";
32+
33+
private String id;
34+
private String query;
35+
private Date started;
36+
private Double runTime;
37+
38+
public QueryEntity() {
39+
super();
40+
}
41+
42+
/**
43+
* @return the query's id
44+
*/
45+
public String getId() {
46+
return id;
47+
}
48+
49+
/**
50+
* @return the query string (potentially truncated)
51+
*/
52+
public String getQuery() {
53+
return query;
54+
}
55+
56+
/**
57+
* @return the date and time when the query was started
58+
*/
59+
public Date getStarted() {
60+
return started;
61+
}
62+
63+
/**
64+
*
65+
* @return the query's run time up to the point the list of queries was queried
66+
*/
67+
public Double getRunTime() {
68+
return runTime;
69+
}
70+
71+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.entity;
22+
23+
/**
24+
* @author Mark - mark at arangodb.com
25+
*
26+
*/
27+
public class QueryTrackingPropertiesEntity {
28+
29+
private Boolean enabled;
30+
private Boolean trackSlowQueries;
31+
private Long maxSlowQueries;
32+
private Long slowQueryThreshold;
33+
private Long maxQueryStringLength;
34+
35+
public QueryTrackingPropertiesEntity() {
36+
super();
37+
}
38+
39+
/**
40+
* @return If set to true, then queries will be tracked. If set to false, neither queries nor slow queries will be
41+
* tracked
42+
*/
43+
public Boolean getEnabled() {
44+
return enabled;
45+
}
46+
47+
/**
48+
* @param enabled
49+
* If set to true, then queries will be tracked. If set to false, neither queries nor slow queries will
50+
* be tracked
51+
*/
52+
public void setEnabled(final Boolean enabled) {
53+
this.enabled = enabled;
54+
}
55+
56+
/**
57+
* @return If set to true, then slow queries will be tracked in the list of slow queries if their runtime exceeds
58+
* the value set in slowQueryThreshold. In order for slow queries to be tracked, the enabled property must
59+
* also be set to true.
60+
*/
61+
public Boolean getTrackSlowQueries() {
62+
return trackSlowQueries;
63+
}
64+
65+
/**
66+
* @param trackSlowQueries
67+
* If set to true, then slow queries will be tracked in the list of slow queries if their runtime exceeds
68+
* the value set in slowQueryThreshold. In order for slow queries to be tracked, the enabled property
69+
* must also be set to true.
70+
*/
71+
public void setTrackSlowQueries(final Boolean trackSlowQueries) {
72+
this.trackSlowQueries = trackSlowQueries;
73+
}
74+
75+
/**
76+
* @return The maximum number of slow queries to keep in the list of slow queries. If the list of slow queries is
77+
* full, the oldest entry in it will be discarded when additional slow queries occur.
78+
*/
79+
public Long getMaxSlowQueries() {
80+
return maxSlowQueries;
81+
}
82+
83+
/**
84+
* @param maxSlowQueries
85+
* The maximum number of slow queries to keep in the list of slow queries. If the list of slow queries is
86+
* full, the oldest entry in it will be discarded when additional slow queries occur.
87+
*/
88+
public void setMaxSlowQueries(final Long maxSlowQueries) {
89+
this.maxSlowQueries = maxSlowQueries;
90+
}
91+
92+
/**
93+
* @return The threshold value for treating a query as slow. A query with a runtime greater or equal to this
94+
* threshold value will be put into the list of slow queries when slow query tracking is enabled. The value
95+
* for slowQueryThreshold is specified in seconds.
96+
*/
97+
public Long getSlowQueryThreshold() {
98+
return slowQueryThreshold;
99+
}
100+
101+
/**
102+
* @param slowQueryThreshold
103+
* The threshold value for treating a query as slow. A query with a runtime greater or equal to this
104+
* threshold value will be put into the list of slow queries when slow query tracking is enabled. The
105+
* value for slowQueryThreshold is specified in seconds.
106+
*/
107+
public void setSlowQueryThreshold(final Long slowQueryThreshold) {
108+
this.slowQueryThreshold = slowQueryThreshold;
109+
}
110+
111+
/**
112+
* @return The maximum query string length to keep in the list of queries. Query strings can have arbitrary lengths,
113+
* and this property can be used to save memory in case very long query strings are used. The value is
114+
* specified in bytes.
115+
*/
116+
public Long getMaxQueryStringLength() {
117+
return maxQueryStringLength;
118+
}
119+
120+
/**
121+
* @param maxQueryStringLength
122+
* The maximum query string length to keep in the list of queries. Query strings can have arbitrary
123+
* lengths, and this property can be used to save memory in case very long query strings are used. The
124+
* value is specified in bytes.
125+
*/
126+
public void setMaxQueryStringLength(final Long maxQueryStringLength) {
127+
this.maxQueryStringLength = maxQueryStringLength;
128+
}
129+
130+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class ArangoDBConstants {
4949
public static final String PATH_API_QUERY = "/_api/query";
5050
public static final String PATH_API_QUERY_CACHE = "/_api/query-cache";
5151
public static final String PATH_API_QUERY_CACHE_PROPERTIES = "/_api/query-cache/properties";
52+
public static final String PATH_API_QUERY_PROPERTIES = "/_api/query/properties";
53+
public static final String PATH_API_QUERY_CURRENT = "/_api/query/current";
5254
public static final String PATH_API_TRAVERSAL = "/_api/traversal";
5355

5456
public static final String ENCRYPTION_PLAIN = "plain";

src/main/java/com/arangodb/internal/velocypack/VPackConfigure.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020

2121
package com.arangodb.internal.velocypack;
2222

23+
import java.util.Date;
24+
2325
import org.json.simple.JSONValue;
2426

2527
import com.arangodb.entity.BaseDocument;
2628
import com.arangodb.entity.BaseEdgeDocument;
2729
import com.arangodb.entity.CollectionStatus;
2830
import com.arangodb.entity.CollectionType;
2931
import com.arangodb.entity.DocumentField;
32+
import com.arangodb.entity.QueryEntity;
3033
import com.arangodb.internal.CollectionCache;
3134
import com.arangodb.internal.velocystream.AuthenticationRequest;
3235
import com.arangodb.model.TraversalOptions;
@@ -99,6 +102,7 @@ public static void configure(
99102
builder.registerDeserializer(CollectionStatus.class, VPackDeserializers.COLLECTION_STATUS);
100103
builder.registerDeserializer(BaseDocument.class, VPackDeserializers.BASE_DOCUMENT);
101104
builder.registerDeserializer(BaseEdgeDocument.class, VPackDeserializers.BASE_EDGE_DOCUMENT);
105+
builder.registerDeserializer(QueryEntity.PROPERTY_STARTED, Date.class, VPackDeserializers.DATE_STRING);
102106
}
103107

104108
}

0 commit comments

Comments
 (0)