diff --git a/release.version b/release.version index 9435145c..34b31707 100644 --- a/release.version +++ b/release.version @@ -1 +1 @@ -1.0.87 +1.0.91 diff --git a/runtime/src/main/java/com/fnproject/fn/runtime/MethodFunctionInvoker.java b/runtime/src/main/java/com/fnproject/fn/runtime/MethodFunctionInvoker.java index 0f46d749..04192a37 100644 --- a/runtime/src/main/java/com/fnproject/fn/runtime/MethodFunctionInvoker.java +++ b/runtime/src/main/java/com/fnproject/fn/runtime/MethodFunctionInvoker.java @@ -17,6 +17,26 @@ */ public class MethodFunctionInvoker implements FunctionInvoker { + /* + * If enabled, print the logging framing content + */ + public void logFramer(FunctionRuntimeContext rctx, InputEvent evt) { + String framer = rctx.getConfigurationByKey("FN_LOGFRAME_NAME").orElse(""); + + if (framer != "") { + String valueSrc = rctx.getConfigurationByKey("FN_LOGFRAME_HDR").orElse(""); + + if (valueSrc != "") { + String id = evt.getHeaders().get(valueSrc).orElse(""); + if (id != "") { + System.out.println("\n" + framer + "=" + id + "\n"); + System.err.println("\n" + framer + "=" + id + "\n"); + } + } + } + } + + /** * Invoke the function wrapped by this loader * @@ -33,6 +53,8 @@ public Optional tryInvoke(InvocationContext ctx, InputEvent evt) th Object rawResult; + logFramer(runtimeContext, evt); + try { rawResult = method.getTargetMethod().invoke(ctx.getRuntimeContext().getInvokeInstance().orElse(null), userFunctionParams); } catch (IllegalAccessException | InvocationTargetException e) { diff --git a/runtime/src/test/java/com/fnproject/fn/runtime/EndToEndInvokeTest.java b/runtime/src/test/java/com/fnproject/fn/runtime/EndToEndInvokeTest.java index 4be57f20..a028c368 100644 --- a/runtime/src/test/java/com/fnproject/fn/runtime/EndToEndInvokeTest.java +++ b/runtime/src/test/java/com/fnproject/fn/runtime/EndToEndInvokeTest.java @@ -211,6 +211,19 @@ public void shouldReadBytesOnDefaultCodec() throws Exception { } + @Test + public void shouldPrintLogFrame() throws Exception { + fn.setConfig("FN_LOGFRAME_NAME", "containerID"); + fn.setConfig("FN_LOGFRAME_HDR", "fnID"); + fn.givenEvent().withHeader("fnID", "fnIDVal").withBody( "Hello world!").enqueue(); + + fn.thenRun(TestFn.class, "fnEcho"); + assertThat(fn.getOnlyOutputAsString()).isEqualTo("Hello world!"); + // stdout gets redirected to stderr - hence printing out twice + assertThat(fn.getStdErrAsString()).isEqualTo("\ncontainerID=fnIDVal\n\n\ncontainerID=fnIDVal\n\n"); + + } + @Test public void shouldWriteBytesOnDefaultCodec() throws Exception {