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(automated-rules): implement automated rules #34

Merged
merged 21 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 20 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ truststore/
certs/*.p12
certs/*.pass
*.jfr
.quarkus/
34 changes: 34 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<io.cryostat.core.version>2.21.0</io.cryostat.core.version>

<org.apache.commons.codec.version>1.15</org.apache.commons.codec.version>
<org.apache.commons.io.version>2.11.0</org.apache.commons.io.version>
<org.apache.httpcomponents.version>4.5.14</org.apache.httpcomponents.version>
<org.apache.commons.lang3.version>3.12.0</org.apache.commons.lang3.version>
<org.apache.commons.validator.version>1.7</org.apache.commons.validator.version>
<org.projectnessie.cel.bom.version>0.3.21</org.projectnessie.cel.bom.version>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.1.1.Final</quarkus.platform.version>
Expand Down Expand Up @@ -63,6 +65,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.projectnessie.cel</groupId>
<artifactId>cel-bom</artifactId>
<version>${org.projectnessie.cel.bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -112,6 +121,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
Expand Down Expand Up @@ -144,6 +157,14 @@
<artifactId>httpclient</artifactId>
<version>${org.apache.httpcomponents.version}</version>
</dependency>
<dependency>
<groupId>org.projectnessie.cel</groupId>
<artifactId>cel-tools</artifactId>
</dependency>
<dependency>
<groupId>org.projectnessie.cel</groupId>
<artifactId>cel-jackson</artifactId>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
Expand All @@ -153,6 +174,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-quartz</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
Expand All @@ -170,6 +199,11 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions smoketest/compose/sample-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
depends_on:
cryostat:
condition: service_healthy
image: quay.io/andrewazores/vertx-fib-demo:0.12.3
image: quay.io/andrewazores/vertx-fib-demo:0.13.0
hostname: vertx-fib-demo-1
environment:
HTTP_PORT: 8081
Expand Down Expand Up @@ -32,7 +32,7 @@ services:
start_period: 10s
timeout: 5s
quarkus-test-agent:
image: quay.io/andrewazores/quarkus-test:0.0.11
image: quay.io/andrewazores/quarkus-test:latest
# do not add a depends_on:cryostat here, so that we can test that the agent is tolerant of that state
hostname: quarkus-test-agent
ports:
Expand Down
2 changes: 1 addition & 1 deletion smoketest/k8s/quarkus-test-agent-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spec:
value: "false"
- name: QUARKUS_HTTP_PORT
value: "10010"
image: quay.io/andrewazores/quarkus-test:0.0.11
image: quay.io/andrewazores/quarkus-test:latest
livenessProbe:
exec:
command:
Expand Down
2 changes: 1 addition & 1 deletion smoketest/k8s/sample-app-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
value: "8081"
- name: JMX_PORT
value: "9093"
image: quay.io/andrewazores/vertx-fib-demo:0.12.3
image: quay.io/andrewazores/vertx-fib-demo:0.13.0
livenessProbe:
exec:
command:
Expand Down
2 changes: 1 addition & 1 deletion smoketest/k8s/smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ while [ "$#" -ne 0 ]; do
fi
;;
*)
echo "Usage: $0 [clean|generate]"
echo "Usage: $0 [clean|generate|apply|kind|unkind|forward]"
exit 1
;;
esac
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/io/cryostat/ConfigProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright The Cryostat Authors
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or data
* (collectively the "Software"), free of charge and under any and all copyright
* rights in the Software, and any and all patent rights owned or freely
* licensable by each licensor hereunder covering either (i) the unmodified
* Software as contributed to or provided by such licensor, or (ii) the Larger
* Works (as defined below), to deal in both
*
* (a) the Software, and
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software (each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
* The above copyright notice and either this complete permission notice or at
* a minimum a reference to the UPL must be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.cryostat;

public class ConfigProperties {
public static final String AWS_BUCKET_NAME_ARCHIVES = "storage.buckets.archives.name";
}
5 changes: 5 additions & 0 deletions src/main/java/io/cryostat/ExceptionMappers.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ public RestResponse<Void> mapNoResultException(NoResultException ex) {
public RestResponse<Void> mapNoResultException(ConstraintViolationException ex) {
return RestResponse.status(HttpResponseStatus.BAD_REQUEST.code());
}

@ServerExceptionMapper
public RestResponse<Void> mapValidationException(jakarta.validation.ValidationException ex) {
return RestResponse.status(HttpResponseStatus.BAD_REQUEST.code());
}
}
9 changes: 9 additions & 0 deletions src/main/java/io/cryostat/Producers.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.projectnessie.cel.tools.ScriptHost;
import org.projectnessie.cel.types.jackson.JacksonRegistry;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Configuration;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
Expand Down Expand Up @@ -98,4 +100,11 @@ public static S3Presigner produceS3Presigner(

return builder.build();
}

@Produces
@ApplicationScoped
@DefaultBean
public static ScriptHost provideScriptHost() {
return ScriptHost.newBuilder().registry(JacksonRegistry.newRegistry()).build();
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/cryostat/V2Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
package io.cryostat;

public record V2Response(Meta meta, Data data) {
public static V2Response json(Object payload) {
return new V2Response(new Meta("application/json", "OK"), new Data(payload));
public static V2Response json(Object payload, String status) {
return new V2Response(new Meta("application/json", status), new Data(payload));
}

public record Meta(String type, String status) {}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/cryostat/credentials/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.jboss.resteasy.reactive.RestPath;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.RestResponse.ResponseBuilder;
import org.jboss.resteasy.reactive.RestResponse.Status;

@Path("/api/v2.2/credentials")
public class Credentials {
Expand All @@ -62,15 +63,16 @@ public class Credentials {
@RolesAllowed("read")
public V2Response list() {
List<Credential> credentials = Credential.listAll();
return V2Response.json(credentials.stream().map(Credentials::safeResult).toList());
return V2Response.json(
credentials.stream().map(Credentials::safeResult).toList(), Status.OK.toString());
}

@GET
@RolesAllowed("read")
@Path("/{id}")
public V2Response get(@RestPath long id) {
Credential credential = Credential.find("id", id).singleResult();
return V2Response.json(safeMatchedResult(credential));
return V2Response.json(safeMatchedResult(credential), Status.OK.toString());
}

@Transactional
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/cryostat/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.jboss.resteasy.reactive.RestPath;
import org.jboss.resteasy.reactive.RestQuery;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.RestResponse.Status;

@Path("")
public class Events {
Expand All @@ -85,7 +86,8 @@ public Response listEventsV1(@RestPath URI connectUrl, @RestQuery String q) thro
@Path("/api/v2/targets/{connectUrl}/events")
@RolesAllowed("read")
public V2Response listEventsV2(@RestPath URI connectUrl, @RestQuery String q) throws Exception {
return V2Response.json(searchEvents(Target.getTargetByConnectUrl(connectUrl), q));
return V2Response.json(
searchEvents(Target.getTargetByConnectUrl(connectUrl), q), Status.OK.toString());
}

@GET
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/io/cryostat/recordings/ActiveRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,30 @@
import jakarta.persistence.PostUpdate;
import jakarta.persistence.PreRemove;
import jakarta.persistence.PreUpdate;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jdk.jfr.RecordingState;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;
import org.jboss.logging.Logger;

@Entity
@EntityListeners(ActiveRecording.Listener.class)
@Table(
uniqueConstraints = {
@UniqueConstraint(columnNames = {"target_id", "name"}),
@UniqueConstraint(columnNames = {"target_id", "remoteId"})
})
public class ActiveRecording extends PanacheEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_id")
private Target target;

public long remoteId;
@Column(nullable = false)
public String name;

public long remoteId;
public RecordingState state;
public long duration;
public long startTime;
Expand Down Expand Up @@ -151,10 +160,21 @@ public static ActiveRecording getByName(String name) {
return find("name", name).singleResult();
}

// Default implementation of delete is bulk so does not trigger lifecycle events
public static boolean deleteByName(String name) {
return delete("name", name) > 0;
}

public static boolean deleteFromTarget(Target target, String name) {
ActiveRecording recordingToDelete =
find("target = ?1 and name = ?2", target, name).firstResult();
if (recordingToDelete != null) {
recordingToDelete.delete();
return true;
}
return false; // Recording not found or already deleted.
}

public LinkedRecordingDescriptor toExternalForm() {
return new LinkedRecordingDescriptor(
this.remoteId,
Expand Down Expand Up @@ -189,7 +209,7 @@ public void preUpdate(ActiveRecording activeRecording) throws Exception {
connectionManager.executeConnectedTask(
activeRecording.target,
conn -> {
Recordings.getDescriptorById(conn, activeRecording.remoteId)
RecordingHelper.getDescriptorById(conn, activeRecording.remoteId)
.ifPresent(
d -> {
try {
Expand Down Expand Up @@ -219,7 +239,7 @@ public void preRemove(ActiveRecording activeRecording) throws Exception {
connectionManager.executeConnectedTask(
activeRecording.target,
conn -> {
Recordings.getDescriptor(conn, activeRecording)
RecordingHelper.getDescriptor(conn, activeRecording)
.ifPresent(rec -> Recordings.safeCloseRecording(conn, rec, logger));
return null;
});
Expand Down
Loading