Skip to content

Commit

Permalink
invalidate s3 cached reports on recording deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Aug 30, 2023
1 parent e5875de commit 057563a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@ class MemoryCachingReportsListener {

@ConsumeEvent(value = Recordings.ARCHIVED_RECORDING_DELETED)
public void handleArchivedRecordingDeletion(ArchivedRecording recording) {
if (!quarkusCache || !memoryCache) {
return;
}
// FIXME if the jvmId is not properly persisted with the recording metadata then we cannot
// clear the cache for that entry
String key =
ReportsService.key(
recording.metadata().labels().get("connectUrl"), recording.name());
ReportsService.key(recording.metadata().labels().get("jvmId"), recording.name());
logger.tracev("Picked up deletion of archived recording: {0}", key);
archivedCache.invalidate(key);
}

@ConsumeEvent(value = Recordings.ACTIVE_RECORDING_DELETED)
public void handleActiveRecordingDeletion(ActiveRecording recording) {
if (!quarkusCache || !memoryCache) {
return;
}
// TODO verify that target lost cascades and causes active recording deletion events that we
// observe here
String key = ReportsService.key(recording);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright The Cryostat Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cryostat.reports;

import java.util.Optional;

import io.cryostat.ConfigProperties;
import io.cryostat.recordings.Recordings;
import io.cryostat.recordings.Recordings.ArchivedRecording;

import io.quarkus.vertx.ConsumeEvent;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.logging.Logger;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
import software.amazon.awssdk.services.s3.model.S3Exception;

@ApplicationScoped
class StorageCachingReportsListener {

@ConfigProperty(name = ConfigProperties.STORAGE_CACHE_ENABLED)
boolean enabled;

@ConfigProperty(name = ConfigProperties.ARCHIVED_REPORTS_STORAGE_CACHE_NAME)
String bucket;

@Inject S3Client storage;

@Inject Logger logger;

@ConsumeEvent(value = Recordings.ARCHIVED_RECORDING_DELETED)
public void handleArchivedRecordingDeletion(ArchivedRecording recording) {
if (!enabled) {
return;
}
// FIXME if the jvmId is not properly persisted with the recording metadata then we cannot
// clear the cache for that entry
Optional.ofNullable(recording.metadata().labels().get("jvmId"))
.ifPresent(
jvmId -> {
var key = ReportsService.key(jvmId, recording.name());
logger.tracev("Picked up deletion of archived recording: {0}", key);
var req = DeleteObjectRequest.builder().bucket(bucket).key(key).build();
try {
storage.deleteObject(req);
} catch (S3Exception e) {
logger.warn(e);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.function.Predicate;

import org.openjdk.jmc.flightrecorder.rules.IRule;
Expand Down Expand Up @@ -62,7 +61,6 @@ class StorageCachingReportsService implements ReportsService {
String bucket;

@Inject S3Client storage;
@Inject ExecutorService worker;
@Inject ObjectMapper mapper;

@Inject @Delegate @Any ReportsService delegate;
Expand Down

0 comments on commit 057563a

Please sign in to comment.