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

fix(ws): implement periodic ping frame #460

Merged
merged 3 commits into from
May 14, 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
23 changes: 0 additions & 23 deletions src/main/java/io/cryostat/Producers.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
package io.cryostat;

import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ScheduledExecutorService;

import io.cryostat.core.reports.InterruptibleReportGenerator;
import io.cryostat.core.sys.Clock;
Expand All @@ -32,7 +30,6 @@
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
import org.apache.commons.codec.binary.Base32;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.projectnessie.cel.tools.ScriptHost;
Expand Down Expand Up @@ -60,12 +57,6 @@ public static FileSystem produceFileSystem() {
return new FileSystem();
}

@Produces
@ApplicationScoped
public static Base32 produceBase32() {
return new Base32();
}

@Produces
@ApplicationScoped
@DefaultBean
Expand All @@ -74,20 +65,6 @@ public static Base64 produceBase64Url() {
return new Base64(0, null, true);
}

@Produces
@ApplicationScoped
@DefaultBean
public static ExecutorService produceExecutorService() {
return ForkJoinPool.commonPool();
}

@Produces
@ApplicationScoped
@DefaultBean
public static ScheduledExecutorService produceScheduledExecutorService() {
return Executors.newSingleThreadScheduledExecutor();
}

@Produces
// RequestScoped so that each individual report generation request has its own interruptible
// generator with an independent task queueing thread which dispatches to the shared common pool
Expand Down
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 @@ -66,7 +65,6 @@ class StorageCachingReportsService implements ReportsService {
Duration expiry;

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

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/io/cryostat/ws/MessagingServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package io.cryostat.ws;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.scheduler.Scheduled;
import io.quarkus.vertx.ConsumeEvent;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand All @@ -38,6 +41,8 @@
public class MessagingServer {

private static final String CLIENT_ACTIVITY_CATEGORY = "WsClientActivity";
private static final ByteBuffer PING_MSG =
ByteBuffer.wrap("ping".getBytes(StandardCharsets.UTF_8));

@Inject ObjectMapper mapper;
@Inject Logger logger;
Expand Down Expand Up @@ -106,4 +111,16 @@ void broadcast(Notification notification) {
}
}));
}

@Scheduled(every = "${cryostat.websocket.ping-period:20s}")
void pingClients() {
sessions.forEach(
session -> {
try {
session.getBasicRemote().sendPing(PING_MSG);
} catch (IOException e) {
logger.debug(e);
}
});
}
}
Loading