From b63329f53ee2c2277cac73d3ba345dcbfc6f1ca4 Mon Sep 17 00:00:00 2001 From: Shubham Srivastava Date: Fri, 15 May 2026 07:04:18 +0530 Subject: [PATCH] fix(pricing): bundle snapshot resources into native image (#836) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(pricing): bundle snapshot resources into native image The bundled pricing-snapshots tree was missing from the GraalVM native-image build, so the standard Floci container (which ships the native binary) had no service codes available — the Pricing snapshot loader silently returned null because the JSON files weren't present at runtime. Two changes: 1. Register `pricing-snapshots/**` under `quarkus.native.resources.includes` so GraalVM bundles every snapshot file into the image. Quarkus's static analysis cannot detect resource paths constructed dynamically (the loader joins `pricing-snapshots/` with a per-call relative path), so an explicit include is required. 2. Read snapshot resources via the class's own `ClassLoader` rather than the thread context loader. In a native image the thread context loader can be the bootstrap loader, which sees no application resources, while the class's loader sees everything bundled into the image. Reported by @cfranzen against #821 — Pricing service returned no service codes when called via Testcontainers and `load()` produced no log output, indicating the snapshot files were absent rather than malformed. Refs: https://github.com/floci-io/floci/pull/821#issuecomment-4445052790 * ci: retrigger after sdk-test-node flake on apigatewayv2 websocket disconnect --- .../floci/services/pricing/PricingService.java | 9 ++++++++- src/main/resources/application.yml | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/hectorvent/floci/services/pricing/PricingService.java b/src/main/java/io/github/hectorvent/floci/services/pricing/PricingService.java index 26c9bd1f34..482cea9513 100644 --- a/src/main/java/io/github/hectorvent/floci/services/pricing/PricingService.java +++ b/src/main/java/io/github/hectorvent/floci/services/pricing/PricingService.java @@ -492,7 +492,14 @@ public class PricingService { } } String resource = "pricing-snapshots/" + relativePath; - try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { + // Use the class's own loader rather than the thread's context loader. + // In a GraalVM native image the thread context loader can be the + // bootstrap loader, which sees no application resources, while the + // class's loader sees everything bundled into the image. + ClassLoader cl = PricingService.class.getClassLoader(); + try (InputStream in = cl != null + ? cl.getResourceAsStream(resource) + : ClassLoader.getSystemResourceAsStream(resource)) { if (in == null) { return null; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b621b92bc1..db8cd6c039 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,6 +20,12 @@ quarkus: # No 'delay' value is set - observers run synchronously, no artificial sleep is introduced. delay-enabled: true native: + resources: + # The Pricing service reads its bundled snapshot at runtime via + # ClassLoader#getResourceAsStream. Quarkus's static resource analysis + # cannot detect dynamically-built paths, so the tree is registered + # explicitly to ensure GraalVM includes every file in the native image. + includes: pricing-snapshots/** additional-build-args: - --report-unsupported-elements-at-runtime - --allow-incomplete-classpath