Skip to content

[DE-556] serverId query parameter for /_admin/log/level (v6) #499

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
Apr 25, 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
22 changes: 18 additions & 4 deletions src/main/java/com/arangodb/ArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
import com.arangodb.internal.util.DefaultArangoSerialization;
import com.arangodb.internal.velocystream.VstCommunicationSync;
import com.arangodb.internal.velocystream.VstConnectionFactorySync;
import com.arangodb.model.DBCreateOptions;
import com.arangodb.model.LogOptions;
import com.arangodb.model.UserCreateOptions;
import com.arangodb.model.UserUpdateOptions;
import com.arangodb.model.*;
import com.arangodb.util.*;
import com.arangodb.velocypack.VPack;
import com.arangodb.velocypack.VPackAnnotationFieldFilter;
Expand Down Expand Up @@ -1036,6 +1033,14 @@ default Boolean createDatabase(String name) throws ArangoDBException {
*/
LogLevelEntity getLogLevel() throws ArangoDBException;

/**
* Returns the server's current loglevel settings.
*
* @return the server's current loglevel settings
* @since ArangoDB 3.10
*/
LogLevelEntity getLogLevel(LogLevelOptions options) throws ArangoDBException;

/**
* Modifies and returns the server's current loglevel settings.
*
Expand All @@ -1046,6 +1051,15 @@ default Boolean createDatabase(String name) throws ArangoDBException {
*/
LogLevelEntity setLogLevel(LogLevelEntity entity) throws ArangoDBException;

/**
* Modifies and returns the server's current loglevel settings.
*
* @param entity loglevel settings
* @return the server's current loglevel settings
* @since ArangoDB 3.10
*/
LogLevelEntity setLogLevel(LogLevelEntity entity, LogLevelOptions options) throws ArangoDBException;

/**
* @return the list of available rules and their respective flags
* @throws ArangoDBException
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/com/arangodb/async/ArangoDBAsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
import com.arangodb.internal.util.DefaultArangoSerialization;
import com.arangodb.internal.velocystream.VstCommunicationSync;
import com.arangodb.internal.velocystream.VstConnectionFactorySync;
import com.arangodb.model.DBCreateOptions;
import com.arangodb.model.LogOptions;
import com.arangodb.model.UserCreateOptions;
import com.arangodb.model.UserUpdateOptions;
import com.arangodb.model.*;
import com.arangodb.util.ArangoDeserializer;
import com.arangodb.util.ArangoSerialization;
import com.arangodb.util.ArangoSerializer;
Expand Down Expand Up @@ -197,6 +194,16 @@ default CompletableFuture<Boolean> createDatabase(final String name) {
*/
CompletableFuture<ServerRole> getRole();

/**
* Returns the id of a server in a cluster.
*
* @return the server id
* @throws ArangoDBException
* @see <a href="https://www.arangodb.com/docs/stable/http/administration-and-monitoring.html#return-id-of-a-server-in-a-cluster">API
* Documentation</a>
*/
CompletableFuture<String> getServerId() throws ArangoDBException;

/**
* Create a new user. This user will not have access to any database. You need permission to the _system database in
* order to execute this call.
Expand Down Expand Up @@ -331,6 +338,14 @@ default CompletableFuture<Boolean> createDatabase(final String name) {
*/
CompletableFuture<LogLevelEntity> getLogLevel();

/**
* Returns the server's current loglevel settings.
*
* @return the server's current loglevel settings
* @since ArangoDB 3.10
*/
CompletableFuture<LogLevelEntity> getLogLevel(final LogLevelOptions options);

/**
* Modifies and returns the server's current loglevel settings.
*
Expand All @@ -339,6 +354,15 @@ default CompletableFuture<Boolean> createDatabase(final String name) {
*/
CompletableFuture<LogLevelEntity> setLogLevel(final LogLevelEntity entity);

/**
* Modifies and returns the server's current loglevel settings.
*
* @param entity loglevel settings
* @return the server's current loglevel settings
* @since ArangoDB 3.10
*/
CompletableFuture<LogLevelEntity> setLogLevel(final LogLevelEntity entity, final LogLevelOptions options);

/**
* @return the list of available rules and their respective flags
* @since ArangoDB 3.10
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
import com.arangodb.internal.velocystream.VstCommunicationSync;
import com.arangodb.internal.velocystream.VstProtocol;
import com.arangodb.internal.velocystream.internal.VstConnectionSync;
import com.arangodb.model.DBCreateOptions;
import com.arangodb.model.LogOptions;
import com.arangodb.model.UserCreateOptions;
import com.arangodb.model.UserUpdateOptions;
import com.arangodb.model.*;
import com.arangodb.velocypack.Type;
import com.arangodb.velocystream.Request;
import com.arangodb.velocystream.Response;
Expand Down Expand Up @@ -168,6 +165,11 @@ public CompletableFuture<ServerRole> getRole() {
return executor.execute(getRoleRequest(), getRoleResponseDeserializer());
}

@Override
public CompletableFuture<String> getServerId() {
return executor.execute(getServerIdRequest(), getServerIdResponseDeserializer());
}

@Override
public CompletableFuture<UserEntity> createUser(final String user, final String passwd) {
return executor.execute(createUserRequest(db().dbName(), user, passwd, new UserCreateOptions()),
Expand Down Expand Up @@ -234,12 +236,22 @@ public CompletableFuture<LogEntriesEntity> getLogEntries(final LogOptions option

@Override
public CompletableFuture<LogLevelEntity> getLogLevel() {
return executor.execute(getLogLevelRequest(), LogLevelEntity.class);
return getLogLevel(new LogLevelOptions());
}

@Override
public CompletableFuture<LogLevelEntity> getLogLevel(final LogLevelOptions options) {
return executor.execute(getLogLevelRequest(options), LogLevelEntity.class);
}

@Override
public CompletableFuture<LogLevelEntity> setLogLevel(final LogLevelEntity entity) {
return executor.execute(setLogLevelRequest(entity), LogLevelEntity.class);
return setLogLevel(entity, new LogLevelOptions());
}

@Override
public CompletableFuture<LogLevelEntity> setLogLevel(final LogLevelEntity entity, final LogLevelOptions options) {
return executor.execute(setLogLevelRequest(entity, options), LogLevelEntity.class);
}

@Override
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/arangodb/internal/ArangoDBImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
import com.arangodb.internal.util.ArangoSerializationFactory.Serializer;
import com.arangodb.internal.velocystream.VstCommunicationSync;
import com.arangodb.internal.velocystream.VstProtocol;
import com.arangodb.model.DBCreateOptions;
import com.arangodb.model.LogOptions;
import com.arangodb.model.UserCreateOptions;
import com.arangodb.model.UserUpdateOptions;
import com.arangodb.model.*;
import com.arangodb.util.ArangoCursorInitializer;
import com.arangodb.util.ArangoSerialization;
import com.arangodb.velocypack.Type;
Expand Down Expand Up @@ -262,12 +259,22 @@ public LogEntriesEntity getLogEntries(final LogOptions options) throws ArangoDBE

@Override
public LogLevelEntity getLogLevel() throws ArangoDBException {
return executor.execute(getLogLevelRequest(), LogLevelEntity.class);
return getLogLevel(new LogLevelOptions());
}

@Override
public LogLevelEntity getLogLevel(final LogLevelOptions options) throws ArangoDBException {
return executor.execute(getLogLevelRequest(options), LogLevelEntity.class);
}

@Override
public LogLevelEntity setLogLevel(final LogLevelEntity entity) throws ArangoDBException {
return executor.execute(setLogLevelRequest(entity), LogLevelEntity.class);
return setLogLevel(entity, new LogLevelOptions());
}

@Override
public LogLevelEntity setLogLevel(final LogLevelEntity entity, final LogLevelOptions options) {
return executor.execute(setLogLevelRequest(entity, options), LogLevelEntity.class);
}

@Override
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/arangodb/internal/InternalArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ protected Request getLogEntriesRequest(final LogOptions options) {
.putQueryParam(LogOptions.PROPERTY_SORT, params.getSort());
}

protected Request getLogLevelRequest() {
return request(DbName.SYSTEM, RequestType.GET, PATH_API_ADMIN_LOG_LEVEL);
protected Request getLogLevelRequest(final LogLevelOptions options) {
return request(DbName.SYSTEM, RequestType.GET, PATH_API_ADMIN_LOG_LEVEL)
.putQueryParam("serverId", options.getServerId());
}

protected Request setLogLevelRequest(final LogLevelEntity entity) {
protected Request setLogLevelRequest(final LogLevelEntity entity, final LogLevelOptions options) {
return request(DbName.SYSTEM, RequestType.PUT, PATH_API_ADMIN_LOG_LEVEL)
.putQueryParam("serverId", options.getServerId())
.setBody(util().serialize(entity));
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/arangodb/model/LogLevelOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.arangodb.model;

public class LogLevelOptions {
private String serverId;

public String getServerId() {
return serverId;
}

public LogLevelOptions serverId(final String serverId) {
this.serverId = serverId;
return this;
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/arangodb/ArangoDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,25 @@ void setAllLogLevel(ArangoDB arangoDB) {
}
}

@ParameterizedTest(name = "{index}")
@MethodSource("arangos")
void logLevelWithServerId(ArangoDB arangoDB) {
assumeTrue(isAtLeastVersion(3, 10));
assumeTrue(isCluster());
String serverId = arangoDB.getServerId();
LogLevelOptions options = new LogLevelOptions().serverId(serverId);
final LogLevelEntity entity = new LogLevelEntity();
try {
entity.setGraphs(LogLevelEntity.LogLevel.ERROR);
final LogLevelEntity logLevel = arangoDB.setLogLevel(entity, options);
assertThat(logLevel.getGraphs()).isEqualTo(LogLevelEntity.LogLevel.ERROR);
assertThat(arangoDB.getLogLevel(options).getGraphs()).isEqualTo(LogLevelEntity.LogLevel.ERROR);
} finally {
entity.setGraphs(LogLevelEntity.LogLevel.INFO);
arangoDB.setLogLevel(entity);
}
}

@ParameterizedTest(name = "{index}")
@MethodSource("arangos")
void getQueryOptimizerRules(ArangoDB arangoDB) {
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/arangodb/async/ArangoDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,24 @@ void setLogLevel() throws InterruptedException, ExecutionException {
}
}

@Test
void logLevelWithServerId() throws InterruptedException, ExecutionException {
assumeTrue(isAtLeastVersion(3, 10));
assumeTrue(isCluster());
String serverId = arangoDB.getServerId().get();
LogLevelOptions options = new LogLevelOptions().serverId(serverId);
final LogLevelEntity entity = new LogLevelEntity();
try {
entity.setGraphs(LogLevelEntity.LogLevel.ERROR);
final LogLevelEntity logLevel = arangoDB.setLogLevel(entity, options).get();
assertThat(logLevel.getGraphs()).isEqualTo(LogLevelEntity.LogLevel.ERROR);
assertThat(arangoDB.getLogLevel(options).get().getGraphs()).isEqualTo(LogLevelEntity.LogLevel.ERROR);
} finally {
entity.setGraphs(LogLevelEntity.LogLevel.INFO);
arangoDB.setLogLevel(entity);
}
}

@Test
void queueTime() throws InterruptedException, ExecutionException {
List<CompletableFuture<ArangoCursorAsync<Void>>> reqs = IntStream.range(0, 80)
Expand Down