Skip to content
New issue

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

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

Already on GitHub? # to your account

Highlight enums with String values correctly #1488

Merged
merged 5 commits into from
Jul 12, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CaseFormat;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import rocks.inspectit.ocelot.config.model.InspectitConfig;
import rocks.inspectit.ocelot.config.model.exporters.TransportProtocol;
import rocks.inspectit.ocelot.config.model.instrumentation.actions.GenericActionSettings;
import rocks.inspectit.ocelot.rest.AbstractBaseController;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@Slf4j
public class HighlightRulesMapController extends AbstractBaseController {

@VisibleForTesting
Expand Down Expand Up @@ -166,7 +166,7 @@ private void generateMapCollections(Map<String, Object> innerMap, Class<?> conte
* @return List of names of all possible values for the enum.
*/
private List<String> extractEnumValues(Class<?> currentEnum) {
return Arrays.stream(currentEnum.getFields()).map(Field::getName).collect(Collectors.toList());
return Arrays.stream(currentEnum.getEnumConstants()).map(Object::toString).collect(Collectors.toList());
}

@ApiOperation(value = "Get JSON for Highlight Rules Generation", notes = "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.junit.jupiter.api.Nested;
Expand All @@ -10,9 +11,11 @@
import org.springframework.http.ResponseEntity;
import rocks.inspectit.ocelot.IntegrationTestBase;
import rocks.inspectit.ocelot.config.model.InspectitConfig;
import rocks.inspectit.ocelot.config.model.exporters.TransportProtocol;
import rocks.inspectit.ocelot.config.model.instrumentation.actions.GenericActionSettings;
import rocks.inspectit.ocelot.config.model.instrumentation.data.PropagationMode;
import rocks.inspectit.ocelot.config.model.instrumentation.scope.AdvancedScopeSettings;
import springfox.documentation.spring.web.json.Json;

import java.util.List;
import java.util.Map;
Expand All @@ -27,14 +30,15 @@ public class HighlightRulesMapControllerIntTest extends IntegrationTestBase {
@Autowired
HighlightRulesMapController controller;

static JsonParser jsonParser = new JsonParser();

@Nested
public class GetHighlightingRulesMapTest {
@Test
void testGetHighlightingRulesMap() {

final String JSON = controller.generateMap(InspectitConfig.class).toString();
JsonParser jsonParser = new JsonParser();
Gson gson = new Gson();

final String JSON = gson.toJson(controller.generateMap(InspectitConfig.class));

// get expected JSON
JsonObject expected = jsonParser.parse(JSON).getAsJsonObject();
Expand All @@ -43,7 +47,8 @@ void testGetHighlightingRulesMap() {
ResponseEntity<Object> result = authRest.getForEntity("/api/v1/highlight-rules", Object.class);

// parse to JSON
JsonObject obj = jsonParser.parse(result.getBody().toString()).getAsJsonObject();
final String RESPONSE_JSON = gson.toJson(result.getBody());
JsonObject obj = jsonParser.parse(RESPONSE_JSON).getAsJsonObject();

// assert that the returned body is a JsonObject and that it equals the expected JSON
assertThat(obj.isJsonObject()).isTrue();
Expand Down Expand Up @@ -93,8 +98,11 @@ void withTestClass() throws JsonProcessingException {
String.format("\"advanced-scope-settings\":{\"%s\":\"%s\", \"%s\":%s},",
HighlightRulesMapController.KEY_TYPE, HighlightRulesMapController.VALUE_TYPE_OBJECT,
HighlightRulesMapController.KEY_OBJECT_ATTRIBUTES, advancedScopeSettingsExpected) +
String.format("\"a-boolean\":{\"%s\":\"%s\"}}",
HighlightRulesMapController.KEY_TYPE, HighlightRulesMapController.VALUE_TYPE_TEXT);
String.format("\"a-boolean\":{\"%s\":\"%s\"},",
HighlightRulesMapController.KEY_TYPE, HighlightRulesMapController.VALUE_TYPE_TEXT)+
String.format("\"protocol\":{\"%s\":\"%s\", \"%s\": [\"\", \"grpc\", \"http/thrift\", \"http/protobuf\"]}}",
HighlightRulesMapController.KEY_TYPE, HighlightRulesMapController.VALUE_TYPE_ENUM,
HighlightRulesMapController.KEY_ENUM_VALUES);

Map<String,Object> expected = new ObjectMapper().readValue(expectedJson, Map.class);

Expand Down Expand Up @@ -142,5 +150,7 @@ private static class TestClass{

Boolean aBoolean;

TransportProtocol protocol;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ inspectit:

# settings used in LoggingMetricsExporterService for the LoggingMetricExporter (https://github.com/open-telemetry/opentelemetry-java/tree/main/exporters/logging)
logging:
enabled: DISABLED
# the export interval of the metrics
export-interval: ${inspectit.metrics.frequency}
enabled: DISABLED
# the export interval of the metrics
export-interval: ${inspectit.metrics.frequency}

# settings for the OtlpGrpcMetricExporter used in OtlpGrpcMetricExporterService
otlp:
Expand All @@ -52,7 +52,7 @@ inspectit:
# the URL endpoint, e.g., http://127.0.0.1:4317
endpoint: null
# the transport protocol, e.g., 'grpc' or 'http/protobuf'
protocol: null
protocol:

# settings for trace exporters
tracing:
Expand All @@ -72,16 +72,16 @@ inspectit:
# the URL under which the jaeger thrift server can be accessed, e.g. http://127.0.0.1:14268/api/traces for http/thrift or http://127.0.0.1:14250/v1/traces for grpc
endpoint: null
# the transport protocol, e.g., 'http/thrift' or 'grpc'
protocol: null
protocol:

# settings used in LoggingTraceExporterService for the LoggingSpanExporter (https://github.com/open-telemetry/opentelemetry-java/tree/main/exporters/logging)
logging:
enabled: DISABLED
enabled: DISABLED

# settings for the OtlpGrpcSpanExporter/OtlpHttpSpanExporter used in OtlpTraceExporterService
otlp:
enabled: IF_CONFIGURED
# the URL endpoint, e.g., http://127.0.0.1:4318
endpoint: null
# the transport protocol, e.g., 'http/thrift' or 'grpc'
protocol: null
enabled: IF_CONFIGURED
# the URL endpoint, e.g., http://127.0.0.1:4318
endpoint: null
# the transport protocol, e.g., 'http/thrift' or 'grpc'
protocol: