Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi-Du committed Oct 25, 2023
1 parent 8cb1e45 commit 47a096a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.stargate.sgv2.jsonapi.exception;

//import io.quarkus.runtime.annotations.StaticInitSafe;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;


//@StaticInitSafe
@ConfigMapping(prefix = "stargate.haha")
public interface DebugModeConfig {

@WithDefault("false")
boolean enabled();
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.stargate.sgv2.jsonapi.exception;

import io.quarkus.logging.Log;
import io.smallrye.config.SmallRyeConfig;
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult;
import io.stargate.sgv2.jsonapi.exception.mappers.ThrowableToErrorMapper;
import jakarta.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.microprofile.config.ConfigProvider;

/**
* Our own {@link RuntimeException} that uses {@link ErrorCode} to describe the exception cause.
Expand All @@ -17,9 +18,6 @@
* directly.
*/
public class JsonApiException extends RuntimeException implements Supplier<CommandResult> {

private static final Logger LOGGER = LoggerFactory.getLogger(JsonApiException.class);

private final ErrorCode errorCode;

public JsonApiException(ErrorCode errorCode) {
Expand Down Expand Up @@ -64,7 +62,11 @@ public CommandResult get() {
public CommandResult.Error getCommandResultError(String message) {
Map<String, Object> fields = null;
// only have exceptionClass in debug mode
if (LOGGER.isDebugEnabled()) {
Log.error("??2");
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
DebugModeConfig debugModeConfig = config.getConfigMapping(DebugModeConfig.class);
final boolean debugEnabled = debugModeConfig.enabled();
if (debugEnabled) {
fields =
Map.of("errorCode", errorCode.name(), "exceptionClass", this.getClass().getSimpleName());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,42 @@

import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.quarkus.logging.Log;
import io.smallrye.config.SmallRyeConfig;
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult;
import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig;
import io.stargate.sgv2.jsonapi.exception.DebugModeConfig;
import io.stargate.sgv2.jsonapi.exception.JsonApiException;
import io.stargate.sgv2.jsonapi.service.embedding.configuration.PropertyBasedEmbeddingServiceConfig;
import jakarta.ws.rs.core.Response;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.microprofile.config.ConfigProvider;

/**
* Simple mapper for mapping {@link Throwable}s to {@link CommandResult.Error}, with a default
* implementation.
*/
public final class ThrowableToErrorMapper {
private static final Logger LOGGER = LoggerFactory.getLogger(ThrowableToErrorMapper.class);

private static final BiFunction<Throwable, String, CommandResult.Error> MAPPER_WITH_MESSAGE =
(throwable, message) -> {
final boolean debugEnabled = LOGGER.isDebugEnabled();
SmallRyeConfig c1 = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
PropertyBasedEmbeddingServiceConfig hah =
c1.getConfigMapping(PropertyBasedEmbeddingServiceConfig.class);
Log.error(hah.enabled());

SmallRyeConfig c2 = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
JsonApiMetricsConfig hah1 =
c2.getConfigMapping(JsonApiMetricsConfig.class);
Log.error(hah1.errorClass());
Log.error("??1");


SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
DebugModeConfig debugModeConfig = config.getConfigMapping(DebugModeConfig.class);
final boolean debugEnabled = debugModeConfig.enabled();
// if our own exception, shortcut
if (throwable instanceof JsonApiException jae) {
return jae.getCommandResultError(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
@ConfigMapping(prefix = "stargate.jsonapi.embedding.service")
public interface PropertyBasedEmbeddingServiceConfig {

@WithDefault("false")
boolean enabled();

@Nullable
OpenaiConfig openai();

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

stargate:

haha:
enabled: false

# disable all sgv2 exception mappers, handled differently
exception-mappers:
enabled: false
Expand Down Expand Up @@ -33,6 +36,7 @@ stargate:
# This can be `property` or `in-memory` to store Embedding service configuration
store: property
service:
enabled: true
# Open AI embedding service configuration
openai:
enabled: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public DseTestResource() {
}

// DEBUG mode for Integration Test
if (null == System.getProperty("quarkus.log.level")) {
System.setProperty("quarkus.log.level", "DEBUG");
if (null == System.getProperty("stargate.debug.enabled")) {
System.setProperty("stargate.debug.enabled", "true");
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ stargate:
data-store:
ignore-bridge: true

# DEBUG mode for unit tests
debug:
enabled: true

# change test port from 8081 (used by other SG services)
quarkus:
http:
test-port: 9080
log:
# DEBUG mode for unit tests
level: DEBUG
# log:
## DEBUG mode for unit tests
# level: DEBUG

0 comments on commit 47a096a

Please sign in to comment.