Skip to content
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

feat(eventtemplates): add Preset event templates type and Quarkus-specific preset #733

Merged
merged 10 commits into from
Dec 19, 2024
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
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jfr</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand Down
58 changes: 57 additions & 1 deletion schema/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ components:
enum:
- TARGET
- CUSTOM
- PRESET
type: string
UUID:
format: uuid
Expand Down Expand Up @@ -1140,7 +1141,9 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/Template'
items:
$ref: '#/components/schemas/Template'
type: array
description: OK
"401":
description: Not Authorized
Expand Down Expand Up @@ -1193,6 +1196,59 @@ paths:
- SecurityScheme: []
tags:
- Event Templates
/api/v4/event_templates/{templateType}:
get:
parameters:
- in: path
name: templateType
required: true
schema:
type: string
responses:
"200":
content:
application/json:
schema:
items:
$ref: '#/components/schemas/Template'
type: array
description: OK
"401":
description: Not Authorized
"403":
description: Not Allowed
security:
- SecurityScheme: []
tags:
- Event Templates
/api/v4/event_templates/{templateType}/{templateName}:
get:
parameters:
- in: path
name: templateName
required: true
schema:
type: string
- in: path
name: templateType
required: true
schema:
type: string
responses:
"200":
content:
application/xml:
schema:
type: string
description: OK
"401":
description: Not Authorized
"403":
description: Not Allowed
security:
- SecurityScheme: []
tags:
- Event Templates
/api/v4/grafana/{encodedKey}:
post:
parameters:
Expand Down
1 change: 1 addition & 0 deletions src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ ENTRYPOINT [ "/deployments/app/entrypoint.bash", "/opt/jboss/container/java/run/

# We make distinct layers so if there are application changes the library layers can be re-used
COPY --chown=185 src/main/docker/include/cryostat.jfc /usr/lib/jvm/jre/lib/jfr/
COPY --chown=185 src/main/docker/include/template_presets/* /opt/cryostat.d/presets.d/
COPY --chown=185 src/main/docker/include/genpass.bash /deployments/app/
COPY --chown=185 src/main/docker/include/entrypoint.bash /deployments/app/
COPY --chown=185 src/main/docker/include/truststore-setup.bash /deployments/app/
Expand Down
12 changes: 12 additions & 0 deletions src/main/docker/include/template_presets/quarkus.jfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration version="2.0" label="Quarkus" description="Quarkus-specific REST events" provider="Cryostat">
<event name="quarkus.Rest">
<setting name="enabled">true</setting>
</event>
<event name="quarkus.RestStart">
<setting name="enabled">true</setting>
</event>
<event name="quarkus.RestEnd">
<setting name="enabled">true</setting>
</event>
</configuration>
3 changes: 2 additions & 1 deletion src/main/java/io/cryostat/ConfigProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class ConfigProperties {
"storage.transient-archives.enabled";
public static final String STORAGE_TRANSIENT_ARCHIVES_TTL = "storage.transient-archives.ttl";

public static final String TEMPLATES_DIR = "templates-dir";
public static final String CUSTOM_TEMPLATES_DIR = "templates-dir";
public static final String PRESET_TEMPLATES_DIR = "preset-templates-dir";
public static final String SSL_TRUSTSTORE_DIR = "ssl.truststore.dir";

public static final String URI_RANGE = "cryostat.target.uri-range";
Expand Down
44 changes: 37 additions & 7 deletions src/main/java/io/cryostat/events/EventTemplates.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.cryostat.core.FlightRecorderException;
import io.cryostat.core.templates.MutableTemplateService.InvalidXmlException;
import io.cryostat.core.templates.TemplateService;
import io.cryostat.libcryostat.sys.FileSystem;
import io.cryostat.libcryostat.templates.InvalidEventTemplateException;
import io.cryostat.libcryostat.templates.Template;
Expand All @@ -35,7 +36,9 @@
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import org.apache.commons.lang3.StringUtils;
import org.jboss.logging.Logger;
Expand All @@ -60,6 +63,7 @@ public class EventTemplates {
@Inject FileSystem fs;
@Inject TargetTemplateService.Factory targetTemplateServiceFactory;
@Inject S3TemplateService customTemplateService;
@Inject PresetTemplateService presetTemplateService;
@Inject Logger logger;

@GET
Expand All @@ -69,21 +73,47 @@ public List<Template> listTemplates() throws Exception {
var list = new ArrayList<Template>();
list.add(ALL_EVENTS_TEMPLATE);
list.addAll(customTemplateService.getTemplates());
list.addAll(presetTemplateService.getTemplates());
return list;
}

@GET
@Path("/{templateType}")
@Blocking
@RolesAllowed("read")
public Template getTemplate(@RestPath String templateName)
public List<Template> getTemplates(@RestPath String templateType)
throws IOException, FlightRecorderException {
if (StringUtils.isBlank(templateName)) {
throw new BadRequestException();
TemplateType tt = TemplateType.valueOf(templateType);
switch (tt) {
case CUSTOM:
return customTemplateService.getTemplates();
case PRESET:
return presetTemplateService.getTemplates();
default:
throw new BadRequestException();
}
}

@GET
@Path("/{templateType}/{templateName}")
@Blocking
@RolesAllowed("read")
@Produces(MediaType.APPLICATION_XML)
public String getTemplate(@RestPath String templateType, @RestPath String templateName)
throws IOException, FlightRecorderException {
TemplateType tt = TemplateType.valueOf(templateType);
TemplateService svc;
switch (tt) {
case CUSTOM:
svc = customTemplateService;
break;
case PRESET:
svc = presetTemplateService;
break;
default:
throw new BadRequestException();
}
return customTemplateService.getTemplates().stream()
.filter(t -> t.getName().equals(templateName))
.findFirst()
.orElseThrow();
return svc.getXml(templateName, tt).orElseThrow(() -> new NotFoundException());
}

@POST
Expand Down
Loading
Loading