Skip to content

Commit 4960a47

Browse files
authored
fix(recordings): use safe recording close on cleanup (#763)
1 parent 7d5b8f5 commit 4960a47

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

compose/auth_proxy.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ services:
99
QUARKUS_HTTP_PROXY_ALLOW_X_FORWARDED: "true"
1010
QUARKUS_HTTP_PROXY_ENABLE_FORWARDED_HOST: "true"
1111
QUARKUS_HTTP_PROXY_ENABLE_FORWARDED_PREFIX: "true"
12-
QUARKUS_HTTP_ACCESS_LOG_PATTERN: long
13-
QUARKUS_HTTP_ACCESS_LOG_ENABLED: "true"
1412
auth:
1513
# the proxy does not actually depend on cryostat being up, but we use this
1614
# to ensure that when the smoketest tries to open the auth login page in a

compose/cryostat.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ services:
1515
hostname: cryostat
1616
user: "1000"
1717
environment:
18-
QUARKUS_LOG_LEVEL: ALL
18+
QUARKUS_LOG_LEVEL: ${CRYOSTAT_LOG_LEVEL:-INFO}
19+
QUARKUS_HTTP_ACCESS_LOG_ENABLED: "true"
20+
QUARKUS_HTTP_ACCESS_LOG_PATTERN: long
1921
QUARKUS_HTTP_HOST: "cryostat"
2022
QUARKUS_HTTP_PORT: ${CRYOSTAT_HTTP_PORT}
2123
QUARKUS_HIBERNATE_ORM_LOG_SQL: "true"

smoketest.bash

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ OPEN_TABS=${OPEN_TABS:-false}
1919

2020
PRECREATE_BUCKETS=${PRECREATE_BUCKETS:-archivedrecordings,archivedreports,eventtemplates,probes}
2121

22+
LOG_LEVEL=0
2223
CRYOSTAT_HTTP_HOST=${CRYOSTAT_HTTP_HOST:-cryostat}
2324
CRYOSTAT_HTTP_PORT=${CRYOSTAT_HTTP_PORT:-8080}
2425
USE_PROXY=${USE_PROXY:-true}
@@ -44,11 +45,12 @@ display_usage() {
4445
echo -e "\t-b\t\t\t\t\t\topen a Browser tab for each running service's first mapped port (ex. auth proxy login, database viewer)"
4546
echo -e "\t-n\t\t\t\t\t\tdo Not apply configuration changes, instead emit the compose YAML that would have been used to stdout."
4647
echo -e "\t-k\t\t\t\t\t\tdisable TLS on the auth proxy."
48+
echo -e "\t-v\t\t\t\t\t\tenable verbose logging. Can be passed multiple times to increase verbosity."
4749
}
4850

4951
s3=seaweed
5052
container_engine="$(command -v podman)"
51-
while getopts "hs:prGtAOVXc:bnk" opt; do
53+
while getopts "hs:prGtAOVXc:bnkv" opt; do
5254
case $opt in
5355
h)
5456
display_usage
@@ -97,6 +99,9 @@ while getopts "hs:prGtAOVXc:bnk" opt; do
9799
O)
98100
PULL_IMAGES=false
99101
;;
102+
v)
103+
LOG_LEVEL=$((LOG_LEVEL+1))
104+
;;
100105
V)
101106
KEEP_VOLUMES=true
102107
DATABASE_GENERATION=update
@@ -168,6 +173,16 @@ else
168173
fi
169174
GRAFANA_DASHBOARD_EXT_URL=http://grafana:3000/
170175
fi
176+
if [ $LOG_LEVEL = 0 ]; then
177+
CRYOSTAT_LOG_LEVEL=INFO
178+
elif [ $LOG_LEVEL = 1 ]; then
179+
CRYOSTAT_LOG_LEVEL=DEBUG
180+
elif [ $LOG_LEVEL = 2 ]; then
181+
CRYOSTAT_LOG_LEVEL=TRACE
182+
else
183+
CRYOSTAT_LOG_LEVEL=ALL
184+
fi
185+
export CRYOSTAT_LOG_LEVEL
171186
export CRYOSTAT_HTTP_HOST
172187
export CRYOSTAT_HTTP_PORT
173188
export GRAFANA_DASHBOARD_EXT_URL

