Skip to content

Commit

Permalink
Add log
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Oct 24, 2024
1 parent 8ddb628 commit a0e980a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties
/sample/dev.sh
/sample/maas.sh
2 changes: 1 addition & 1 deletion deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<name>Quarkus Chappie - Deployment</name>

<properties>
<chappie-server.version>0.0.13</chappie-server.version>
<chappie-server.version>999-SNAPSHOT</chappie-server.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,43 @@
import io.quarkus.deployment.annotations.BuildSteps;
import io.quarkus.deployment.builditem.DevServicesResultBuildItem;
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.devui.spi.buildtime.FooterLogBuildItem;
import io.quarkus.runtime.util.ClassPathUtils;
import io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor;

@BuildSteps(onlyIf = { IsDevelopment.class, GlobalDevServicesConfig.Enabled.class })
public class ChappieDevServiceProcessor {
private static Process process;
private static ChappieClient chappieClient;
private static final Logger LOG = Logger.getLogger("Quarkus Assistant");
private static final Logger LOG = Logger.getLogger(ChappieDevServiceProcessor.class);

@BuildStep
public void createContainer(BuildProducer<DevServicesResultBuildItem> devServicesResultProducer,
BuildProducer<ChappieClientBuildItem> chappieClientProducer,
BuildProducer<FooterLogBuildItem> footerLogProducer,
ExtensionVersionBuildItem extensionVersionBuildItem,
Optional<OllamaBuildItem> ollamaBuildItem,
ChappieConfig config) {

if (process == null && (config.openai().apiKey().isPresent() || config.openai().baseUrl().isPresent()
|| ollamaBuildItem.isPresent())) {

BroadcastProcessor<String> logProcessor = BroadcastProcessor.create();

// Dev UI Log stream
footerLogProducer.produce(new FooterLogBuildItem("Assistant", () -> {
return logProcessor.convert().toPublisher();
}));

Map<String, String> properties = new HashMap<>();
int port = findAvailablePort(4315);

String jsonRpcBase = "http://localhost:" + port;

properties.put("quarkus.http.host", "localhost");
properties.put("quarkus.http.port", String.valueOf(port));

if (config.devservices().log()) {
properties.put("chappie.log.request", "true");
properties.put("chappie.log.response", "true");
}
properties.put("chappie.log.request", "true");
properties.put("chappie.log.response", "true");

properties.put("chappie.timeout", config.devservices().timeout());
if (config.openai().apiKey().isPresent() || config.openai().baseUrl().isPresent()) {
Expand All @@ -82,7 +89,7 @@ public void createContainer(BuildProducer<DevServicesResultBuildItem> devService
}

try {
runServer(extVersion, properties, config.devservices().log());
runServer(extVersion, properties, logProcessor);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (process != null && process.isAlive()) {
process.destroy();
Expand Down Expand Up @@ -207,7 +214,8 @@ private Path getChappieBaseDir(String version) {
return Path.of(userHome, ".chappie/" + version);
}

private void runServer(String version, Map<String, String> properties, boolean log) throws IOException {
private void runServer(String version, Map<String, String> properties, BroadcastProcessor<String> logProcessor)
throws IOException {
Path chappieServer = getChappieServer(version);

List<String> command = new ArrayList<>();
Expand All @@ -223,21 +231,15 @@ private void runServer(String version, Map<String, String> properties, boolean l

process = processBuilder.start();

new Thread(() -> handleStream(process.getInputStream(), "OUTPUT", log)).start();
new Thread(() -> handleStream(process.getErrorStream(), "ERROR", log)).start();
new Thread(() -> handleStream(process.getInputStream(), logProcessor)).start();
new Thread(() -> handleStream(process.getErrorStream(), logProcessor)).start();
}

private void handleStream(java.io.InputStream inputStream, String type, boolean log) {
private void handleStream(java.io.InputStream inputStream, BroadcastProcessor<String> logProcessor) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = reader.readLine()) != null) {
if (type.equals("ERROR")) {
LOG.error(line);
} else if (log) {
LOG.info(line);
} else {
LOG.debug(line);
}
logProcessor.onNext(line);
}
} catch (IOException e) {
LOG.error("Error in Quarkus Assistant", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
@ConfigGroup
public interface DevServicesConfig {

/**
* Show the log of the dev service in the application log
*/
@WithDefault("false")
boolean log();

/**
* The default port where the inference server listens for requests
*/
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.14.2</quarkus.version>
<quarkus.version>3.16.0.CR1</quarkus.version>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit a0e980a

Please sign in to comment.