Skip to content

[DE-557] serverId query parameter for /_admin/log/level #498

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 2 commits 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 core/src/main/java/com/arangodb/ArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import com.arangodb.internal.ArangoDBImpl;
import com.arangodb.internal.InternalArangoDBBuilder;
import com.arangodb.internal.net.*;
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 javax.annotation.concurrent.ThreadSafe;
import java.util.Collection;
Expand Down Expand Up @@ -298,6 +295,14 @@ public interface ArangoDB extends ArangoSerdeAccessor {
*/
LogLevelEntity getLogLevel();

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

/**
* Modifies and returns the server's current loglevel settings.
*
Expand All @@ -307,6 +312,15 @@ public interface ArangoDB extends ArangoSerdeAccessor {
*/
LogLevelEntity setLogLevel(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
*/
LogLevelEntity setLogLevel(LogLevelEntity entity, LogLevelOptions options);

/**
* @return the list of available rules and their respective flags
* @since ArangoDB 3.10
Expand Down
19 changes: 13 additions & 6 deletions core/src/main/java/com/arangodb/internal/ArangoDBImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
import com.arangodb.internal.net.HostResolver;
import com.arangodb.internal.net.ProtocolProvider;
import com.arangodb.internal.serde.SerdeUtils;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -185,12 +182,22 @@ public LogEntriesEntity getLogEntries(final LogOptions options) {

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

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

@Override
public LogLevelEntity setLogLevel(final LogLevelEntity entity) {
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
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,14 @@ protected InternalRequest getLogEntriesRequest(final LogOptions options) {
.putQueryParam(LogOptions.PROPERTY_SORT, params.getSort());
}

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

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

Expand Down
14 changes: 14 additions & 0 deletions core/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 driver/src/test/java/com/arangodb/ArangoDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,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