Skip to content

Commit

Permalink
feat(#615): JFR recording API
Browse files Browse the repository at this point in the history
  • Loading branch information
novoj committed Jul 19, 2024
1 parent 235fda7 commit b780de9
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
*/
String value();

/**
* Contains a human-readable name of the group.
*/
String name() default "";

/**
* Contains a description of the group.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public FileForFetch createFile(
"Failed to create file."
)
);
lock.lock();
try {
final FileForFetch fileForFetch = new FileForFetch(
fileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
/**
* This event is base class for all cache related events.
*/
@EventGroup(value = AbstractCacheEvent.PACKAGE_NAME, description = "evitaDB events relating to internal database cache.")
@EventGroup(
value = AbstractCacheEvent.PACKAGE_NAME,
name = "evitaDB - Cache",
description = "evitaDB events relating to internal database cache."
)
@Category({"evitaDB", "Cache"})
@RequiredArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
/**
* This event is base class for all query related events.
*/
@EventGroup(value = AbstractQueryEvent.PACKAGE_NAME, description = "evitaDB events relating to query processing.")
@EventGroup(
value = AbstractQueryEvent.PACKAGE_NAME,
name = "evitaDB - Query",
description = "evitaDB events relating to query processing."
)
@Category({"evitaDB", "Query"})
@RequiredArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
/**
* This event is base class for all session related events.
*/
@EventGroup(value = AbstractSessionEvent.PACKAGE_NAME, description = "evitaDB events relating to session handling.")
@EventGroup(
value = AbstractSessionEvent.PACKAGE_NAME,
name = "evitaDB - Session",
description = "evitaDB events relating to session handling."
)
@Category({"evitaDB", "Session"})
@RequiredArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
/**
* This event is base class for all transaction events.
*/
@EventGroup(value = AbstractStorageEvent.PACKAGE_NAME, description = "evitaDB events relating to data storage.")
@EventGroup(
value = AbstractStorageEvent.PACKAGE_NAME,
name = "evitaDB - Storage",
description = "evitaDB events relating to data storage."
)
@Category({"evitaDB", "Storage"})
@RequiredArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
/**
* This event is base class for all system related events.
*/
@EventGroup(value = AbstractSystemEvent.PACKAGE_NAME, description = "evitaDB events relating to system wide operations, such as tasks, threads etc.")
@EventGroup(
value = AbstractSystemEvent.PACKAGE_NAME,
name = "evitaDB - System",
description = "evitaDB events relating to system wide operations, such as tasks, threads etc."
)
@Category({"evitaDB", "System"})
@RequiredArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
/**
* This event is base class for all transaction events.
*/
@EventGroup(value = AbstractTransactionEvent.PACKAGE_NAME, description = "evitaDB events relating to transaction processing.")
@EventGroup(
value = AbstractTransactionEvent.PACKAGE_NAME,
name = "evitaDB - Transaction",
description = "evitaDB events relating to transaction processing."
)
@Category({"evitaDB", "Transaction"})
@RequiredArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
*
* @author Lukáš Hornych, FG Forrest a.s. (c) 2024
*/
@EventGroup(value = AbstractGraphQLInstanceEvent.PACKAGE_NAME, description = "evitaDB events relating to GraphQL API.")
@EventGroup(
value = AbstractGraphQLInstanceEvent.PACKAGE_NAME,
name = "evitaDB - GraphQL API",
description = "evitaDB events relating to GraphQL API."
)
@Category({"evitaDB", "API", "GraphQL", "Instance", "Schema"})
@RequiredArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
*
* @author Lukáš Hornych, FG Forrest a.s. (c) 2024
*/
@EventGroup(value = AbstractGraphQLRequestEvent.PACKAGE_NAME, description = "evitaDB events relating to GraphQL request processing.")
@EventGroup(
value = AbstractGraphQLRequestEvent.PACKAGE_NAME,
name = "evitaDB - GraphQL Request",
description = "evitaDB events relating to GraphQL request processing."
)
@Category({"evitaDB", "ExternalAPI", "GraphQL", "Request"})
@Getter
public class AbstractGraphQLRequestEvent extends CustomMetricsExecutionEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
/**
* This event is base class for all gRPC API related events.
*/
@EventGroup(value = AbstractGrpcApiEvent.PACKAGE_NAME, description = "evitaDB events relating to gRPC request processing.")
@EventGroup(
value = AbstractGrpcApiEvent.PACKAGE_NAME,
name = "evitaDB - gRPC Request",
description = "evitaDB events relating to gRPC request processing."
)
@Category({"evitaDB", "API", "gRPC"})
@RequiredArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package io.evitadb.externalApi.observability;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.linecorp.armeria.server.HttpService;
import com.linecorp.armeria.server.file.FileService;
import io.evitadb.api.exception.SingletonTaskAlreadyRunningException;
Expand All @@ -34,7 +35,6 @@
import io.evitadb.core.metric.event.CustomMetricsExecutionEvent;
import io.evitadb.exception.EvitaInvalidUsageException;
import io.evitadb.exception.UnexpectedIOException;
import io.evitadb.externalApi.configuration.ApiOptions;
import io.evitadb.externalApi.http.CorsEndpoint;
import io.evitadb.externalApi.http.ExternalApiProviderRegistrar;
import io.evitadb.externalApi.observability.agent.ErrorMonitor;
Expand Down Expand Up @@ -120,18 +120,14 @@ public class ObservabilityManager {
* Observability API config.
*/
private final ObservabilityConfig config;
/**
* API options part of the config.
*/
private final ApiOptions apiOptions;
/**
* Evita instance.
*/
private final Evita evita;
/**
* Common object mapper for endpoints
*/
@Nonnull @Getter private final ObjectMapper objectMapper = new ObjectMapper();
@Nonnull @Getter private final ObjectMapper objectMapper;

static {
ClassLoader classLoader = null;
Expand Down Expand Up @@ -174,13 +170,14 @@ public static void evitaErrorEvent(@Nonnull String simpleName) {
}
}

public ObservabilityManager(ObservabilityConfig config, ApiOptions apiOptions, Evita evita) {
public ObservabilityManager(ObservabilityConfig config, Evita evita) {
this.config = config;
this.apiOptions = apiOptions;
this.evita = evita;
createAndRegisterPrometheusServlet();
registerJfrControlEndpoints();
registerRecordingFileResourceHandler();
objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
}

/**
Expand Down Expand Up @@ -242,16 +239,16 @@ public void clearHealthProblem(@Nonnull String healthProblem) {
@Nonnull
public List<RecordingGroup> getAvailableJfrEventTypes() {
return Stream.concat(
EvitaJfrEventRegistry.getCustomEventPackages()
EvitaJfrEventRegistry.getEvitaEventGroups()
.values()
.stream()
.sorted(Comparator.comparing(EvitaEventGroup::name))
.map(it -> new RecordingGroup(it.name(), it.description())),
.map(it -> new RecordingGroup(it.id(), it.name(), it.description())),
EvitaJfrEventRegistry.getJdkEventGroups()
.values()
.stream()
.sorted(Comparator.comparing(JdkEventGroup::name))
.map(it -> new RecordingGroup(it.name(), it.description()))
.map(it -> new RecordingGroup(it.id(), it.name(), it.description()))
)
.toList();
}
Expand Down Expand Up @@ -393,6 +390,7 @@ private void registerJfrControlEndpoints() {
* @param description the description of the group
*/
public record RecordingGroup(
@Nonnull String id,
@Nonnull String name,
@Nullable String description
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public int getOrder() {
@Nonnull
@Override
public ExternalApiProvider<ObservabilityConfig> register(@Nonnull Evita evita, @Nonnull ExternalApiServer externalApiServer, @Nonnull ApiOptions apiOptions, @Nonnull ObservabilityConfig observabilityConfig) {
final ObservabilityManager observabilityManager = new ObservabilityManager(observabilityConfig, apiOptions, evita);
final ObservabilityManager observabilityManager = new ObservabilityManager(observabilityConfig, evita);
final TracingConfig tracingConfig = observabilityConfig.getTracing();
if (tracingConfig != null && tracingConfig.getEndpoint() != null) {
OpenTelemetryTracerSetup.setTracingConfig(observabilityConfig.getTracing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ protected void writeResponse(@Nonnull JfrRecordingEndpointExecutionContext execu
responseWriter.write(HttpData.ofUtf8(manager.getObjectMapper().writeValueAsString(result)));
} catch (JsonProcessingException e) {
throw new GenericEvitaInternalError(
"Failed to serialize available JFR event types",
"Failed to serialize response object to JSON.",
"Failed to serialize response object to JSON: " + e.getMessage(),

e
);
}
Expand Down
Loading

0 comments on commit b780de9

Please sign in to comment.