src/main/java/io/cryostat/recordings/RecordingHelper.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@
136136
@ApplicationScoped
137137
public class RecordingHelper {
138138

139+
private static final int S3_API_PART_LIMIT = 10_000;
140+
private static final int MIB = 1024 * 1024;
141+
139142
public static final String JFR_MIME = HttpMimeType.JFR.mime();
140143

141144
private static final Pattern TEMPLATE_PATTERN =
@@ -473,7 +476,7 @@ public Uni<ActiveRecording> createSnapshot(Target target) {
473476
try (InputStream snapshot =
474477
remoteRecordingStreamFactory.open(connection, target, desc)) {
475478
if (!snapshotIsReadable(target, snapshot)) {
476-
connection.getService().close(desc);
479+
safeCloseRecording(connection, desc);
477480
throw new SnapshotCreationException(
478481
"Snapshot was not readable - are there any source recordings?");
479482
}
@@ -570,24 +573,20 @@ public Uni<ActiveRecording> stopRecording(ActiveRecording recording) throws Exce
570573
}
571574

572575
public Uni<ActiveRecording> deleteRecording(ActiveRecording recording) {
573-
var closed =
574-
connectionManager.executeConnectedTask(
575-
recording.target,
576-
conn -> {
577-
var desc = getDescriptorById(conn, recording.remoteId);
578-
if (desc.isEmpty()) {
579-
throw new NotFoundException();
580-
}
581-
conn.getService().close(desc.get());
582-
return recording;
583-
});
576+
connectionManager.executeConnectedTask(
577+
recording.target,
578+
conn -> {
579+
getDescriptorById(conn, recording.remoteId)
580+
.ifPresent(d -> safeCloseRecording(conn, d));
581+
return null;
582+
});
584583
return QuarkusTransaction.joiningExisting()
585584
.call(
586585
() -> {
587-
closed.target.activeRecordings.remove(recording);
588-
closed.target.persist();
589-
closed.delete();
590-
return Uni.createFrom().item(closed);
586+
recording.target.activeRecordings.remove(recording);
587+
recording.target.persist();
588+
recording.delete();
589+
return Uni.createFrom().item(recording);
591590
});
592591
}
593592

@@ -818,14 +817,13 @@ public ArchivedRecording archiveRecording(
818817
if (StringUtils.isBlank(savename)) {
819818
savename = filename;
820819
}
821-
int mib = 1024 * 1024;
822820
String key = archivedRecordingKey(recording.target.jvmId, filename);
823821
String multipartId = null;
824822
List<Pair<Integer, String>> parts = new ArrayList<>();
825823
long accum = 0;
826824
try (var stream = getActiveInputStream(recording);
827825
var ch = Channels.newChannel(stream)) {
828-
ByteBuffer buf = ByteBuffer.allocate(20 * mib);
826+
ByteBuffer buf = ByteBuffer.allocate(20 * MIB);
829827
CreateMultipartUploadRequest.Builder builder =
830828
CreateMultipartUploadRequest.builder()
831829
.bucket(archiveBucket)
@@ -840,7 +838,7 @@ public ArchivedRecording archiveRecording(
840838
CreateMultipartUploadRequest request = builder.build();
841839
multipartId = storage.createMultipartUpload(request).uploadId();
842840
int read = 0;
843-
for (int i = 1; i <= 10_000; i++) {
841+
for (int i = 1; i <= S3_API_PART_LIMIT; i++) {
844842
read = ch.read(buf);
845843

846844
if (read == 0) {
@@ -868,7 +866,7 @@ public ArchivedRecording archiveRecording(
868866
parts.add(Pair.of(i, eTag));
869867
buf.clear();
870868
// S3 API limit
871-
if (i == 10_000) {
869+
if (i == S3_API_PART_LIMIT) {
872870
throw new IndexOutOfBoundsException("Exceeded S3 maximum part count");
873871
}
874872
}

0 commit comments

Comments
 (0)