From c7f46270e4b4366d1909d64eeeb5eea1961dc5ae Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 22 Jan 2024 09:33:36 +0100 Subject: [PATCH 001/167] POC --- .../internal/stream/HttpServerFactory.java | 102 ++++++++++++++++++ .../main/resources/META-INF/zilla/http.idl | 73 +++++++++++++ 2 files changed, 175 insertions(+) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 76cfa97c84..f499a314eb 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -44,6 +44,7 @@ import static java.util.Arrays.asList; import java.net.URI; +import java.nio.ByteBuffer; import java.time.Instant; import java.util.ArrayList; import java.util.EnumMap; @@ -117,6 +118,7 @@ import io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW; import io.aklivity.zilla.runtime.binding.http.internal.types.String16FW; import io.aklivity.zilla.runtime.binding.http.internal.types.String8FW; +import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.Capability; @@ -1024,11 +1026,39 @@ else if (limit > endOfMethodLimit) if (isCorsPreflightRequest(headers)) { + HttpEventFW event = server.httpEventRW + .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) + .corsPreflightRequestNotAllowed(e -> e + .originId(server.originId) + .routedId(server.routedId) + .initialId(server.initialId) + .replyId(server.replyId) + .affinity(server.affinity) + .authorization(authorization) + .budgetId(budgetId) + .traceId(traceId) + ) + .build(); + System.out.println(event); // TODO: Ati server.onDecodeCorsPreflight(traceId, authorization, headers); server.decoder = decodeEmptyLines; } else if (!isCorsRequestAllowed(server.binding, headers)) { + HttpEventFW event = server.httpEventRW + .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) + .corsRequestNotAllowed(e -> e + .originId(server.originId) + .routedId(server.routedId) + .initialId(server.initialId) + .replyId(server.replyId) + .affinity(server.affinity) + .authorization(authorization) + .budgetId(budgetId) + .traceId(traceId) + ) + .build(); + System.out.println(event); // TODO: Ati server.onDecodeHeadersError(traceId, authorization, response403); server.decoder = decodeIgnore; } @@ -1057,12 +1087,63 @@ else if (!isCorsRequestAllowed(server.binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); + if (exchangeAuth == 0) + { + HttpEventFW event = server.httpEventRW + .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) + .guardAuthorizationFailure(e -> e + .originId(server.originId) + .routedId(server.routedId) + .initialId(server.initialId) + .replyId(server.replyId) + .affinity(server.affinity) + .authorization(authorization) + .budgetId(budgetId) + .traceId(traceId) + ) + .build(); + System.out.println(event); // TODO: Ati + } + else + { + HttpEventFW event = server.httpEventRW + .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) + .guardAuthorizationSuccess(e -> e + .originId(server.originId) + .routedId(server.routedId) + .initialId(server.initialId) + .replyId(server.replyId) + .affinity(server.affinity) + .authorization(authorization) + .budgetId(budgetId) + .traceId(traceId) + ) + .build(); + System.out.println(event); // TODO: Ati + } } } HttpRouteConfig route = binding.resolve(exchangeAuth, headers::get); if (route != null) { + if (guard != null) + { + HttpEventFW event = server.httpEventRW + .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) + .routeFound(e -> e + .originId(server.originId) + .routedId(server.routedId) + .initialId(server.initialId) + .replyId(server.replyId) + .affinity(server.affinity) + .authorization(authorization) + .budgetId(budgetId) + .traceId(traceId) + ) + .build(); + System.out.println(event); // TODO: Ati + } if (binding.options != null && binding.options.overrides != null) { binding.options.overrides.forEach((k, v) -> headers.put(k.asString(), v.asString())); @@ -1086,6 +1167,23 @@ else if (!isCorsRequestAllowed(server.binding, headers)) } else { + if (guard != null) + { + HttpEventFW event = server.httpEventRW + .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) + .routeNotFound(e -> e + .originId(server.originId) + .routedId(server.routedId) + .initialId(server.initialId) + .replyId(server.replyId) + .affinity(server.affinity) + .authorization(authorization) + .budgetId(budgetId) + .traceId(traceId) + ) + .build(); + System.out.println(event); // TODO: Ati + } error = response404; } } @@ -1584,6 +1682,8 @@ private final class HttpServer private long replyBudgetId; private int replyMax; private HttpRequestType requestType; + private final HttpEventFW.Builder httpEventRW; + private final MutableDirectBuffer eventBuffer; private HttpServer( HttpBindingConfig binding, @@ -1610,6 +1710,8 @@ private HttpServer( this.delegateNetwork = this::onNetwork; this.guard = resolveGuard(binding); this.credentials = binding.credentials(); + this.httpEventRW = new HttpEventFW.Builder(); + this.eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(1024)); // TODO: Ati } private int replyPendingAck() diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 20887c8bdd..d4a854309e 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -49,4 +49,77 @@ scope http HttpHeader[] headers; } } + + scope event + { + enum HttpEventType (uint8) + { + CORS_PREFLIGHT_REQUEST_NOT_ALLOWED (1), + CORS_REQUEST_NOT_ALLOWED (2), + GUARD_AUTHORIZATION_FAILURE (3), + GUARD_AUTHORIZATION_SUCCESS (4), + ROUTE_NOT_FOUND (5), + ROUTE_FOUND (6) + } + + enum Level + { + INFO, + WARNING, + ERROR + } + + struct HttpEventCommon + { + int64 timestamp = 0; + int64 originId; + int64 routedId; + int64 initialId; + int64 replyId; + int64 affinity; + int64 authorization = 0; + int64 budgetId; + int64 traceId; + } + + struct HttpEventCorsPreflightRequestNotAllowed extends HttpEventCommon + { + Level level = WARNING; + } + + struct HttpEventCorsRequestNotAllowed extends HttpEventCommon + { + Level level = WARNING; + } + + struct HttpEventGuardAuthorizationFailure extends HttpEventCommon + { + Level level = WARNING; + } + + struct HttpEventGuardAuthorizationSuccess extends HttpEventCommon + { + Level level = INFO; + } + + struct HttpEventRouteNotFound extends HttpEventCommon + { + Level level = WARNING; + } + + struct HttpEventRouteFound extends HttpEventCommon + { + Level level = INFO; + } + + union HttpEvent switch (HttpEventType) + { + case CORS_PREFLIGHT_REQUEST_NOT_ALLOWED: HttpEventCorsPreflightRequestNotAllowed corsPreflightRequestNotAllowed; + case CORS_REQUEST_NOT_ALLOWED: HttpEventCorsRequestNotAllowed corsRequestNotAllowed; + case GUARD_AUTHORIZATION_FAILURE: HttpEventGuardAuthorizationFailure guardAuthorizationFailure; + case GUARD_AUTHORIZATION_SUCCESS: HttpEventGuardAuthorizationSuccess guardAuthorizationSuccess; + case ROUTE_NOT_FOUND: HttpEventRouteNotFound routeNotFound; + case ROUTE_FOUND: HttpEventRouteFound routeFound; + } + } } From 1a7592ff7984e2d875e10aa74b03b14150a6189e Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 23 Jan 2024 10:18:27 +0100 Subject: [PATCH 002/167] fix --- .../internal/stream/HttpServerFactory.java | 98 +++---------------- .../main/resources/META-INF/zilla/http.idl | 57 +++-------- 2 files changed, 28 insertions(+), 127 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index f499a314eb..1365a233aa 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -119,6 +119,8 @@ import io.aklivity.zilla.runtime.binding.http.internal.types.String16FW; import io.aklivity.zilla.runtime.binding.http.internal.types.String8FW; import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; +import io.aklivity.zilla.runtime.binding.http.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.Capability; @@ -943,6 +945,7 @@ private void doChallenge( receiver.accept(challenge.typeId(), challenge.buffer(), challenge.offset(), challenge.sizeof()); } + @SuppressWarnings("checkstyle:methodlength") // TODO: Ati private int decodeHeaders( HttpServer server, long traceId, @@ -1026,20 +1029,6 @@ else if (limit > endOfMethodLimit) if (isCorsPreflightRequest(headers)) { - HttpEventFW event = server.httpEventRW - .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) - .corsPreflightRequestNotAllowed(e -> e - .originId(server.originId) - .routedId(server.routedId) - .initialId(server.initialId) - .replyId(server.replyId) - .affinity(server.affinity) - .authorization(authorization) - .budgetId(budgetId) - .traceId(traceId) - ) - .build(); - System.out.println(event); // TODO: Ati server.onDecodeCorsPreflight(traceId, authorization, headers); server.decoder = decodeEmptyLines; } @@ -1047,14 +1036,13 @@ else if (!isCorsRequestAllowed(server.binding, headers)) { HttpEventFW event = server.httpEventRW .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) - .corsRequestNotAllowed(e -> e + .accessControl(e -> e + .result(r -> r.set(Result.FAILURE)) + .level(l -> l.set(Level.WARNING)) .originId(server.originId) .routedId(server.routedId) .initialId(server.initialId) .replyId(server.replyId) - .affinity(server.affinity) - .authorization(authorization) - .budgetId(budgetId) .traceId(traceId) ) .build(); @@ -1087,63 +1075,26 @@ else if (!isCorsRequestAllowed(server.binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); - if (exchangeAuth == 0) - { - HttpEventFW event = server.httpEventRW - .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) - .guardAuthorizationFailure(e -> e - .originId(server.originId) - .routedId(server.routedId) - .initialId(server.initialId) - .replyId(server.replyId) - .affinity(server.affinity) - .authorization(authorization) - .budgetId(budgetId) - .traceId(traceId) - ) - .build(); - System.out.println(event); // TODO: Ati - } - else - { - HttpEventFW event = server.httpEventRW - .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) - .guardAuthorizationSuccess(e -> e - .originId(server.originId) - .routedId(server.routedId) - .initialId(server.initialId) - .replyId(server.replyId) - .affinity(server.affinity) - .authorization(authorization) - .budgetId(budgetId) - .traceId(traceId) - ) - .build(); - System.out.println(event); // TODO: Ati - } - } - } - - HttpRouteConfig route = binding.resolve(exchangeAuth, headers::get); - if (route != null) - { - if (guard != null) - { + long exchangeAuth0 = exchangeAuth; HttpEventFW event = server.httpEventRW .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) - .routeFound(e -> e + .authorization(e -> e + .result(r -> r.set(exchangeAuth0 == 0 ? Result.FAILURE : Result.SUCCESS)) + .level(l -> l.set(exchangeAuth0 == 0 ? Level.WARNING : Level.INFO)) .originId(server.originId) .routedId(server.routedId) .initialId(server.initialId) .replyId(server.replyId) - .affinity(server.affinity) - .authorization(authorization) - .budgetId(budgetId) .traceId(traceId) ) .build(); - System.out.println(event); // TODO: Ati + System.out.println(event); // TODO: Ati } + } + + HttpRouteConfig route = binding.resolve(exchangeAuth, headers::get); + if (route != null) + { if (binding.options != null && binding.options.overrides != null) { binding.options.overrides.forEach((k, v) -> headers.put(k.asString(), v.asString())); @@ -1167,23 +1118,6 @@ else if (!isCorsRequestAllowed(server.binding, headers)) } else { - if (guard != null) - { - HttpEventFW event = server.httpEventRW - .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) - .routeNotFound(e -> e - .originId(server.originId) - .routedId(server.routedId) - .initialId(server.initialId) - .replyId(server.replyId) - .affinity(server.affinity) - .authorization(authorization) - .budgetId(budgetId) - .traceId(traceId) - ) - .build(); - System.out.println(event); // TODO: Ati - } error = response404; } } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index d4a854309e..6a88e0bc67 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -54,12 +54,14 @@ scope http { enum HttpEventType (uint8) { - CORS_PREFLIGHT_REQUEST_NOT_ALLOWED (1), - CORS_REQUEST_NOT_ALLOWED (2), - GUARD_AUTHORIZATION_FAILURE (3), - GUARD_AUTHORIZATION_SUCCESS (4), - ROUTE_NOT_FOUND (5), - ROUTE_FOUND (6) + ACCESS_CONTROL (1), + AUTHORIZATION (2) + } + + enum Result + { + SUCCESS, + FAILURE } enum Level @@ -71,55 +73,20 @@ scope http struct HttpEventCommon { + Result result; + Level level; int64 timestamp = 0; int64 originId; int64 routedId; int64 initialId; int64 replyId; - int64 affinity; - int64 authorization = 0; - int64 budgetId; int64 traceId; } - struct HttpEventCorsPreflightRequestNotAllowed extends HttpEventCommon - { - Level level = WARNING; - } - - struct HttpEventCorsRequestNotAllowed extends HttpEventCommon - { - Level level = WARNING; - } - - struct HttpEventGuardAuthorizationFailure extends HttpEventCommon - { - Level level = WARNING; - } - - struct HttpEventGuardAuthorizationSuccess extends HttpEventCommon - { - Level level = INFO; - } - - struct HttpEventRouteNotFound extends HttpEventCommon - { - Level level = WARNING; - } - - struct HttpEventRouteFound extends HttpEventCommon - { - Level level = INFO; - } - union HttpEvent switch (HttpEventType) { - case CORS_PREFLIGHT_REQUEST_NOT_ALLOWED: HttpEventCorsPreflightRequestNotAllowed corsPreflightRequestNotAllowed; - case CORS_REQUEST_NOT_ALLOWED: HttpEventCorsRequestNotAllowed corsRequestNotAllowed; - case GUARD_AUTHORIZATION_FAILURE: HttpEventGuardAuthorizationFailure guardAuthorizationFailure; - case GUARD_AUTHORIZATION_SUCCESS: HttpEventGuardAuthorizationSuccess guardAuthorizationSuccess; - case ROUTE_NOT_FOUND: HttpEventRouteNotFound routeNotFound; - case ROUTE_FOUND: HttpEventRouteFound routeFound; + case ACCESS_CONTROL: HttpEventCommon accessControl; + case AUTHORIZATION: HttpEventCommon authorization; } } } From 3609baae7dd71c68881a65a7091bbf4a2beced45 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 23 Jan 2024 11:34:41 +0100 Subject: [PATCH 003/167] WIP HttpEventContext --- .../http/internal/HttpEventContext.java | 88 +++++++++++++++++++ .../internal/stream/HttpServerFactory.java | 43 ++------- 2 files changed, 97 insertions(+), 34 deletions(-) create mode 100644 runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java new file mode 100644 index 0000000000..561a818f37 --- /dev/null +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -0,0 +1,88 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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.aklivity.zilla.runtime.binding.http.internal; + +import java.nio.ByteBuffer; + +import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; + +import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; +import io.aklivity.zilla.runtime.binding.http.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; +import io.aklivity.zilla.runtime.engine.EngineContext; + +public class HttpEventContext +{ + private static final int EVENT_BUFFER_CAPACITY = 1024; + + private final HttpEventFW.Builder httpEventRW = new HttpEventFW.Builder(); + private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + + public HttpEventContext( + EngineContext context) + { + // TODO: Ati - context + } + + public void accessControl( + Result result, + Level level, + long originId, + long routedId, + long initialId, + long replyId, + long traceId) + { + HttpEventFW event = httpEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .accessControl(e -> e + .result(r -> r.set(result)) + .level(l -> l.set(level)) + .originId(originId) + .routedId(routedId) + .initialId(initialId) + .replyId(replyId) + .traceId(traceId) + ) + .build(); + System.out.println(event); + } + + public void authorization( + Result result, + Level level, + long originId, + long routedId, + long initialId, + long replyId, + long traceId) + { + HttpEventFW event = httpEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorization(e -> e + .result(r -> r.set(result)) + .level(l -> l.set(level)) + .originId(originId) + .routedId(routedId) + .initialId(initialId) + .replyId(replyId) + .traceId(traceId) + ) + .build(); + System.out.println(event); + } +} diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 1365a233aa..625a113757 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -44,7 +44,6 @@ import static java.util.Arrays.asList; import java.net.URI; -import java.nio.ByteBuffer; import java.time.Instant; import java.util.ArrayList; import java.util.EnumMap; @@ -87,6 +86,7 @@ import io.aklivity.zilla.runtime.binding.http.config.HttpVersion; import io.aklivity.zilla.runtime.binding.http.internal.HttpBinding; import io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration; +import io.aklivity.zilla.runtime.binding.http.internal.HttpEventContext; import io.aklivity.zilla.runtime.binding.http.internal.codec.Http2ContinuationFW; import io.aklivity.zilla.runtime.binding.http.internal.codec.Http2DataFW; import io.aklivity.zilla.runtime.binding.http.internal.codec.Http2ErrorCode; @@ -118,7 +118,6 @@ import io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW; import io.aklivity.zilla.runtime.binding.http.internal.types.String16FW; import io.aklivity.zilla.runtime.binding.http.internal.types.String8FW; -import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.binding.http.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.AbortFW; @@ -549,6 +548,7 @@ public final class HttpServerFactory implements HttpStreamFactory private final Matcher connectionClose; private final int maximumHeadersSize; private final Long2ObjectHashMap bindings; + private final HttpEventContext event; public HttpServerFactory( HttpConfiguration config, @@ -581,6 +581,7 @@ public HttpServerFactory( this.encodeMax = bufferPool.slotCapacity(); this.createValidator = context::createValidator; this.bindings = new Long2ObjectHashMap<>(); + this.event = new HttpEventContext(context); this.headers200 = initHeaders(config, STATUS_200); this.headers204 = initHeaders(config, STATUS_204); @@ -945,7 +946,6 @@ private void doChallenge( receiver.accept(challenge.typeId(), challenge.buffer(), challenge.offset(), challenge.sizeof()); } - @SuppressWarnings("checkstyle:methodlength") // TODO: Ati private int decodeHeaders( HttpServer server, long traceId, @@ -1034,19 +1034,8 @@ else if (limit > endOfMethodLimit) } else if (!isCorsRequestAllowed(server.binding, headers)) { - HttpEventFW event = server.httpEventRW - .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) - .accessControl(e -> e - .result(r -> r.set(Result.FAILURE)) - .level(l -> l.set(Level.WARNING)) - .originId(server.originId) - .routedId(server.routedId) - .initialId(server.initialId) - .replyId(server.replyId) - .traceId(traceId) - ) - .build(); - System.out.println(event); // TODO: Ati + event.accessControl(Result.FAILURE, Level.WARNING, server.originId, server.routedId, server.initialId, + server.replyId, traceId); server.onDecodeHeadersError(traceId, authorization, response403); server.decoder = decodeIgnore; } @@ -1075,20 +1064,10 @@ else if (!isCorsRequestAllowed(server.binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); - long exchangeAuth0 = exchangeAuth; - HttpEventFW event = server.httpEventRW - .wrap(server.eventBuffer, 0, server.eventBuffer.capacity()) - .authorization(e -> e - .result(r -> r.set(exchangeAuth0 == 0 ? Result.FAILURE : Result.SUCCESS)) - .level(l -> l.set(exchangeAuth0 == 0 ? Level.WARNING : Level.INFO)) - .originId(server.originId) - .routedId(server.routedId) - .initialId(server.initialId) - .replyId(server.replyId) - .traceId(traceId) - ) - .build(); - System.out.println(event); // TODO: Ati + event.authorization( + exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, + exchangeAuth == 0 ? Level.WARNING : Level.INFO, + server.originId, server.routedId, server.initialId, server.replyId, traceId); } } @@ -1616,8 +1595,6 @@ private final class HttpServer private long replyBudgetId; private int replyMax; private HttpRequestType requestType; - private final HttpEventFW.Builder httpEventRW; - private final MutableDirectBuffer eventBuffer; private HttpServer( HttpBindingConfig binding, @@ -1644,8 +1621,6 @@ private HttpServer( this.delegateNetwork = this::onNetwork; this.guard = resolveGuard(binding); this.credentials = binding.credentials(); - this.httpEventRW = new HttpEventFW.Builder(); - this.eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(1024)); // TODO: Ati } private int replyPendingAck() From d4a6ec61d7674d6709c5c74b771079a7428e7cc8 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 23 Jan 2024 11:59:18 +0100 Subject: [PATCH 004/167] WIP core Event --- .../main/resources/META-INF/zilla/http.idl | 27 ++---------------- .../main/resources/META-INF/zilla/core.idl | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 6a88e0bc67..a268199540 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -58,35 +58,14 @@ scope http AUTHORIZATION (2) } - enum Result + struct HttpAuthorizationEvent extends core::event::Event { - SUCCESS, - FAILURE - } - - enum Level - { - INFO, - WARNING, - ERROR - } - - struct HttpEventCommon - { - Result result; - Level level; - int64 timestamp = 0; - int64 originId; - int64 routedId; - int64 initialId; - int64 replyId; - int64 traceId; } union HttpEvent switch (HttpEventType) { - case ACCESS_CONTROL: HttpEventCommon accessControl; - case AUTHORIZATION: HttpEventCommon authorization; + case ACCESS_CONTROL: core::event::Event accessControl; + case AUTHORIZATION: HttpAuthorizationEvent authorization; } } } diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index bc78dd0888..53efa1f48d 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -100,4 +100,32 @@ scope core octets extension; } } + + scope event + { + enum Level + { + INFO, + WARNING, + ERROR + } + + enum Result + { + SUCCESS, + FAILURE + } + + struct Event + { + Result result; + Level level; + int64 timestamp = 0; + int64 originId; + int64 routedId; + int64 initialId; + int64 replyId; + int64 traceId; + } + } } From ddef06c392593ad215abaa32b64f8024ca50b734 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 23 Jan 2024 12:13:20 +0100 Subject: [PATCH 005/167] WIP EngineWorker logEvent --- .../runtime/binding/http/internal/HttpEventContext.java | 8 +++++--- .../io/aklivity/zilla/runtime/engine/EngineContext.java | 3 +++ .../runtime/engine/internal/registry/EngineWorker.java | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 561a818f37..8df32487ef 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -16,6 +16,7 @@ package io.aklivity.zilla.runtime.binding.http.internal; import java.nio.ByteBuffer; +import java.util.function.Consumer; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -31,11 +32,12 @@ public class HttpEventContext private final HttpEventFW.Builder httpEventRW = new HttpEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + private final Consumer logEvent; public HttpEventContext( EngineContext context) { - // TODO: Ati - context + this.logEvent = context::logEvent; } public void accessControl( @@ -59,7 +61,7 @@ public void accessControl( .traceId(traceId) ) .build(); - System.out.println(event); + logEvent.accept(event); } public void authorization( @@ -83,6 +85,6 @@ public void authorization( .traceId(traceId) ) .build(); - System.out.println(event); + logEvent.accept(event); } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 0612ec1c15..48e9373324 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -143,4 +143,7 @@ void onExporterAttached( void onExporterDetached( long exporterId); + + void logEvent( + T event); } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 18f5fa564c..972fcc0081 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -870,6 +870,14 @@ public Validator createValidator( return validatorFactory.create(validator, resolveId, this::supplyCatalog); } + @Override + public void logEvent( + T event) + { + // TODO: Ati + System.out.println(event); + } + private void onSystemMessage( int msgTypeId, DirectBuffer buffer, From a4399ca1ff499c1e2109cf04145ccd1a0be26b52 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 23 Jan 2024 14:41:17 +0100 Subject: [PATCH 006/167] WIP code BindingEvent --- .../src/main/resources/META-INF/zilla/http.idl | 4 ++-- specs/engine.spec/src/main/resources/META-INF/zilla/core.idl | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index a268199540..b9898bfcb0 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -58,13 +58,13 @@ scope http AUTHORIZATION (2) } - struct HttpAuthorizationEvent extends core::event::Event + struct HttpAuthorizationEvent extends core::event::BindingEvent { } union HttpEvent switch (HttpEventType) { - case ACCESS_CONTROL: core::event::Event accessControl; + case ACCESS_CONTROL: core::event::BindingEvent accessControl; case AUTHORIZATION: HttpAuthorizationEvent authorization; } } diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index 53efa1f48d..896276de73 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -121,6 +121,10 @@ scope core Result result; Level level; int64 timestamp = 0; + } + + struct BindingEvent extends Event + { int64 originId; int64 routedId; int64 initialId; From 66202a93601ee3be74286f668c739252c6c2a06f Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 23 Jan 2024 17:01:07 +0100 Subject: [PATCH 007/167] WIP h2 --- .../binding/http/internal/stream/HttpServerFactory.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 625a113757..1fd4e75479 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -4856,6 +4856,7 @@ else if (headersDecoder.httpError()) } else if (!isCorsRequestAllowed(binding, headers)) { + event.accessControl(Result.FAILURE, Level.WARNING, originId, routedId, initialId, replyId, traceId); doEncodeHeaders(traceId, authorization, streamId, headers403, true); } else @@ -4888,6 +4889,10 @@ else if (!isCorsRequestAllowed(binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(initialId, credentialsMatch); + event.authorization( + exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, + exchangeAuth == 0 ? Level.WARNING : Level.INFO, + originId, routedId, initialId, replyId, traceId); } } From d67cf9ed1e990384e023b1e4984463a026bb446e Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 24 Jan 2024 10:21:53 +0100 Subject: [PATCH 008/167] WIP identity --- .../runtime/binding/http/internal/HttpEventContext.java | 4 +++- .../binding/http/internal/stream/HttpServerFactory.java | 6 ++++-- .../src/main/resources/META-INF/zilla/http.idl | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 8df32487ef..7d56cc6d7f 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -71,7 +71,8 @@ public void authorization( long routedId, long initialId, long replyId, - long traceId) + long traceId, + String identity) { HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) @@ -83,6 +84,7 @@ public void authorization( .initialId(initialId) .replyId(replyId) .traceId(traceId) + .identity(identity) ) .build(); logEvent.accept(event); diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 1fd4e75479..506d7952e2 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1067,7 +1067,8 @@ else if (!isCorsRequestAllowed(server.binding, headers)) event.authorization( exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, exchangeAuth == 0 ? Level.WARNING : Level.INFO, - server.originId, server.routedId, server.initialId, server.replyId, traceId); + server.originId, server.routedId, server.initialId, server.replyId, traceId, + guard.identity(authorization)); } } @@ -4892,7 +4893,8 @@ else if (!isCorsRequestAllowed(binding, headers)) event.authorization( exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, exchangeAuth == 0 ? Level.WARNING : Level.INFO, - originId, routedId, initialId, replyId, traceId); + originId, routedId, initialId, replyId, traceId, + guard.identity(authorization)); } } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index b9898bfcb0..16dd172f38 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -54,12 +54,13 @@ scope http { enum HttpEventType (uint8) { - ACCESS_CONTROL (1), - AUTHORIZATION (2) + AUTHORIZATION (1), + ACCESS_CONTROL (2) } struct HttpAuthorizationEvent extends core::event::BindingEvent { + string8 identity; } union HttpEvent switch (HttpEventType) From 95aefb3150fca7a6c831b7e8fb59349247b54fef Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 24 Jan 2024 10:22:10 +0100 Subject: [PATCH 009/167] WIP mqtt --- .../mqtt/internal/MqttEventContext.java | 68 +++++++++++++++++++ .../internal/stream/MqttServerFactory.java | 10 +++ .../main/resources/META-INF/zilla/mqtt.idl | 18 +++++ 3 files changed, 96 insertions(+) create mode 100644 runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java new file mode 100644 index 0000000000..4d20ff6689 --- /dev/null +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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.aklivity.zilla.runtime.binding.mqtt.internal; + +import java.nio.ByteBuffer; +import java.util.function.Consumer; + +import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; + +import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.MqttEventFW; +import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Result; +import io.aklivity.zilla.runtime.engine.EngineContext; + +public class MqttEventContext +{ + private static final int EVENT_BUFFER_CAPACITY = 1024; + + private final MqttEventFW.Builder mqttEventRW = new MqttEventFW.Builder(); + private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + private final Consumer logEvent; + + public MqttEventContext( + EngineContext context) + { + this.logEvent = context::logEvent; + } + + public void authorization( + Result result, + Level level, + long originId, + long routedId, + long initialId, + long replyId, + long traceId, + String identity) + { + MqttEventFW event = mqttEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorization(e -> e + .result(r -> r.set(result)) + .level(l -> l.set(level)) + .originId(originId) + .routedId(routedId) + .initialId(initialId) + .replyId(replyId) + .traceId(traceId) + .identity(identity) + ) + .build(); + logEvent.accept(event); + } +} diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index 6f88fdb965..49f59ee8b7 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -112,6 +112,7 @@ import io.aklivity.zilla.runtime.binding.mqtt.config.MqttPatternConfig.MqttConnectProperty; import io.aklivity.zilla.runtime.binding.mqtt.internal.MqttBinding; import io.aklivity.zilla.runtime.binding.mqtt.internal.MqttConfiguration; +import io.aklivity.zilla.runtime.binding.mqtt.internal.MqttEventContext; import io.aklivity.zilla.runtime.binding.mqtt.internal.MqttValidator; import io.aklivity.zilla.runtime.binding.mqtt.internal.config.MqttBindingConfig; import io.aklivity.zilla.runtime.binding.mqtt.internal.config.MqttRouteConfig; @@ -167,6 +168,8 @@ import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttUserPropertyFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttWillV4FW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttWillV5FW; +import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.stream.DataFW; @@ -403,6 +406,7 @@ public final class MqttServerFactory implements MqttStreamFactory private final Map decodersByPacketTypeV5; private final IntSupplier supplySubscriptionId; private final EngineContext context; + private final MqttEventContext event; private int maximumPacketSize = Integer.MAX_VALUE; @@ -527,6 +531,7 @@ public MqttServerFactory( this.decodePacketTypeByVersion.put(MQTT_PROTOCOL_VERSION_4, this::decodePacketTypeV4); this.decodePacketTypeByVersion.put(MQTT_PROTOCOL_VERSION_5, this::decodePacketTypeV5); this.unreleasedPacketIdsByClientId = unreleasedPacketIdsByClientId; + this.event = new MqttEventContext(context); } @Override @@ -2923,6 +2928,11 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) if (credentialsMatch != null) { sessionAuth = guard.reauthorize(initialId, credentialsMatch); + event.authorization( + sessionAuth == 0 ? Result.FAILURE : Result.SUCCESS, + sessionAuth == 0 ? Level.WARNING : Level.INFO, + originId, routedId, initialId, replyId, traceId, + guard.identity(sessionId)); } } diff --git a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl index 170f771a63..fb0328ec25 100644 --- a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl +++ b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl @@ -257,4 +257,22 @@ scope mqtt int16[length] packetIds; } } + + scope event + { + enum MqttEventType (uint8) + { + AUTHORIZATION (1) + } + + struct MqttAuthorizationEvent extends core::event::BindingEvent + { + string8 identity; + } + + union MqttEvent switch (MqttEventType) + { + case AUTHORIZATION: MqttAuthorizationEvent authorization; + } + } } From e13736351d9442ea663e7739ec8386c01b5a7d8a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 24 Jan 2024 10:48:37 +0100 Subject: [PATCH 010/167] fix --- .../http/internal/HttpEventContext.java | 18 +++++------------- .../internal/stream/HttpServerFactory.java | 11 ++++------- .../mqtt/internal/MqttEventContext.java | 8 ++------ .../internal/stream/MqttServerFactory.java | 3 +-- .../src/main/resources/META-INF/zilla/core.idl | 4 +--- 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 7d56cc6d7f..1a96023063 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -43,22 +43,18 @@ public HttpEventContext( public void accessControl( Result result, Level level, - long originId, + long traceId, long routedId, - long initialId, - long replyId, - long traceId) + long initialId) { HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .accessControl(e -> e .result(r -> r.set(result)) .level(l -> l.set(level)) - .originId(originId) + .traceId(traceId) .routedId(routedId) .initialId(initialId) - .replyId(replyId) - .traceId(traceId) ) .build(); logEvent.accept(event); @@ -67,11 +63,9 @@ public void accessControl( public void authorization( Result result, Level level, - long originId, + long traceId, long routedId, long initialId, - long replyId, - long traceId, String identity) { HttpEventFW event = httpEventRW @@ -79,11 +73,9 @@ public void authorization( .authorization(e -> e .result(r -> r.set(result)) .level(l -> l.set(level)) - .originId(originId) + .traceId(traceId) .routedId(routedId) .initialId(initialId) - .replyId(replyId) - .traceId(traceId) .identity(identity) ) .build(); diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 506d7952e2..5dea23c3c0 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1034,8 +1034,7 @@ else if (limit > endOfMethodLimit) } else if (!isCorsRequestAllowed(server.binding, headers)) { - event.accessControl(Result.FAILURE, Level.WARNING, server.originId, server.routedId, server.initialId, - server.replyId, traceId); + event.accessControl(Result.FAILURE, Level.WARNING, traceId, server.routedId, server.initialId); server.onDecodeHeadersError(traceId, authorization, response403); server.decoder = decodeIgnore; } @@ -1067,8 +1066,7 @@ else if (!isCorsRequestAllowed(server.binding, headers)) event.authorization( exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, exchangeAuth == 0 ? Level.WARNING : Level.INFO, - server.originId, server.routedId, server.initialId, server.replyId, traceId, - guard.identity(authorization)); + traceId, server.routedId, server.initialId, guard.identity(authorization)); } } @@ -4857,7 +4855,7 @@ else if (headersDecoder.httpError()) } else if (!isCorsRequestAllowed(binding, headers)) { - event.accessControl(Result.FAILURE, Level.WARNING, originId, routedId, initialId, replyId, traceId); + event.accessControl(Result.FAILURE, Level.WARNING, traceId, routedId, initialId); doEncodeHeaders(traceId, authorization, streamId, headers403, true); } else @@ -4893,8 +4891,7 @@ else if (!isCorsRequestAllowed(binding, headers)) event.authorization( exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, exchangeAuth == 0 ? Level.WARNING : Level.INFO, - originId, routedId, initialId, replyId, traceId, - guard.identity(authorization)); + traceId, routedId, initialId, guard.identity(authorization)); } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 4d20ff6689..1e12b98873 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -43,11 +43,9 @@ public MqttEventContext( public void authorization( Result result, Level level, - long originId, + long traceId, long routedId, long initialId, - long replyId, - long traceId, String identity) { MqttEventFW event = mqttEventRW @@ -55,11 +53,9 @@ public void authorization( .authorization(e -> e .result(r -> r.set(result)) .level(l -> l.set(level)) - .originId(originId) + .traceId(traceId) .routedId(routedId) .initialId(initialId) - .replyId(replyId) - .traceId(traceId) .identity(identity) ) .build(); diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index 49f59ee8b7..8de75a6aa8 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -2931,8 +2931,7 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) event.authorization( sessionAuth == 0 ? Result.FAILURE : Result.SUCCESS, sessionAuth == 0 ? Level.WARNING : Level.INFO, - originId, routedId, initialId, replyId, traceId, - guard.identity(sessionId)); + traceId, routedId, initialId, guard.identity(sessionId)); } } diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index 896276de73..05d3a59908 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -121,15 +121,13 @@ scope core Result result; Level level; int64 timestamp = 0; + int64 traceId; } struct BindingEvent extends Event { - int64 originId; int64 routedId; int64 initialId; - int64 replyId; - int64 traceId; } } } From 7cd659f213a5880992acaf04aa1109be7f58307e Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 24 Jan 2024 10:57:30 +0100 Subject: [PATCH 011/167] fix --- .../binding/http/internal/HttpEventContext.java | 4 ++-- .../binding/mqtt/internal/MqttEventContext.java | 2 +- .../src/main/resources/META-INF/zilla/http.idl | 15 +++++++++++++-- .../src/main/resources/META-INF/zilla/mqtt.idl | 13 ++++++++++++- .../src/main/resources/META-INF/zilla/core.idl | 7 ------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 1a96023063..6069703019 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -50,11 +50,11 @@ public void accessControl( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .accessControl(e -> e - .result(r -> r.set(result)) .level(l -> l.set(level)) .traceId(traceId) .routedId(routedId) .initialId(initialId) + .result(r -> r.set(result)) ) .build(); logEvent.accept(event); @@ -71,11 +71,11 @@ public void authorization( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e - .result(r -> r.set(result)) .level(l -> l.set(level)) .traceId(traceId) .routedId(routedId) .initialId(initialId) + .result(r -> r.set(result)) .identity(identity) ) .build(); diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 1e12b98873..79a758c467 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -51,11 +51,11 @@ public void authorization( MqttEventFW event = mqttEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e - .result(r -> r.set(result)) .level(l -> l.set(level)) .traceId(traceId) .routedId(routedId) .initialId(initialId) + .result(r -> r.set(result)) .identity(identity) ) .build(); diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 16dd172f38..8217779537 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -58,14 +58,25 @@ scope http ACCESS_CONTROL (2) } - struct HttpAuthorizationEvent extends core::event::BindingEvent + enum Result (uint8) + { + SUCCESS (0), + FAILURE (1) + } + + struct HttpBindingEvent extends core::event::BindingEvent + { + Result result; + } + + struct HttpAuthorizationEvent extends HttpBindingEvent { string8 identity; } union HttpEvent switch (HttpEventType) { - case ACCESS_CONTROL: core::event::BindingEvent accessControl; + case ACCESS_CONTROL: HttpBindingEvent accessControl; case AUTHORIZATION: HttpAuthorizationEvent authorization; } } diff --git a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl index fb0328ec25..204e81f9af 100644 --- a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl +++ b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl @@ -265,7 +265,18 @@ scope mqtt AUTHORIZATION (1) } - struct MqttAuthorizationEvent extends core::event::BindingEvent + enum Result (uint8) + { + SUCCESS (0), + FAILURE (1) + } + + struct MqttBindingEvent extends core::event::BindingEvent + { + Result result; + } + + struct MqttAuthorizationEvent extends MqttBindingEvent { string8 identity; } diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index 05d3a59908..61cab333a4 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -110,15 +110,8 @@ scope core ERROR } - enum Result - { - SUCCESS, - FAILURE - } - struct Event { - Result result; Level level; int64 timestamp = 0; int64 traceId; From 3c4074697f2e3a1215c6a7c07357774bad570eed Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 24 Jan 2024 12:51:21 +0100 Subject: [PATCH 012/167] WIP MessageConsumer --- .../binding/http/internal/HttpEventContext.java | 13 +++++++++---- .../http/internal/stream/HttpServerFactory.java | 2 +- .../binding/mqtt/internal/MqttEventContext.java | 10 +++++++--- .../mqtt/internal/stream/MqttServerFactory.java | 2 +- .../zilla/runtime/engine/EngineContext.java | 7 +++++-- .../engine/internal/registry/EngineWorker.java | 12 ++++++++---- 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 6069703019..fcbc2571bd 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -16,7 +16,6 @@ package io.aklivity.zilla.runtime.binding.http.internal; import java.nio.ByteBuffer; -import java.util.function.Consumer; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -25,6 +24,7 @@ import io.aklivity.zilla.runtime.binding.http.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; public class HttpEventContext { @@ -32,11 +32,14 @@ public class HttpEventContext private final HttpEventFW.Builder httpEventRW = new HttpEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); - private final Consumer logEvent; + private final int httpTypeId; + private final MessageConsumer logEvent; public HttpEventContext( + int httpTypeId, EngineContext context) { + this.httpTypeId = httpTypeId; this.logEvent = context::logEvent; } @@ -57,7 +60,8 @@ public void accessControl( .result(r -> r.set(result)) ) .build(); - logEvent.accept(event); + System.out.println(event); // TODO: Ati + logEvent.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } public void authorization( @@ -79,6 +83,7 @@ public void authorization( .identity(identity) ) .build(); - logEvent.accept(event); + System.out.println(event); // TODO: Ati + logEvent.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 5dea23c3c0..b4a8f4e8df 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -581,7 +581,7 @@ public HttpServerFactory( this.encodeMax = bufferPool.slotCapacity(); this.createValidator = context::createValidator; this.bindings = new Long2ObjectHashMap<>(); - this.event = new HttpEventContext(context); + this.event = new HttpEventContext(httpTypeId, context); this.headers200 = initHeaders(config, STATUS_200); this.headers204 = initHeaders(config, STATUS_204); diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 79a758c467..33e3db8017 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -16,7 +16,6 @@ package io.aklivity.zilla.runtime.binding.mqtt.internal; import java.nio.ByteBuffer; -import java.util.function.Consumer; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -25,6 +24,7 @@ import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.MqttEventFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; public class MqttEventContext { @@ -32,11 +32,14 @@ public class MqttEventContext private final MqttEventFW.Builder mqttEventRW = new MqttEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); - private final Consumer logEvent; + private final int mqttTypeId; + private final MessageConsumer logEvent; public MqttEventContext( + int mqttTypeId, EngineContext context) { + this.mqttTypeId = mqttTypeId; this.logEvent = context::logEvent; } @@ -59,6 +62,7 @@ public void authorization( .identity(identity) ) .build(); - logEvent.accept(event); + System.out.println(event); // TODO: Ati + logEvent.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index 8de75a6aa8..00302a46fe 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -531,7 +531,7 @@ public MqttServerFactory( this.decodePacketTypeByVersion.put(MQTT_PROTOCOL_VERSION_4, this::decodePacketTypeV4); this.decodePacketTypeByVersion.put(MQTT_PROTOCOL_VERSION_5, this::decodePacketTypeV5); this.unreleasedPacketIdsByClientId = unreleasedPacketIdsByClientId; - this.event = new MqttEventContext(context); + this.event = new MqttEventContext(mqttTypeId, context); } @Override diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 48e9373324..752e2a0257 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -21,6 +21,7 @@ import java.util.function.LongSupplier; import java.util.function.ToLongFunction; +import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import io.aklivity.zilla.runtime.engine.binding.BindingHandler; @@ -144,6 +145,8 @@ void onExporterAttached( void onExporterDetached( long exporterId); - void logEvent( - T event); + void logEvent(int msgTypeId, + DirectBuffer buffer, + int index, + int length); } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 972fcc0081..5cb841cb53 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -871,11 +871,15 @@ public Validator createValidator( } @Override - public void logEvent( - T event) + public void logEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) { - // TODO: Ati - System.out.println(event); + // TODO: Ati - write record + // TODO: Ati - include timestamp + System.out.printf("%d %s %d %d%n", msgTypeId, buffer, index, length); } private void onSystemMessage( From e58cd98f65c05e196a473e785bb4f1023fca0b74 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 25 Jan 2024 10:35:07 +0100 Subject: [PATCH 013/167] WIP SchemaRegistryEventContext --- .../catalog-schema-registry.spec/pom.xml | 20 ++++++ .../META-INF/zilla/schemaregistry.idl | 47 ++++++++++++++ incubator/catalog-schema-registry/pom.xml | 21 +++++- .../internal/SchemaRegistryCatalog.java | 2 +- .../SchemaRegistryCatalogContext.java | 11 +++- .../SchemaRegistryCatalogHandler.java | 21 +++++- .../internal/SchemaRegistryEventContext.java | 64 +++++++++++++++++++ .../registry/internal/SchemaRegistryIT.java | 13 ++-- .../main/resources/META-INF/zilla/core.idl | 6 +- 9 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schemaregistry.idl create mode 100644 incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java diff --git a/incubator/catalog-schema-registry.spec/pom.xml b/incubator/catalog-schema-registry.spec/pom.xml index 6e529c8f30..63dd135cac 100644 --- a/incubator/catalog-schema-registry.spec/pom.xml +++ b/incubator/catalog-schema-registry.spec/pom.xml @@ -63,6 +63,23 @@ org.jasig.maven maven-notice-plugin + + ${project.groupId} + flyweight-maven-plugin + ${project.version} + + core schemaregistry + io.aklivity.zilla.specs.catalog.schema.registry.internal.types + + + + + validate + generate + + + + com.mycila license-maven-plugin @@ -86,6 +103,9 @@ org.jacoco jacoco-maven-plugin + + io/aklivity/zilla/specs/catalog/schema/registry/internal/types/**/*.class + BUNDLE diff --git a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schemaregistry.idl b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schemaregistry.idl new file mode 100644 index 0000000000..e9e1218302 --- /dev/null +++ b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schemaregistry.idl @@ -0,0 +1,47 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +scope schemaregistry +{ + scope event + { + enum SchemaRegistryEventType (uint8) + { + REMOTE_ACCESS (1) + } + + enum Result (uint8) + { + SUCCESS (0), + FAILURE (1) + } + + struct SchemaRegistryCatalogEvent extends core::event::CatalogEvent + { + Result result; + } + + struct SchemaRegistryRemoteAccessEvent extends SchemaRegistryCatalogEvent + { + string16 url; + string8 method; + int16 status; + } + + union SchemaRegistryEvent switch (SchemaRegistryEventType) + { + case REMOTE_ACCESS: SchemaRegistryRemoteAccessEvent remoteAccess; + } + } +} diff --git a/incubator/catalog-schema-registry/pom.xml b/incubator/catalog-schema-registry/pom.xml index a8b9867eba..99b6b89b31 100644 --- a/incubator/catalog-schema-registry/pom.xml +++ b/incubator/catalog-schema-registry/pom.xml @@ -24,7 +24,7 @@ 11 11 - 0.90 + 0.80 0 @@ -71,6 +71,22 @@ org.jasig.maven maven-notice-plugin + + ${project.groupId} + flyweight-maven-plugin + ${project.version} + + core schemaregistry + io.aklivity.zilla.runtime.catalog.schema.registry.internal.types + + + + + generate + + + + com.mycila license-maven-plugin @@ -125,6 +141,9 @@ org.jacoco jacoco-maven-plugin + + io/aklivity/zilla/runtime/catalog/schema/registry/internal/types/**/*.class + BUNDLE diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalog.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalog.java index 8affce6dc5..c7ebe83402 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalog.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalog.java @@ -40,7 +40,7 @@ public String name() public CatalogContext supply( EngineContext context) { - return new SchemaRegistryCatalogContext(); + return new SchemaRegistryCatalogContext(context); } @Override diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogContext.java index cf5c8eb7b6..164c9e4b8e 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogContext.java @@ -15,16 +15,25 @@ package io.aklivity.zilla.runtime.catalog.schema.registry.internal; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.config.SchemaRegistryOptionsConfig; +import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.catalog.CatalogContext; import io.aklivity.zilla.runtime.engine.catalog.CatalogHandler; import io.aklivity.zilla.runtime.engine.config.CatalogConfig; public class SchemaRegistryCatalogContext implements CatalogContext { + private final EngineContext context; + + public SchemaRegistryCatalogContext( + EngineContext context) + { + this.context = context; + } + @Override public CatalogHandler attach( CatalogConfig catalog) { - return new SchemaRegistryCatalogHandler(SchemaRegistryOptionsConfig.class.cast(catalog.options)); + return new SchemaRegistryCatalogHandler(SchemaRegistryOptionsConfig.class.cast(catalog.options), context); } } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java index 28376e90a2..ab6b4e23bf 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java @@ -25,6 +25,9 @@ import io.aklivity.zilla.runtime.catalog.schema.registry.internal.config.SchemaRegistryOptionsConfig; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.serializer.RegisterSchemaRequest; +import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Level; +import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Result; +import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.catalog.CatalogHandler; public class SchemaRegistryCatalogHandler implements CatalogHandler @@ -39,9 +42,11 @@ public class SchemaRegistryCatalogHandler implements CatalogHandler private final CRC32C crc32c; private final Int2ObjectCache cache; private final Int2ObjectCache schemaIdCache; + private final SchemaRegistryEventContext event; public SchemaRegistryCatalogHandler( - SchemaRegistryOptionsConfig config) + SchemaRegistryOptionsConfig config, + EngineContext context) { this.baseUrl = config.url; this.client = HttpClient.newHttpClient(); @@ -49,6 +54,7 @@ public SchemaRegistryCatalogHandler( this.crc32c = new CRC32C(); this.cache = new Int2ObjectCache<>(1, 1024, i -> {}); this.schemaIdCache = new Int2ObjectCache<>(1, 1024, i -> {}); + this.event = new SchemaRegistryEventContext(context); } @Override @@ -136,10 +142,21 @@ private String sendHttpRequest( try { HttpResponse response = client.send(httpRequest, HttpResponse.BodyHandlers.ofString()); - return response.statusCode() == 200 ? response.body() : null; + String responseBody = null; + if (response.statusCode() == 200) + { + responseBody = response.body(); + } + else + { + event.remoteAccess(Result.FAILURE, Level.ERROR, httpRequest.uri().toString(), httpRequest.method(), + response.statusCode()); + } + return responseBody; } catch (Exception ex) { + event.remoteAccess(Result.FAILURE, Level.ERROR, httpRequest.uri().toString(), httpRequest.method(), -1); ex.printStackTrace(System.out); } return null; diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java new file mode 100644 index 0000000000..ed6b98c054 --- /dev/null +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -0,0 +1,64 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.catalog.schema.registry.internal; + +import java.nio.ByteBuffer; + +import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; + +import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Level; +import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Result; +import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.SchemaRegistryEventFW; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; + +public class SchemaRegistryEventContext +{ + private static final int EVENT_BUFFER_CAPACITY = 1024; + + private final SchemaRegistryEventFW.Builder schemaRegistryEventRW = new SchemaRegistryEventFW.Builder(); + private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + private final int typeId; + private final MessageConsumer logEvent; + + public SchemaRegistryEventContext( + EngineContext context) + { + this.typeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); + this.logEvent = context::logEvent; + } + + public void remoteAccess( + Result result, + Level level, + String url, + String method, + int status) + { + SchemaRegistryEventFW event = schemaRegistryEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .remoteAccess(e -> e + .level(l -> l.set(level)) + .result(r -> r.set(result)) + .url(url) + .method(method) + .status((short) status) + ) + .build(); + System.out.println(event); // TODO: Ati + logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); + } +} diff --git a/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java b/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java index c115321a4c..1485a0e104 100644 --- a/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java +++ b/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java @@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertEquals; import static org.junit.rules.RuleChain.outerRule; +import static org.mockito.Mockito.mock; import org.junit.Before; import org.junit.Rule; @@ -31,6 +32,7 @@ import org.kaazing.k3po.junit.rules.K3poRule; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.config.SchemaRegistryOptionsConfig; +import io.aklivity.zilla.runtime.engine.EngineContext; public class SchemaRegistryIT { @@ -43,6 +45,7 @@ public class SchemaRegistryIT public final TestRule chain = outerRule(k3po).around(timeout); private SchemaRegistryOptionsConfig config; + private EngineContext context = mock(EngineContext.class); @Before public void setup() @@ -59,7 +62,7 @@ public void shouldResolveSchemaViaSchemaId() throws Exception "{\"name\":\"status\",\"type\":\"string\"}]," + "\"name\":\"Event\",\"namespace\":\"io.aklivity.example\",\"type\":\"record\"}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); String schema = catalog.resolve(9); @@ -78,7 +81,7 @@ public void shouldResolveSchemaViaSubjectVersion() throws Exception "{\"name\":\"status\",\"type\":\"string\"}]," + "\"name\":\"Event\",\"namespace\":\"io.aklivity.example\",\"type\":\"record\"}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); int schemaId = catalog.resolve("items-snapshots-value", "latest"); @@ -99,7 +102,7 @@ public void shouldRegisterSchema() throws Exception String schema = "{\"type\": \"record\",\"name\": \"test\",\"fields\":[{\"type\": \"string\",\"name\": \"field1\"}," + "{\"type\": \"com.acme.Referenced\",\"name\": \"int\"}]}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); int schemaId = catalog.register("items-snapshots-value", "avro", schema); @@ -118,7 +121,7 @@ public void shouldResolveSchemaViaSchemaIdFromCache() throws Exception "{\"name\":\"status\",\"type\":\"string\"}]," + "\"name\":\"Event\",\"namespace\":\"io.aklivity.example\",\"type\":\"record\"}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); catalog.resolve(9); @@ -139,7 +142,7 @@ public void shouldResolveSchemaViaSubjectVersionFromCache() throws Exception "{\"name\":\"status\",\"type\":\"string\"}]," + "\"name\":\"Event\",\"namespace\":\"io.aklivity.example\",\"type\":\"record\"}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); catalog.resolve(catalog.resolve("items-snapshots-value", "latest")); diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index 61cab333a4..b89e20bdc1 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -114,7 +114,7 @@ scope core { Level level; int64 timestamp = 0; - int64 traceId; + int64 traceId = 0; } struct BindingEvent extends Event @@ -122,5 +122,9 @@ scope core int64 routedId; int64 initialId; } + + struct CatalogEvent extends Event + { + } } } From e6a4c099939af82dd141b93673b6ef23b6543528 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 25 Jan 2024 12:23:55 +0100 Subject: [PATCH 014/167] WIP TcpEventContext --- .../binding/tcp/internal/TcpEventContext.java | 68 +++++++++++++++++++ .../tcp/internal/stream/TcpClientFactory.java | 15 ++-- .../main/resources/META-INF/zilla/proxy.idl | 29 ++++++++ 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java new file mode 100644 index 0000000000..5c831bac90 --- /dev/null +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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.aklivity.zilla.runtime.binding.tcp.internal; + +import java.nio.ByteBuffer; + +import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; + +import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.ProxyEventFW; +import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Result; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; + +public class TcpEventContext +{ + private static final int EVENT_BUFFER_CAPACITY = 1024; + + private final ProxyEventFW.Builder proxyEventRW = new ProxyEventFW.Builder(); + private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + private final int typeId; + private final MessageConsumer logEvent; + + public TcpEventContext( + int typeId, + EngineContext context) + { + this.typeId = typeId; + this.logEvent = context::logEvent; + } + + public void remoteAccess( + Result result, + Level level, + long traceId, + long routedId, + long initialId, + String address) + { + ProxyEventFW event = proxyEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .remoteAccess(e -> e + .level(l -> l.set(level)) + .traceId(traceId) + .routedId(routedId) + .initialId(initialId) + .result(r -> r.set(result)) + .address(address) + ) + .build(); + System.out.println(event); // TODO: Ati + logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); + } +} diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 08afe896f8..4d72452477 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -44,9 +44,12 @@ import io.aklivity.zilla.runtime.binding.tcp.config.TcpOptionsConfig; import io.aklivity.zilla.runtime.binding.tcp.internal.TcpConfiguration; +import io.aklivity.zilla.runtime.binding.tcp.internal.TcpEventContext; import io.aklivity.zilla.runtime.binding.tcp.internal.config.TcpBindingConfig; import io.aklivity.zilla.runtime.binding.tcp.internal.types.Flyweight; import io.aklivity.zilla.runtime.binding.tcp.internal.types.OctetsFW; +import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.DataFW; @@ -95,6 +98,7 @@ public class TcpClientFactory implements TcpStreamFactory private final int proxyTypeId; private final int windowThreshold; private final int initialMax; + private final TcpEventContext event; public TcpClientFactory( TcpConfiguration config, @@ -115,6 +119,7 @@ public TcpClientFactory( this.initialMax = bufferPool.slotCapacity(); this.windowThreshold = (bufferPool.slotCapacity() * config.windowThreshold()) / 100; + this.event = new TcpEventContext(proxyTypeId, context); } @Override @@ -270,7 +275,7 @@ private void doNetConnect( } catch (UnresolvedAddressException | IOException ex) { - onNetRejected(); + onNetRejected(remoteAddress); } } @@ -285,7 +290,7 @@ private int onNetConnect( } catch (UnresolvedAddressException | IOException ex) { - onNetRejected(); + onNetRejected(null); } return 1; @@ -311,10 +316,12 @@ private void onNetConnected() } } - private void onNetRejected() + private void onNetRejected( + InetSocketAddress remoteAddress) { final long traceId = supplyTraceId.getAsLong(); - + String address = remoteAddress == null ? null : remoteAddress.toString(); + event.remoteAccess(Result.FAILURE, Level.ERROR, traceId, routedId, initialId, address); cleanup(traceId); } diff --git a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl index 7088aa8e85..12268f6a72 100644 --- a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl +++ b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl @@ -127,4 +127,33 @@ scope proxy ProxyInfo[] infos; } } + + scope event + { + enum ProxyEventType (uint8) + { + REMOTE_ACCESS (1) + } + + enum Result (uint8) + { + SUCCESS (0), + FAILURE (1) + } + + struct ProxyBindingEvent extends core::event::BindingEvent + { + Result result; + } + + struct ProxyRemoteAccessEvent extends ProxyBindingEvent + { + string16 address; + } + + union ProxyEvent switch (ProxyEventType) + { + case REMOTE_ACCESS: ProxyRemoteAccessEvent remoteAccess; + } + } } From 2916bed6881747b201f3c2cf1a87e6a150654d3a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 26 Jan 2024 11:18:06 +0100 Subject: [PATCH 015/167] WIP tls --- .../binding/tls/internal/TlsEventContext.java | 62 +++++++++++++++++++ .../tls/internal/stream/TlsClientFactory.java | 10 +++ .../tls/internal/stream/TlsServerFactory.java | 10 +++ .../main/resources/META-INF/zilla/proxy.idl | 7 ++- .../main/resources/META-INF/zilla/core.idl | 4 +- 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java new file mode 100644 index 0000000000..72b789b589 --- /dev/null +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -0,0 +1,62 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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.aklivity.zilla.runtime.binding.tls.internal; + +import java.nio.ByteBuffer; + +import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; + +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.ProxyEventFW; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Result; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; + +public class TlsEventContext +{ + private static final int EVENT_BUFFER_CAPACITY = 1024; + + private final ProxyEventFW.Builder proxyEventRW = new ProxyEventFW.Builder(); + private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + private final int typeId; + private final MessageConsumer logEvent; + + public TlsEventContext( + int typeId, + EngineContext context) + { + this.typeId = typeId; + this.logEvent = context::logEvent; + } + + public void tls( + Result result, + Level level, + long traceId) + { + ProxyEventFW event = proxyEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .tls(e -> e + .level(l -> l.set(level)) + .traceId(traceId) + .result(r -> r.set(result)) + ) + .build(); + System.out.println(event); // TODO: Ati + logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); + } +} diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index 75b6e7d1b3..27044c378a 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -44,6 +44,7 @@ import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.binding.tls.internal.TlsConfiguration; +import io.aklivity.zilla.runtime.binding.tls.internal.TlsEventContext; import io.aklivity.zilla.runtime.binding.tls.internal.config.TlsBindingConfig; import io.aklivity.zilla.runtime.binding.tls.internal.config.TlsRouteConfig; import io.aklivity.zilla.runtime.binding.tls.internal.types.OctetsFW; @@ -51,6 +52,8 @@ import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsRecordInfoFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedDataFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedInfoFW; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.DataFW; @@ -129,6 +132,7 @@ public final class TlsClientFactory implements TlsStreamFactory private final LongUnaryOperator supplyReplyId; private final int initialPadAdjust; private final Long2ObjectHashMap bindings; + private final TlsEventContext event; private final int decodeMax; private final int handshakeMax; @@ -168,6 +172,7 @@ public TlsClientFactory( this.initialPadAdjust = Math.max(context.bufferPool().slotCapacity() >> 14, 1) * MAXIMUM_HEADER_SIZE; this.bindings = new Long2ObjectHashMap<>(); + this.event = new TlsEventContext(proxyTypeId, context); this.inNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity()); this.inNetBuffer = new UnsafeBuffer(inNetByteBuffer); this.outNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity() << 1); @@ -617,6 +622,7 @@ private int decodeNotHandshaking( } catch (SSLException ex) { + event.tls(Result.FAILURE, Level.ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -780,6 +786,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException ex) { + event.tls(Result.FAILURE, Level.ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -1622,6 +1629,7 @@ private void onNetSignalHandshakeTimeout( final long traceId = signal.traceId(); cleanupNet(traceId); + event.tls(Result.HANDSHAKE_TIMEOUT, Level.ERROR, traceId); decoder = decodeIgnoreAll; } } @@ -1642,6 +1650,7 @@ private void doNetBegin( } catch (SSLException ex) { + event.tls(Result.FAILURE, Level.ERROR, traceId); cleanupNet(traceId); } @@ -2024,6 +2033,7 @@ private void doEncodeWrap( } catch (SSLException ex) { + event.tls(Result.FAILURE, Level.ERROR, traceId); cleanupNet(traceId); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index faf7445a4d..8d413a6c34 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -52,12 +52,15 @@ import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.binding.tls.internal.TlsConfiguration; +import io.aklivity.zilla.runtime.binding.tls.internal.TlsEventContext; import io.aklivity.zilla.runtime.binding.tls.internal.config.TlsBindingConfig; import io.aklivity.zilla.runtime.binding.tls.internal.config.TlsRouteConfig; import io.aklivity.zilla.runtime.binding.tls.internal.types.OctetsFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsRecordInfoFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedDataFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedInfoFW; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.DataFW; @@ -145,6 +148,7 @@ public final class TlsServerFactory implements TlsStreamFactory private final LongUnaryOperator supplyReplyId; private final int replyPadAdjust; private final Long2ObjectHashMap bindings; + private final TlsEventContext event; private final int decodeMax; private final int handshakeMax; @@ -183,6 +187,7 @@ public TlsServerFactory( this.handshakeMax = Math.min(config.handshakeWindowBytes(), decodeMax); this.handshakeTimeoutMillis = SECONDS.toMillis(config.handshakeTimeout()); this.bindings = new Long2ObjectHashMap<>(); + this.event = new TlsEventContext(proxyTypeId, context); this.inNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity()); this.inNetBuffer = new UnsafeBuffer(inNetByteBuffer); @@ -528,6 +533,7 @@ private int decodeBeforeHandshake( } catch (SSLException | RuntimeException ex) { + event.tls(Result.FAILURE, Level.ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -646,6 +652,7 @@ private int decodeNotHandshaking( } catch (SSLException | RuntimeException ex) { + event.tls(Result.FAILURE, Level.ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -827,6 +834,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException | RuntimeException ex) { + event.tls(Result.FAILURE, Level.ERROR, traceId); server.doEncodeWrapIfNecessary(traceId, budgetId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; @@ -1305,6 +1313,7 @@ private void onNetSignalHandshakeTimeout( handshakeTimeoutFutureId = NO_CANCEL_ID; cleanupNet(traceId); + event.tls(Result.HANDSHAKE_TIMEOUT, Level.ERROR, traceId); decoder = decodeIgnoreAll; } } @@ -1681,6 +1690,7 @@ private void doEncodeWrap( } catch (SSLException | RuntimeException ex) { + event.tls(Result.FAILURE, Level.ERROR, traceId); cleanupNet(traceId); } } diff --git a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl index 12268f6a72..aa03d207a0 100644 --- a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl +++ b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl @@ -132,13 +132,15 @@ scope proxy { enum ProxyEventType (uint8) { - REMOTE_ACCESS (1) + REMOTE_ACCESS (1), + TLS (2) } enum Result (uint8) { SUCCESS (0), - FAILURE (1) + FAILURE (1), + HANDSHAKE_TIMEOUT (2) } struct ProxyBindingEvent extends core::event::BindingEvent @@ -154,6 +156,7 @@ scope proxy union ProxyEvent switch (ProxyEventType) { case REMOTE_ACCESS: ProxyRemoteAccessEvent remoteAccess; + case TLS: ProxyBindingEvent tls; } } } diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index b89e20bdc1..c45a413360 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -119,8 +119,8 @@ scope core struct BindingEvent extends Event { - int64 routedId; - int64 initialId; + int64 routedId = 0; + int64 initialId = 0; } struct CatalogEvent extends Event From 35a723c2b39cf298ce468512714bbb94be6ec04e Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 26 Jan 2024 11:18:40 +0100 Subject: [PATCH 016/167] WIP kafka --- .../kafka/internal/KafkaEventContext.java | 66 +++++++++++++++++++ .../stream/KafkaClientSaslHandshaker.java | 12 ++++ .../main/resources/META-INF/zilla/kafka.idl | 24 +++++++ 3 files changed, 102 insertions(+) create mode 100644 runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java new file mode 100644 index 0000000000..5b8de0479e --- /dev/null +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -0,0 +1,66 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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.aklivity.zilla.runtime.binding.kafka.internal; + +import java.nio.ByteBuffer; + +import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; + +import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.KafkaEventFW; +import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Result; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; + +public class KafkaEventContext +{ + private static final int EVENT_BUFFER_CAPACITY = 1024; + + private final KafkaEventFW.Builder kafkaEventRW = new KafkaEventFW.Builder(); + private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + private final int kafkaTypeId; + private final MessageConsumer logEvent; + + public KafkaEventContext( + int kafkaTypeId, + EngineContext context) + { + this.kafkaTypeId = kafkaTypeId; + this.logEvent = context::logEvent; + } + + public void authorization( + Result result, + Level level, + long traceId, + long routedId, + long initialId) + { + KafkaEventFW event = kafkaEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorization(e -> e + .level(l -> l.set(level)) + .traceId(traceId) + .routedId(routedId) + .initialId(initialId) + .result(r -> r.set(result)) + ) + .build(); + System.out.println(event); // TODO: Ati + logEvent.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); + } +} diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index ab21551f5a..854dc9504c 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -34,7 +34,9 @@ import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.binding.kafka.config.KafkaSaslConfig; +import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaBinding; import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaConfiguration; +import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaEventContext; import io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaScramMechanism; import io.aklivity.zilla.runtime.binding.kafka.internal.types.String16FW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.RequestHeaderFW; @@ -44,6 +46,8 @@ import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeMechanismResponseFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeRequestFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeResponseFW; +import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.DataFW; import io.aklivity.zilla.runtime.engine.EngineContext; @@ -82,6 +86,7 @@ public abstract class KafkaClientSaslHandshaker private final SaslHandshakeResponseFW saslHandshakeResponseRO = new SaslHandshakeResponseFW(); private final SaslHandshakeMechanismResponseFW saslHandshakeMechanismResponseRO = new SaslHandshakeMechanismResponseFW(); private final SaslAuthenticateResponseFW saslAuthenticateResponseRO = new SaslAuthenticateResponseFW(); + private final KafkaEventContext event; private KafkaSaslClientDecoder decodeSaslPlainAuthenticate = this::decodeSaslPlainAuthenticate; private KafkaSaslClientDecoder decodeSaslScramAuthenticateFirst = this::decodeSaslScramAuthenticateFirst; @@ -109,6 +114,7 @@ public KafkaClientSaslHandshaker( this.supplyReplyId = context::supplyReplyId; this.writeBuffer = new UnsafeBuffer(new byte[context.writeBuffer().capacity()]); this.nonceSupplier = config.nonceSupplier(); + this.event = new KafkaEventContext(context.supplyTypeId(KafkaBinding.NAME), context); } public abstract class KafkaSaslClient @@ -656,6 +662,10 @@ private int decodeSaslPlainAuthenticate( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); + event.authorization( + errorCode == ERROR_NONE ? Result.SUCCESS : Result.FAILURE, + errorCode == ERROR_NONE ? Level.INFO : Level.WARNING, + traceId, client.routedId, client.initialId); progress = authenticateResponse.limit(); @@ -714,11 +724,13 @@ private int decodeSaslScramAuthenticateFirst( client.decodeSaslAuthenticate = decodeSaslScramAuthenticateFinal; client.onDecodeSaslResponse(traceId); client.onDecodeSaslHandshakeResponse(traceId, authorization, ERROR_NONE); + event.authorization(Result.SUCCESS, Level.INFO, traceId, client.routedId, client.initialId); } else { client.onDecodeSaslResponse(traceId); client.onDecodeSaslAuthenticateResponse(traceId, authorization, ERROR_SASL_AUTHENTICATION_FAILED); + event.authorization(Result.FAILURE, Level.WARNING, traceId, client.routedId, client.initialId); } } } diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index b9bc62e50c..8973d2b9c4 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -519,4 +519,28 @@ scope kafka int32 index; } } + + scope event + { + enum KafkaEventType (uint8) + { + AUTHORIZATION (1) + } + + enum Result (uint8) + { + SUCCESS (0), + FAILURE (1) + } + + struct KafkaBindingEvent extends core::event::BindingEvent + { + Result result; + } + + union KafkaEvent switch (KafkaEventType) + { + case AUTHORIZATION: KafkaBindingEvent authorization; + } + } } From d304db7e243d52436a8513cffd3b1ecbbb3bc6e6 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 26 Jan 2024 16:16:21 +0100 Subject: [PATCH 017/167] WIP kafka apiversion --- .../kafka/internal/KafkaEventContext.java | 17 +++++++++++++++++ .../stream/KafkaClientProduceFactory.java | 10 ++++++++++ .../src/main/resources/META-INF/zilla/kafka.idl | 4 +++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 5b8de0479e..3f9e4ec7fe 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -63,4 +63,21 @@ public void authorization( System.out.println(event); // TODO: Ati logEvent.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } + + public void apiVersion( + Result result, + Level level, + long traceId) + { + KafkaEventFW event = kafkaEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .apiVersion(e -> e + .level(l -> l.set(level)) + .traceId(traceId) + .result(r -> r.set(result)) + ) + .build(); + System.out.println(event); // TODO: Ati + logEvent.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); + } } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index b2fb009d15..54b7d85ad3 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -41,6 +41,7 @@ import io.aklivity.zilla.runtime.binding.kafka.config.KafkaSaslConfig; import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaBinding; import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaConfiguration; +import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaEventContext; import io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaBindingConfig; import io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaRouteConfig; import io.aklivity.zilla.runtime.binding.kafka.internal.types.Array32FW; @@ -62,6 +63,8 @@ import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.produce.ProduceResponseTrailerFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.produce.ProduceTopicRequestFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.produce.ProduceTopicResponseFW; +import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Level; +import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.DataFW; @@ -105,6 +108,7 @@ public final class KafkaClientProduceFactory extends KafkaClientSaslHandshaker i private static final int RECORD_LENGTH_MAX = 5; // varint32(max_value) private static final int ERROR_NONE = 0; + private static final int ERROR_UNSUPPORTED_VERSION = 35; private static final int SIGNAL_NEXT_REQUEST = 1; @@ -191,6 +195,7 @@ public final class KafkaClientProduceFactory extends KafkaClientSaslHandshaker i private final int decodeMaxBytes; private final int encodeMaxBytes; private final CRC32C crc32c; + private final KafkaEventContext event; public KafkaClientProduceFactory( KafkaConfiguration config, @@ -216,6 +221,7 @@ public KafkaClientProduceFactory( this.encodeMaxBytes = Math.min(config.clientProduceMaxBytes(), encodePool.slotCapacity() - PRODUCE_REQUEST_RECORDS_OFFSET_MAX); this.crc32c = new CRC32C(); + this.event = new KafkaEventContext(kafkaTypeId, context); } @Override @@ -792,6 +798,10 @@ private int decodeProducePartition( final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); + if (errorCode == ERROR_UNSUPPORTED_VERSION) + { + event.apiVersion(Result.FAILURE, Level.ERROR, traceId); + } progress = partition.limit(); diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index 8973d2b9c4..9c8b14464e 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -524,7 +524,8 @@ scope kafka { enum KafkaEventType (uint8) { - AUTHORIZATION (1) + AUTHORIZATION (1), + API_VERSION (2) } enum Result (uint8) @@ -541,6 +542,7 @@ scope kafka union KafkaEvent switch (KafkaEventType) { case AUTHORIZATION: KafkaBindingEvent authorization; + case API_VERSION: KafkaBindingEvent apiVersion; } } } From 5d3d78b49cbca9d1c38e2c6e16fefca2d2d9185d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 29 Jan 2024 10:32:51 +0100 Subject: [PATCH 018/167] mv schmea_registry.idl --- incubator/catalog-schema-registry.spec/pom.xml | 2 +- .../META-INF/zilla/{schemaregistry.idl => schema_registry.idl} | 2 +- incubator/catalog-schema-registry/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/{schemaregistry.idl => schema_registry.idl} (98%) diff --git a/incubator/catalog-schema-registry.spec/pom.xml b/incubator/catalog-schema-registry.spec/pom.xml index 63dd135cac..85398279c4 100644 --- a/incubator/catalog-schema-registry.spec/pom.xml +++ b/incubator/catalog-schema-registry.spec/pom.xml @@ -68,7 +68,7 @@ flyweight-maven-plugin ${project.version} - core schemaregistry + core schema_registry io.aklivity.zilla.specs.catalog.schema.registry.internal.types diff --git a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schemaregistry.idl b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl similarity index 98% rename from incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schemaregistry.idl rename to incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl index e9e1218302..489ec7e690 100644 --- a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schemaregistry.idl +++ b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl @@ -12,7 +12,7 @@ * WARRANTIES OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -scope schemaregistry +scope schema_registry { scope event { diff --git a/incubator/catalog-schema-registry/pom.xml b/incubator/catalog-schema-registry/pom.xml index 99b6b89b31..ac7abc3f80 100644 --- a/incubator/catalog-schema-registry/pom.xml +++ b/incubator/catalog-schema-registry/pom.xml @@ -76,7 +76,7 @@ flyweight-maven-plugin ${project.version} - core schemaregistry + core schema_registry io.aklivity.zilla.runtime.catalog.schema.registry.internal.types From 4b86a9307c098c34c8f62fb917bc51bc43ab1eff Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 29 Jan 2024 10:41:47 +0100 Subject: [PATCH 019/167] WIP fix rm Result --- .../META-INF/zilla/schema_registry.idl | 17 +++------------ .../SchemaRegistryCatalogHandler.java | 6 ++---- .../internal/SchemaRegistryEventContext.java | 7 ++----- .../http/internal/HttpEventContext.java | 6 ++---- .../internal/stream/HttpServerFactory.java | 4 ++-- .../kafka/internal/KafkaEventContext.java | 6 ++---- .../stream/KafkaClientProduceFactory.java | 3 +-- .../binding/tcp/internal/TcpEventContext.java | 7 ++----- .../tcp/internal/stream/TcpClientFactory.java | 3 +-- .../binding/tls/internal/TlsEventContext.java | 4 ++-- .../tls/internal/stream/TlsClientFactory.java | 10 ++++----- .../tls/internal/stream/TlsServerFactory.java | 10 ++++----- .../main/resources/META-INF/zilla/http.idl | 10 +++------ .../main/resources/META-INF/zilla/kafka.idl | 8 +++---- .../main/resources/META-INF/zilla/mqtt.idl | 6 +----- .../main/resources/META-INF/zilla/proxy.idl | 21 +++++++++---------- 16 files changed, 47 insertions(+), 81 deletions(-) diff --git a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl index 489ec7e690..80d9bc9a3d 100644 --- a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl +++ b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl @@ -18,21 +18,10 @@ scope schema_registry { enum SchemaRegistryEventType (uint8) { - REMOTE_ACCESS (1) + REMOTE_ACCESS_FAILURE (1) } - enum Result (uint8) - { - SUCCESS (0), - FAILURE (1) - } - - struct SchemaRegistryCatalogEvent extends core::event::CatalogEvent - { - Result result; - } - - struct SchemaRegistryRemoteAccessEvent extends SchemaRegistryCatalogEvent + struct SchemaRegistryRemoteAccessFailure extends core::event::CatalogEvent { string16 url; string8 method; @@ -41,7 +30,7 @@ scope schema_registry union SchemaRegistryEvent switch (SchemaRegistryEventType) { - case REMOTE_ACCESS: SchemaRegistryRemoteAccessEvent remoteAccess; + case REMOTE_ACCESS_FAILURE: SchemaRegistryRemoteAccessFailure remoteAccessFailure; } } } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java index ab6b4e23bf..9e09780091 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java @@ -26,7 +26,6 @@ import io.aklivity.zilla.runtime.catalog.schema.registry.internal.config.SchemaRegistryOptionsConfig; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.serializer.RegisterSchemaRequest; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Level; -import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.catalog.CatalogHandler; @@ -149,14 +148,13 @@ private String sendHttpRequest( } else { - event.remoteAccess(Result.FAILURE, Level.ERROR, httpRequest.uri().toString(), httpRequest.method(), - response.statusCode()); + event.remoteAccessFailure(Level.ERROR, httpRequest.uri().toString(), httpRequest.method(), response.statusCode()); } return responseBody; } catch (Exception ex) { - event.remoteAccess(Result.FAILURE, Level.ERROR, httpRequest.uri().toString(), httpRequest.method(), -1); + event.remoteAccessFailure(Level.ERROR, httpRequest.uri().toString(), httpRequest.method(), -1); ex.printStackTrace(System.out); } return null; diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index ed6b98c054..5ee5982cbb 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -20,7 +20,6 @@ import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Level; -import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Result; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.SchemaRegistryEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -41,8 +40,7 @@ public SchemaRegistryEventContext( this.logEvent = context::logEvent; } - public void remoteAccess( - Result result, + public void remoteAccessFailure( Level level, String url, String method, @@ -50,9 +48,8 @@ public void remoteAccess( { SchemaRegistryEventFW event = schemaRegistryEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .remoteAccess(e -> e + .remoteAccessFailure(e -> e .level(l -> l.set(level)) - .result(r -> r.set(result)) .url(url) .method(method) .status((short) status) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index fcbc2571bd..e36e6a3ca4 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -43,8 +43,7 @@ public HttpEventContext( this.logEvent = context::logEvent; } - public void accessControl( - Result result, + public void accessControlFailure( Level level, long traceId, long routedId, @@ -52,12 +51,11 @@ public void accessControl( { HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .accessControl(e -> e + .accessControlFailure(e -> e .level(l -> l.set(level)) .traceId(traceId) .routedId(routedId) .initialId(initialId) - .result(r -> r.set(result)) ) .build(); System.out.println(event); // TODO: Ati diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index b4a8f4e8df..15bcecfd7e 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1034,7 +1034,7 @@ else if (limit > endOfMethodLimit) } else if (!isCorsRequestAllowed(server.binding, headers)) { - event.accessControl(Result.FAILURE, Level.WARNING, traceId, server.routedId, server.initialId); + event.accessControlFailure(Level.WARNING, traceId, server.routedId, server.initialId); server.onDecodeHeadersError(traceId, authorization, response403); server.decoder = decodeIgnore; } @@ -4855,7 +4855,7 @@ else if (headersDecoder.httpError()) } else if (!isCorsRequestAllowed(binding, headers)) { - event.accessControl(Result.FAILURE, Level.WARNING, traceId, routedId, initialId); + event.accessControlFailure(Level.WARNING, traceId, routedId, initialId); doEncodeHeaders(traceId, authorization, streamId, headers403, true); } else diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 3f9e4ec7fe..8d24a792b8 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -64,17 +64,15 @@ public void authorization( logEvent.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } - public void apiVersion( - Result result, + public void apiVersionRejection( Level level, long traceId) { KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .apiVersion(e -> e + .apiVersionRejection(e -> e .level(l -> l.set(level)) .traceId(traceId) - .result(r -> r.set(result)) ) .build(); System.out.println(event); // TODO: Ati diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index 54b7d85ad3..ec6da2bc53 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -64,7 +64,6 @@ import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.produce.ProduceTopicRequestFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.produce.ProduceTopicResponseFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Level; -import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.DataFW; @@ -800,7 +799,7 @@ private int decodeProducePartition( final int errorCode = partition.errorCode(); if (errorCode == ERROR_UNSUPPORTED_VERSION) { - event.apiVersion(Result.FAILURE, Level.ERROR, traceId); + event.apiVersionRejection(Level.ERROR, traceId); } progress = partition.limit(); diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 5c831bac90..5da98d8ac6 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -22,7 +22,6 @@ import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.ProxyEventFW; -import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -43,8 +42,7 @@ public TcpEventContext( this.logEvent = context::logEvent; } - public void remoteAccess( - Result result, + public void remoteAccessFailure( Level level, long traceId, long routedId, @@ -53,12 +51,11 @@ public void remoteAccess( { ProxyEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .remoteAccess(e -> e + .remoteAccessFailure(e -> e .level(l -> l.set(level)) .traceId(traceId) .routedId(routedId) .initialId(initialId) - .result(r -> r.set(result)) .address(address) ) .build(); diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 4d72452477..baaf73931b 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -49,7 +49,6 @@ import io.aklivity.zilla.runtime.binding.tcp.internal.types.Flyweight; import io.aklivity.zilla.runtime.binding.tcp.internal.types.OctetsFW; import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Level; -import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.DataFW; @@ -321,7 +320,7 @@ private void onNetRejected( { final long traceId = supplyTraceId.getAsLong(); String address = remoteAddress == null ? null : remoteAddress.toString(); - event.remoteAccess(Result.FAILURE, Level.ERROR, traceId, routedId, initialId, address); + event.remoteAccessFailure(Level.ERROR, traceId, routedId, initialId, address); cleanup(traceId); } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 72b789b589..c507526e77 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -43,14 +43,14 @@ public TlsEventContext( this.logEvent = context::logEvent; } - public void tls( + public void tlsFailure( Result result, Level level, long traceId) { ProxyEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .tls(e -> e + .tlsFailure(e -> e .level(l -> l.set(level)) .traceId(traceId) .result(r -> r.set(result)) diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index 27044c378a..84679e01a8 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -622,7 +622,7 @@ private int decodeNotHandshaking( } catch (SSLException ex) { - event.tls(Result.FAILURE, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -786,7 +786,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException ex) { - event.tls(Result.FAILURE, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -1629,7 +1629,7 @@ private void onNetSignalHandshakeTimeout( final long traceId = signal.traceId(); cleanupNet(traceId); - event.tls(Result.HANDSHAKE_TIMEOUT, Level.ERROR, traceId); + event.tlsFailure(Result.HANDSHAKE_TIMEOUT, Level.ERROR, traceId); decoder = decodeIgnoreAll; } } @@ -1650,7 +1650,7 @@ private void doNetBegin( } catch (SSLException ex) { - event.tls(Result.FAILURE, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); cleanupNet(traceId); } @@ -2033,7 +2033,7 @@ private void doEncodeWrap( } catch (SSLException ex) { - event.tls(Result.FAILURE, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); cleanupNet(traceId); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index 8d413a6c34..95e66d9e29 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -533,7 +533,7 @@ private int decodeBeforeHandshake( } catch (SSLException | RuntimeException ex) { - event.tls(Result.FAILURE, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -652,7 +652,7 @@ private int decodeNotHandshaking( } catch (SSLException | RuntimeException ex) { - event.tls(Result.FAILURE, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -834,7 +834,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException | RuntimeException ex) { - event.tls(Result.FAILURE, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); server.doEncodeWrapIfNecessary(traceId, budgetId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; @@ -1313,7 +1313,7 @@ private void onNetSignalHandshakeTimeout( handshakeTimeoutFutureId = NO_CANCEL_ID; cleanupNet(traceId); - event.tls(Result.HANDSHAKE_TIMEOUT, Level.ERROR, traceId); + event.tlsFailure(Result.HANDSHAKE_TIMEOUT, Level.ERROR, traceId); decoder = decodeIgnoreAll; } } @@ -1690,7 +1690,7 @@ private void doEncodeWrap( } catch (SSLException | RuntimeException ex) { - event.tls(Result.FAILURE, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); cleanupNet(traceId); } } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 8217779537..6a9687d10b 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -55,7 +55,7 @@ scope http enum HttpEventType (uint8) { AUTHORIZATION (1), - ACCESS_CONTROL (2) + ACCESS_CONTROL_FAILURE (2) } enum Result (uint8) @@ -64,20 +64,16 @@ scope http FAILURE (1) } - struct HttpBindingEvent extends core::event::BindingEvent + struct HttpAuthorizationEvent extends core::event::BindingEvent { Result result; - } - - struct HttpAuthorizationEvent extends HttpBindingEvent - { string8 identity; } union HttpEvent switch (HttpEventType) { - case ACCESS_CONTROL: HttpBindingEvent accessControl; case AUTHORIZATION: HttpAuthorizationEvent authorization; + case ACCESS_CONTROL_FAILURE: core::event::BindingEvent accessControlFailure; } } } diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index 9c8b14464e..1081495258 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -525,7 +525,7 @@ scope kafka enum KafkaEventType (uint8) { AUTHORIZATION (1), - API_VERSION (2) + API_VERSION_REJECTION (2) } enum Result (uint8) @@ -534,15 +534,15 @@ scope kafka FAILURE (1) } - struct KafkaBindingEvent extends core::event::BindingEvent + struct KafkaAuthorizationEvent extends core::event::BindingEvent { Result result; } union KafkaEvent switch (KafkaEventType) { - case AUTHORIZATION: KafkaBindingEvent authorization; - case API_VERSION: KafkaBindingEvent apiVersion; + case AUTHORIZATION: KafkaAuthorizationEvent authorization; + case API_VERSION_REJECTION: core::event::BindingEvent apiVersionRejection; } } } diff --git a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl index 204e81f9af..af2b0c1675 100644 --- a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl +++ b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl @@ -271,13 +271,9 @@ scope mqtt FAILURE (1) } - struct MqttBindingEvent extends core::event::BindingEvent + struct MqttAuthorizationEvent extends core::event::BindingEvent { Result result; - } - - struct MqttAuthorizationEvent extends MqttBindingEvent - { string8 identity; } diff --git a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl index aa03d207a0..ee9b3dfffa 100644 --- a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl +++ b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl @@ -132,31 +132,30 @@ scope proxy { enum ProxyEventType (uint8) { - REMOTE_ACCESS (1), - TLS (2) + REMOTE_ACCESS_FAILURE (1), + TLS_FAILURE (2) } enum Result (uint8) { - SUCCESS (0), - FAILURE (1), - HANDSHAKE_TIMEOUT (2) + HANDSHAKE_TIMEOUT (1), + UNKNOWN_ERROR (2) } - struct ProxyBindingEvent extends core::event::BindingEvent + struct ProxyRemoteAccessFailure extends core::event::BindingEvent { - Result result; + string16 address; } - struct ProxyRemoteAccessEvent extends ProxyBindingEvent + struct ProxyTlsFailure extends core::event::BindingEvent { - string16 address; + Result result; } union ProxyEvent switch (ProxyEventType) { - case REMOTE_ACCESS: ProxyRemoteAccessEvent remoteAccess; - case TLS: ProxyBindingEvent tls; + case REMOTE_ACCESS_FAILURE: ProxyRemoteAccessFailure remoteAccessFailure; + case TLS_FAILURE: ProxyTlsFailure tlsFailure; } } } From d18a716a3cd0262dd36c49f151b557c4d324b740 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 29 Jan 2024 11:52:36 +0100 Subject: [PATCH 020/167] ref lvl --- .../internal/SchemaRegistryCatalogHandler.java | 5 ++--- .../registry/internal/SchemaRegistryEventContext.java | 3 +-- .../binding/http/internal/HttpEventContext.java | 5 ++--- .../http/internal/stream/HttpServerFactory.java | 7 ++----- .../binding/kafka/internal/KafkaEventContext.java | 5 ++--- .../internal/stream/KafkaClientProduceFactory.java | 3 +-- .../internal/stream/KafkaClientSaslHandshaker.java | 6 ++---- .../binding/mqtt/internal/MqttEventContext.java | 2 +- .../mqtt/internal/stream/MqttServerFactory.java | 2 -- .../runtime/binding/tcp/internal/TcpEventContext.java | 3 +-- .../binding/tcp/internal/stream/TcpClientFactory.java | 3 +-- .../runtime/binding/tls/internal/TlsEventContext.java | 3 +-- .../binding/tls/internal/stream/TlsClientFactory.java | 11 +++++------ .../binding/tls/internal/stream/TlsServerFactory.java | 11 +++++------ 14 files changed, 26 insertions(+), 43 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java index 9e09780091..bdbe96d49c 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java @@ -25,7 +25,6 @@ import io.aklivity.zilla.runtime.catalog.schema.registry.internal.config.SchemaRegistryOptionsConfig; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.serializer.RegisterSchemaRequest; -import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Level; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.catalog.CatalogHandler; @@ -148,13 +147,13 @@ private String sendHttpRequest( } else { - event.remoteAccessFailure(Level.ERROR, httpRequest.uri().toString(), httpRequest.method(), response.statusCode()); + event.remoteAccessFailure(httpRequest.uri().toString(), httpRequest.method(), response.statusCode()); } return responseBody; } catch (Exception ex) { - event.remoteAccessFailure(Level.ERROR, httpRequest.uri().toString(), httpRequest.method(), -1); + event.remoteAccessFailure(httpRequest.uri().toString(), httpRequest.method(), -1); ex.printStackTrace(System.out); } return null; diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 5ee5982cbb..0d8e0aabd8 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -41,7 +41,6 @@ public SchemaRegistryEventContext( } public void remoteAccessFailure( - Level level, String url, String method, int status) @@ -49,7 +48,7 @@ public void remoteAccessFailure( SchemaRegistryEventFW event = schemaRegistryEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessFailure(e -> e - .level(l -> l.set(level)) + .level(l -> l.set(Level.ERROR)) .url(url) .method(method) .status((short) status) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index e36e6a3ca4..959765430b 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -44,7 +44,6 @@ public HttpEventContext( } public void accessControlFailure( - Level level, long traceId, long routedId, long initialId) @@ -52,7 +51,7 @@ public void accessControlFailure( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .accessControlFailure(e -> e - .level(l -> l.set(level)) + .level(l -> l.set(Level.WARNING)) .traceId(traceId) .routedId(routedId) .initialId(initialId) @@ -64,12 +63,12 @@ public void accessControlFailure( public void authorization( Result result, - Level level, long traceId, long routedId, long initialId, String identity) { + Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 15bcecfd7e..98acc988a5 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -118,7 +118,6 @@ import io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW; import io.aklivity.zilla.runtime.binding.http.internal.types.String16FW; import io.aklivity.zilla.runtime.binding.http.internal.types.String8FW; -import io.aklivity.zilla.runtime.binding.http.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW; @@ -1034,7 +1033,7 @@ else if (limit > endOfMethodLimit) } else if (!isCorsRequestAllowed(server.binding, headers)) { - event.accessControlFailure(Level.WARNING, traceId, server.routedId, server.initialId); + event.accessControlFailure(traceId, server.routedId, server.initialId); server.onDecodeHeadersError(traceId, authorization, response403); server.decoder = decodeIgnore; } @@ -1065,7 +1064,6 @@ else if (!isCorsRequestAllowed(server.binding, headers)) exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); event.authorization( exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, - exchangeAuth == 0 ? Level.WARNING : Level.INFO, traceId, server.routedId, server.initialId, guard.identity(authorization)); } } @@ -4855,7 +4853,7 @@ else if (headersDecoder.httpError()) } else if (!isCorsRequestAllowed(binding, headers)) { - event.accessControlFailure(Level.WARNING, traceId, routedId, initialId); + event.accessControlFailure(traceId, routedId, initialId); doEncodeHeaders(traceId, authorization, streamId, headers403, true); } else @@ -4890,7 +4888,6 @@ else if (!isCorsRequestAllowed(binding, headers)) exchangeAuth = guard.reauthorize(initialId, credentialsMatch); event.authorization( exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, - exchangeAuth == 0 ? Level.WARNING : Level.INFO, traceId, routedId, initialId, guard.identity(authorization)); } } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 8d24a792b8..c053dd216b 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -45,11 +45,11 @@ public KafkaEventContext( public void authorization( Result result, - Level level, long traceId, long routedId, long initialId) { + Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e @@ -65,13 +65,12 @@ public void authorization( } public void apiVersionRejection( - Level level, long traceId) { KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .apiVersionRejection(e -> e - .level(l -> l.set(level)) + .level(l -> l.set(Level.ERROR)) .traceId(traceId) ) .build(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index ec6da2bc53..d2c89e3d2f 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -63,7 +63,6 @@ import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.produce.ProduceResponseTrailerFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.produce.ProduceTopicRequestFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.produce.ProduceTopicResponseFW; -import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.DataFW; @@ -799,7 +798,7 @@ private int decodeProducePartition( final int errorCode = partition.errorCode(); if (errorCode == ERROR_UNSUPPORTED_VERSION) { - event.apiVersionRejection(Level.ERROR, traceId); + event.apiVersionRejection(traceId); } progress = partition.limit(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index 854dc9504c..1dedefc0ae 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -46,7 +46,6 @@ import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeMechanismResponseFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeRequestFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeResponseFW; -import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.DataFW; import io.aklivity.zilla.runtime.engine.EngineContext; @@ -664,7 +663,6 @@ private int decodeSaslPlainAuthenticate( final int errorCode = authenticateResponse.errorCode(); event.authorization( errorCode == ERROR_NONE ? Result.SUCCESS : Result.FAILURE, - errorCode == ERROR_NONE ? Level.INFO : Level.WARNING, traceId, client.routedId, client.initialId); progress = authenticateResponse.limit(); @@ -724,13 +722,13 @@ private int decodeSaslScramAuthenticateFirst( client.decodeSaslAuthenticate = decodeSaslScramAuthenticateFinal; client.onDecodeSaslResponse(traceId); client.onDecodeSaslHandshakeResponse(traceId, authorization, ERROR_NONE); - event.authorization(Result.SUCCESS, Level.INFO, traceId, client.routedId, client.initialId); + event.authorization(Result.SUCCESS, traceId, client.routedId, client.initialId); } else { client.onDecodeSaslResponse(traceId); client.onDecodeSaslAuthenticateResponse(traceId, authorization, ERROR_SASL_AUTHENTICATION_FAILED); - event.authorization(Result.FAILURE, Level.WARNING, traceId, client.routedId, client.initialId); + event.authorization(Result.FAILURE, traceId, client.routedId, client.initialId); } } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 33e3db8017..b1f9a7b3cb 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -45,12 +45,12 @@ public MqttEventContext( public void authorization( Result result, - Level level, long traceId, long routedId, long initialId, String identity) { + Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; MqttEventFW event = mqttEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index 00302a46fe..b6d016855d 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -168,7 +168,6 @@ import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttUserPropertyFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttWillV4FW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttWillV5FW; -import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.stream.BeginFW; @@ -2930,7 +2929,6 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) sessionAuth = guard.reauthorize(initialId, credentialsMatch); event.authorization( sessionAuth == 0 ? Result.FAILURE : Result.SUCCESS, - sessionAuth == 0 ? Level.WARNING : Level.INFO, traceId, routedId, initialId, guard.identity(sessionId)); } } diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 5da98d8ac6..6be6f6d4e0 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -43,7 +43,6 @@ public TcpEventContext( } public void remoteAccessFailure( - Level level, long traceId, long routedId, long initialId, @@ -52,7 +51,7 @@ public void remoteAccessFailure( ProxyEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessFailure(e -> e - .level(l -> l.set(level)) + .level(l -> l.set(Level.ERROR)) .traceId(traceId) .routedId(routedId) .initialId(initialId) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index baaf73931b..0e096cd48a 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -48,7 +48,6 @@ import io.aklivity.zilla.runtime.binding.tcp.internal.config.TcpBindingConfig; import io.aklivity.zilla.runtime.binding.tcp.internal.types.Flyweight; import io.aklivity.zilla.runtime.binding.tcp.internal.types.OctetsFW; -import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tcp.internal.types.stream.DataFW; @@ -320,7 +319,7 @@ private void onNetRejected( { final long traceId = supplyTraceId.getAsLong(); String address = remoteAddress == null ? null : remoteAddress.toString(); - event.remoteAccessFailure(Level.ERROR, traceId, routedId, initialId, address); + event.remoteAccessFailure(traceId, routedId, initialId, address); cleanup(traceId); } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index c507526e77..5af2288a46 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -45,13 +45,12 @@ public TlsEventContext( public void tlsFailure( Result result, - Level level, long traceId) { ProxyEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsFailure(e -> e - .level(l -> l.set(level)) + .level(l -> l.set(Level.ERROR)) .traceId(traceId) .result(r -> r.set(result)) ) diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index 84679e01a8..fee71b4aee 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -52,7 +52,6 @@ import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsRecordInfoFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedDataFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedInfoFW; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW; @@ -622,7 +621,7 @@ private int decodeNotHandshaking( } catch (SSLException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -786,7 +785,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -1629,7 +1628,7 @@ private void onNetSignalHandshakeTimeout( final long traceId = signal.traceId(); cleanupNet(traceId); - event.tlsFailure(Result.HANDSHAKE_TIMEOUT, Level.ERROR, traceId); + event.tlsFailure(Result.HANDSHAKE_TIMEOUT, traceId); decoder = decodeIgnoreAll; } } @@ -1650,7 +1649,7 @@ private void doNetBegin( } catch (SSLException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } @@ -2033,7 +2032,7 @@ private void doEncodeWrap( } catch (SSLException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index 95e66d9e29..1a6da333b0 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -59,7 +59,6 @@ import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsRecordInfoFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedDataFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedInfoFW; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW; @@ -533,7 +532,7 @@ private int decodeBeforeHandshake( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -652,7 +651,7 @@ private int decodeNotHandshaking( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -834,7 +833,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, traceId); server.doEncodeWrapIfNecessary(traceId, budgetId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; @@ -1313,7 +1312,7 @@ private void onNetSignalHandshakeTimeout( handshakeTimeoutFutureId = NO_CANCEL_ID; cleanupNet(traceId); - event.tlsFailure(Result.HANDSHAKE_TIMEOUT, Level.ERROR, traceId); + event.tlsFailure(Result.HANDSHAKE_TIMEOUT, traceId); decoder = decodeIgnoreAll; } } @@ -1690,7 +1689,7 @@ private void doEncodeWrap( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, Level.ERROR, traceId); + event.tlsFailure(Result.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } } From 66ea78f3f331f3c3963200fa8e8288eb471c5e12 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 29 Jan 2024 15:18:46 +0100 Subject: [PATCH 021/167] Add catalogId --- specs/engine.spec/src/main/resources/META-INF/zilla/core.idl | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index c45a413360..6cfc65b473 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -125,6 +125,7 @@ scope core struct CatalogEvent extends Event { + string8 catalogId = null; } } } From 10663a8aa2220e909024631fe71a3052a2ba66d6 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 29 Jan 2024 15:55:03 +0100 Subject: [PATCH 022/167] fix rm initialId --- .../binding/http/internal/HttpEventContext.java | 10 +++------- .../http/internal/stream/HttpServerFactory.java | 8 ++++---- .../binding/kafka/internal/KafkaEventContext.java | 6 ++---- .../internal/stream/KafkaClientSaslHandshaker.java | 6 +++--- .../binding/mqtt/internal/MqttEventContext.java | 4 +--- .../mqtt/internal/stream/MqttServerFactory.java | 2 +- .../binding/tcp/internal/TcpEventContext.java | 4 +--- .../tcp/internal/stream/TcpClientFactory.java | 2 +- .../binding/tls/internal/TlsEventContext.java | 6 +++--- .../tls/internal/stream/TlsClientFactory.java | 12 ++++++------ .../tls/internal/stream/TlsServerFactory.java | 12 ++++++------ .../src/main/resources/META-INF/zilla/proxy.idl | 4 ++-- .../src/main/resources/META-INF/zilla/core.idl | 3 +-- 13 files changed, 34 insertions(+), 45 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 959765430b..7127181f41 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -45,16 +45,14 @@ public HttpEventContext( public void accessControlFailure( long traceId, - long routedId, - long initialId) + long routedId) { HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .accessControlFailure(e -> e .level(l -> l.set(Level.WARNING)) .traceId(traceId) - .routedId(routedId) - .initialId(initialId) + .bindingId(routedId) ) .build(); System.out.println(event); // TODO: Ati @@ -65,7 +63,6 @@ public void authorization( Result result, long traceId, long routedId, - long initialId, String identity) { Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; @@ -74,8 +71,7 @@ public void authorization( .authorization(e -> e .level(l -> l.set(level)) .traceId(traceId) - .routedId(routedId) - .initialId(initialId) + .bindingId(routedId) .result(r -> r.set(result)) .identity(identity) ) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 98acc988a5..20815c71a3 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1033,7 +1033,7 @@ else if (limit > endOfMethodLimit) } else if (!isCorsRequestAllowed(server.binding, headers)) { - event.accessControlFailure(traceId, server.routedId, server.initialId); + event.accessControlFailure(traceId, server.routedId); server.onDecodeHeadersError(traceId, authorization, response403); server.decoder = decodeIgnore; } @@ -1064,7 +1064,7 @@ else if (!isCorsRequestAllowed(server.binding, headers)) exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); event.authorization( exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, - traceId, server.routedId, server.initialId, guard.identity(authorization)); + traceId, server.routedId, guard.identity(authorization)); } } @@ -4853,7 +4853,7 @@ else if (headersDecoder.httpError()) } else if (!isCorsRequestAllowed(binding, headers)) { - event.accessControlFailure(traceId, routedId, initialId); + event.accessControlFailure(traceId, routedId); doEncodeHeaders(traceId, authorization, streamId, headers403, true); } else @@ -4888,7 +4888,7 @@ else if (!isCorsRequestAllowed(binding, headers)) exchangeAuth = guard.reauthorize(initialId, credentialsMatch); event.authorization( exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, - traceId, routedId, initialId, guard.identity(authorization)); + traceId, routedId, guard.identity(authorization)); } } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index c053dd216b..9e516665a1 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -46,8 +46,7 @@ public KafkaEventContext( public void authorization( Result result, long traceId, - long routedId, - long initialId) + long routedId) { Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; KafkaEventFW event = kafkaEventRW @@ -55,8 +54,7 @@ public void authorization( .authorization(e -> e .level(l -> l.set(level)) .traceId(traceId) - .routedId(routedId) - .initialId(initialId) + .bindingId(routedId) .result(r -> r.set(result)) ) .build(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index 1dedefc0ae..9f3ca1f4c8 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -663,7 +663,7 @@ private int decodeSaslPlainAuthenticate( final int errorCode = authenticateResponse.errorCode(); event.authorization( errorCode == ERROR_NONE ? Result.SUCCESS : Result.FAILURE, - traceId, client.routedId, client.initialId); + traceId, client.routedId); progress = authenticateResponse.limit(); @@ -722,13 +722,13 @@ private int decodeSaslScramAuthenticateFirst( client.decodeSaslAuthenticate = decodeSaslScramAuthenticateFinal; client.onDecodeSaslResponse(traceId); client.onDecodeSaslHandshakeResponse(traceId, authorization, ERROR_NONE); - event.authorization(Result.SUCCESS, traceId, client.routedId, client.initialId); + event.authorization(Result.SUCCESS, traceId, client.routedId); } else { client.onDecodeSaslResponse(traceId); client.onDecodeSaslAuthenticateResponse(traceId, authorization, ERROR_SASL_AUTHENTICATION_FAILED); - event.authorization(Result.FAILURE, traceId, client.routedId, client.initialId); + event.authorization(Result.FAILURE, traceId, client.routedId); } } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index b1f9a7b3cb..525587cc4e 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -47,7 +47,6 @@ public void authorization( Result result, long traceId, long routedId, - long initialId, String identity) { Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; @@ -56,8 +55,7 @@ public void authorization( .authorization(e -> e .level(l -> l.set(level)) .traceId(traceId) - .routedId(routedId) - .initialId(initialId) + .bindingId(routedId) .result(r -> r.set(result)) .identity(identity) ) diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index b6d016855d..049b206f6e 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -2929,7 +2929,7 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) sessionAuth = guard.reauthorize(initialId, credentialsMatch); event.authorization( sessionAuth == 0 ? Result.FAILURE : Result.SUCCESS, - traceId, routedId, initialId, guard.identity(sessionId)); + traceId, routedId, guard.identity(sessionId)); } } diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 6be6f6d4e0..7c61d7412a 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -45,7 +45,6 @@ public TcpEventContext( public void remoteAccessFailure( long traceId, long routedId, - long initialId, String address) { ProxyEventFW event = proxyEventRW @@ -53,8 +52,7 @@ public void remoteAccessFailure( .remoteAccessFailure(e -> e .level(l -> l.set(Level.ERROR)) .traceId(traceId) - .routedId(routedId) - .initialId(initialId) + .bindingId(routedId) .address(address) ) .build(); diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 0e096cd48a..df4ecd7e23 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -319,7 +319,7 @@ private void onNetRejected( { final long traceId = supplyTraceId.getAsLong(); String address = remoteAddress == null ? null : remoteAddress.toString(); - event.remoteAccessFailure(traceId, routedId, initialId, address); + event.remoteAccessFailure(traceId, routedId, address); cleanup(traceId); } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 5af2288a46..816824f6f0 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -22,7 +22,7 @@ import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.tls.internal.types.event.ProxyEventFW; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Result; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsError; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -44,7 +44,7 @@ public TlsEventContext( } public void tlsFailure( - Result result, + TlsError error, long traceId) { ProxyEventFW event = proxyEventRW @@ -52,7 +52,7 @@ public void tlsFailure( .tlsFailure(e -> e .level(l -> l.set(Level.ERROR)) .traceId(traceId) - .result(r -> r.set(result)) + .error(r -> r.set(error)) ) .build(); System.out.println(event); // TODO: Ati diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index fee71b4aee..3b19840c4f 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -52,7 +52,7 @@ import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsRecordInfoFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedDataFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedInfoFW; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Result; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsError; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.DataFW; @@ -621,7 +621,7 @@ private int decodeNotHandshaking( } catch (SSLException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, traceId); + event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -785,7 +785,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, traceId); + event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -1628,7 +1628,7 @@ private void onNetSignalHandshakeTimeout( final long traceId = signal.traceId(); cleanupNet(traceId); - event.tlsFailure(Result.HANDSHAKE_TIMEOUT, traceId); + event.tlsFailure(TlsError.HANDSHAKE_TIMEOUT, traceId); decoder = decodeIgnoreAll; } } @@ -1649,7 +1649,7 @@ private void doNetBegin( } catch (SSLException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, traceId); + event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } @@ -2032,7 +2032,7 @@ private void doEncodeWrap( } catch (SSLException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, traceId); + event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index 1a6da333b0..3d22432b35 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -59,7 +59,7 @@ import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsRecordInfoFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedDataFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedInfoFW; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Result; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsError; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.DataFW; @@ -532,7 +532,7 @@ private int decodeBeforeHandshake( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, traceId); + event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -651,7 +651,7 @@ private int decodeNotHandshaking( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, traceId); + event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -833,7 +833,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, traceId); + event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); server.doEncodeWrapIfNecessary(traceId, budgetId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; @@ -1312,7 +1312,7 @@ private void onNetSignalHandshakeTimeout( handshakeTimeoutFutureId = NO_CANCEL_ID; cleanupNet(traceId); - event.tlsFailure(Result.HANDSHAKE_TIMEOUT, traceId); + event.tlsFailure(TlsError.HANDSHAKE_TIMEOUT, traceId); decoder = decodeIgnoreAll; } } @@ -1689,7 +1689,7 @@ private void doEncodeWrap( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(Result.UNKNOWN_ERROR, traceId); + event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } } diff --git a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl index ee9b3dfffa..d7540a5447 100644 --- a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl +++ b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl @@ -136,7 +136,7 @@ scope proxy TLS_FAILURE (2) } - enum Result (uint8) + enum TlsError (uint8) { HANDSHAKE_TIMEOUT (1), UNKNOWN_ERROR (2) @@ -149,7 +149,7 @@ scope proxy struct ProxyTlsFailure extends core::event::BindingEvent { - Result result; + TlsError error; } union ProxyEvent switch (ProxyEventType) diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index 6cfc65b473..63b4a401e5 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -119,8 +119,7 @@ scope core struct BindingEvent extends Event { - int64 routedId = 0; - int64 initialId = 0; + int64 bindingId = 0; } struct CatalogEvent extends Event From adba065489d24777abef51d7525dcd7c13bfcf7c Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 30 Jan 2024 09:23:32 +0100 Subject: [PATCH 023/167] fix 1 --- specs/engine.spec/src/main/resources/META-INF/zilla/core.idl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index 63b4a401e5..d4b35dfe41 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -124,7 +124,7 @@ scope core struct CatalogEvent extends Event { - string8 catalogId = null; + int64 catalogId = 0; } } } From 5504201517ada242131572aa44e55ce3a293aed6 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 30 Jan 2024 09:31:52 +0100 Subject: [PATCH 024/167] fix 2 --- .../registry/internal/SchemaRegistryEventContext.java | 2 -- .../runtime/binding/http/internal/HttpEventContext.java | 4 ---- .../runtime/binding/kafka/internal/KafkaEventContext.java | 4 ---- .../runtime/binding/mqtt/internal/MqttEventContext.java | 3 --- .../runtime/binding/tcp/internal/TcpEventContext.java | 2 -- .../runtime/binding/tls/internal/TlsEventContext.java | 2 -- .../src/main/resources/META-INF/zilla/core.idl | 8 -------- 7 files changed, 25 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 0d8e0aabd8..af8b8ce79e 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -19,7 +19,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.Level; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.types.event.SchemaRegistryEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -48,7 +47,6 @@ public void remoteAccessFailure( SchemaRegistryEventFW event = schemaRegistryEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessFailure(e -> e - .level(l -> l.set(Level.ERROR)) .url(url) .method(method) .status((short) status) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 7127181f41..c44c7859d8 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -21,7 +21,6 @@ import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; -import io.aklivity.zilla.runtime.binding.http.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -50,7 +49,6 @@ public void accessControlFailure( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .accessControlFailure(e -> e - .level(l -> l.set(Level.WARNING)) .traceId(traceId) .bindingId(routedId) ) @@ -65,11 +63,9 @@ public void authorization( long routedId, String identity) { - Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e - .level(l -> l.set(level)) .traceId(traceId) .bindingId(routedId) .result(r -> r.set(result)) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 9e516665a1..46e713ac51 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -21,7 +21,6 @@ import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.KafkaEventFW; -import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -48,11 +47,9 @@ public void authorization( long traceId, long routedId) { - Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e - .level(l -> l.set(level)) .traceId(traceId) .bindingId(routedId) .result(r -> r.set(result)) @@ -68,7 +65,6 @@ public void apiVersionRejection( KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .apiVersionRejection(e -> e - .level(l -> l.set(Level.ERROR)) .traceId(traceId) ) .build(); diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 525587cc4e..32856f3b54 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -20,7 +20,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.MqttEventFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; @@ -49,11 +48,9 @@ public void authorization( long routedId, String identity) { - Level level = result == Result.FAILURE ? Level.WARNING : Level.INFO; MqttEventFW event = mqttEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e - .level(l -> l.set(level)) .traceId(traceId) .bindingId(routedId) .result(r -> r.set(result)) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 7c61d7412a..ef8e2b3050 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -20,7 +20,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.ProxyEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -50,7 +49,6 @@ public void remoteAccessFailure( ProxyEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessFailure(e -> e - .level(l -> l.set(Level.ERROR)) .traceId(traceId) .bindingId(routedId) .address(address) diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 816824f6f0..789efba194 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -20,7 +20,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.Level; import io.aklivity.zilla.runtime.binding.tls.internal.types.event.ProxyEventFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsError; import io.aklivity.zilla.runtime.engine.EngineContext; @@ -50,7 +49,6 @@ public void tlsFailure( ProxyEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsFailure(e -> e - .level(l -> l.set(Level.ERROR)) .traceId(traceId) .error(r -> r.set(error)) ) diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index d4b35dfe41..c9c53150e2 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -103,16 +103,8 @@ scope core scope event { - enum Level - { - INFO, - WARNING, - ERROR - } - struct Event { - Level level; int64 timestamp = 0; int64 traceId = 0; } From bd145f67937b67c95f104c455166e3756c65b37e Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 30 Jan 2024 09:52:40 +0100 Subject: [PATCH 025/167] fix 3 --- .../main/resources/META-INF/zilla/schema_registry.idl | 6 +++--- .../internal/SchemaRegistryCatalogContext.java | 2 +- .../internal/SchemaRegistryCatalogHandler.java | 9 ++++++--- .../registry/internal/SchemaRegistryEventContext.java | 6 ++++-- .../schema/registry/internal/SchemaRegistryIT.java | 10 +++++----- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl index 80d9bc9a3d..59da33fb3f 100644 --- a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl +++ b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl @@ -18,10 +18,10 @@ scope schema_registry { enum SchemaRegistryEventType (uint8) { - REMOTE_ACCESS_FAILURE (1) + REMOTE_ACCESS_REJECTED (1) } - struct SchemaRegistryRemoteAccessFailure extends core::event::CatalogEvent + struct SchemaRegistryRemoteAccessRejectedEvent extends core::event::CatalogEvent { string16 url; string8 method; @@ -30,7 +30,7 @@ scope schema_registry union SchemaRegistryEvent switch (SchemaRegistryEventType) { - case REMOTE_ACCESS_FAILURE: SchemaRegistryRemoteAccessFailure remoteAccessFailure; + case REMOTE_ACCESS_REJECTED: SchemaRegistryRemoteAccessRejectedEvent remoteAccessRejected; } } } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogContext.java index 164c9e4b8e..1dbfd3c22f 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogContext.java @@ -34,6 +34,6 @@ public SchemaRegistryCatalogContext( public CatalogHandler attach( CatalogConfig catalog) { - return new SchemaRegistryCatalogHandler(SchemaRegistryOptionsConfig.class.cast(catalog.options), context); + return new SchemaRegistryCatalogHandler(SchemaRegistryOptionsConfig.class.cast(catalog.options), context, catalog.id); } } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java index bdbe96d49c..6bb7013527 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java @@ -41,10 +41,12 @@ public class SchemaRegistryCatalogHandler implements CatalogHandler private final Int2ObjectCache cache; private final Int2ObjectCache schemaIdCache; private final SchemaRegistryEventContext event; + private final long catalogId; public SchemaRegistryCatalogHandler( SchemaRegistryOptionsConfig config, - EngineContext context) + EngineContext context, + long catalogId) { this.baseUrl = config.url; this.client = HttpClient.newHttpClient(); @@ -53,6 +55,7 @@ public SchemaRegistryCatalogHandler( this.cache = new Int2ObjectCache<>(1, 1024, i -> {}); this.schemaIdCache = new Int2ObjectCache<>(1, 1024, i -> {}); this.event = new SchemaRegistryEventContext(context); + this.catalogId = catalogId; } @Override @@ -147,13 +150,13 @@ private String sendHttpRequest( } else { - event.remoteAccessFailure(httpRequest.uri().toString(), httpRequest.method(), response.statusCode()); + event.remoteAccessRejected(catalogId, httpRequest.uri().toString(), httpRequest.method(), response.statusCode()); } return responseBody; } catch (Exception ex) { - event.remoteAccessFailure(httpRequest.uri().toString(), httpRequest.method(), -1); + event.remoteAccessRejected(catalogId, httpRequest.uri().toString(), httpRequest.method(), -1); ex.printStackTrace(System.out); } return null; diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index af8b8ce79e..fff3bf6003 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -39,14 +39,16 @@ public SchemaRegistryEventContext( this.logEvent = context::logEvent; } - public void remoteAccessFailure( + public void remoteAccessRejected( + long catalogId, String url, String method, int status) { SchemaRegistryEventFW event = schemaRegistryEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .remoteAccessFailure(e -> e + .remoteAccessRejected(e -> e + .catalogId(catalogId) .url(url) .method(method) .status((short) status) diff --git a/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java b/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java index 1485a0e104..c9ec65197a 100644 --- a/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java +++ b/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java @@ -62,7 +62,7 @@ public void shouldResolveSchemaViaSchemaId() throws Exception "{\"name\":\"status\",\"type\":\"string\"}]," + "\"name\":\"Event\",\"namespace\":\"io.aklivity.example\",\"type\":\"record\"}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); String schema = catalog.resolve(9); @@ -81,7 +81,7 @@ public void shouldResolveSchemaViaSubjectVersion() throws Exception "{\"name\":\"status\",\"type\":\"string\"}]," + "\"name\":\"Event\",\"namespace\":\"io.aklivity.example\",\"type\":\"record\"}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); int schemaId = catalog.resolve("items-snapshots-value", "latest"); @@ -102,7 +102,7 @@ public void shouldRegisterSchema() throws Exception String schema = "{\"type\": \"record\",\"name\": \"test\",\"fields\":[{\"type\": \"string\",\"name\": \"field1\"}," + "{\"type\": \"com.acme.Referenced\",\"name\": \"int\"}]}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); int schemaId = catalog.register("items-snapshots-value", "avro", schema); @@ -121,7 +121,7 @@ public void shouldResolveSchemaViaSchemaIdFromCache() throws Exception "{\"name\":\"status\",\"type\":\"string\"}]," + "\"name\":\"Event\",\"namespace\":\"io.aklivity.example\",\"type\":\"record\"}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); catalog.resolve(9); @@ -142,7 +142,7 @@ public void shouldResolveSchemaViaSubjectVersionFromCache() throws Exception "{\"name\":\"status\",\"type\":\"string\"}]," + "\"name\":\"Event\",\"namespace\":\"io.aklivity.example\",\"type\":\"record\"}"; - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); catalog.resolve(catalog.resolve("items-snapshots-value", "latest")); From 216263097208a8b98885a9ed04fea673983ff057 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 30 Jan 2024 09:57:19 +0100 Subject: [PATCH 026/167] fix 4 --- .../runtime/binding/kafka/internal/KafkaEventContext.java | 4 ++-- .../kafka/internal/stream/KafkaClientProduceFactory.java | 2 +- .../src/main/resources/META-INF/zilla/kafka.idl | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 46e713ac51..166c4f363e 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -59,12 +59,12 @@ public void authorization( logEvent.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } - public void apiVersionRejection( + public void apiVersionRejected( long traceId) { KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .apiVersionRejection(e -> e + .apiVersionRejected(e -> e .traceId(traceId) ) .build(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index d2c89e3d2f..b9637a9185 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -798,7 +798,7 @@ private int decodeProducePartition( final int errorCode = partition.errorCode(); if (errorCode == ERROR_UNSUPPORTED_VERSION) { - event.apiVersionRejection(traceId); + event.apiVersionRejected(traceId); } progress = partition.limit(); diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index 1081495258..cb636d1e02 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -525,7 +525,7 @@ scope kafka enum KafkaEventType (uint8) { AUTHORIZATION (1), - API_VERSION_REJECTION (2) + API_VERSION_REJECTED (2) } enum Result (uint8) @@ -542,7 +542,7 @@ scope kafka union KafkaEvent switch (KafkaEventType) { case AUTHORIZATION: KafkaAuthorizationEvent authorization; - case API_VERSION_REJECTION: core::event::BindingEvent apiVersionRejection; + case API_VERSION_REJECTED: core::event::BindingEvent apiVersionRejected; } } } From 1b9d779e0dd3972b2de21f3a3c909906b678538a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 30 Jan 2024 10:02:32 +0100 Subject: [PATCH 027/167] fix 5 --- .../zilla/runtime/binding/http/internal/HttpEventContext.java | 4 ++-- .../binding/http/internal/stream/HttpServerFactory.java | 4 ++-- .../src/main/resources/META-INF/zilla/http.idl | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index c44c7859d8..a459589710 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -42,13 +42,13 @@ public HttpEventContext( this.logEvent = context::logEvent; } - public void accessControlFailure( + public void accessDenied( long traceId, long routedId) { HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .accessControlFailure(e -> e + .accessDenied(e -> e .traceId(traceId) .bindingId(routedId) ) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 20815c71a3..7a228c88af 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1033,7 +1033,7 @@ else if (limit > endOfMethodLimit) } else if (!isCorsRequestAllowed(server.binding, headers)) { - event.accessControlFailure(traceId, server.routedId); + event.accessDenied(traceId, server.routedId); server.onDecodeHeadersError(traceId, authorization, response403); server.decoder = decodeIgnore; } @@ -4853,7 +4853,7 @@ else if (headersDecoder.httpError()) } else if (!isCorsRequestAllowed(binding, headers)) { - event.accessControlFailure(traceId, routedId); + event.accessDenied(traceId, routedId); doEncodeHeaders(traceId, authorization, streamId, headers403, true); } else diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 6a9687d10b..50e193674a 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -55,7 +55,7 @@ scope http enum HttpEventType (uint8) { AUTHORIZATION (1), - ACCESS_CONTROL_FAILURE (2) + ACCESS_DENIED (2) } enum Result (uint8) @@ -73,7 +73,7 @@ scope http union HttpEvent switch (HttpEventType) { case AUTHORIZATION: HttpAuthorizationEvent authorization; - case ACCESS_CONTROL_FAILURE: core::event::BindingEvent accessControlFailure; + case ACCESS_DENIED: core::event::BindingEvent accessDenied; } } } From f2e867b73ad9cc766c15cc17fd8043dd67148602 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 30 Jan 2024 10:49:01 +0100 Subject: [PATCH 028/167] fix 6 --- .../binding/tcp/internal/TcpEventContext.java | 4 ++-- .../tcp/internal/stream/TcpClientFactory.java | 2 +- .../binding/tls/internal/TlsEventContext.java | 4 ++-- .../tls/internal/stream/TlsClientFactory.java | 10 +++++----- .../tls/internal/stream/TlsServerFactory.java | 10 +++++----- .../src/main/resources/META-INF/zilla/proxy.idl | 12 ++++++------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index ef8e2b3050..0216c21d08 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -41,14 +41,14 @@ public TcpEventContext( this.logEvent = context::logEvent; } - public void remoteAccessFailure( + public void remoteAccessFailed( long traceId, long routedId, String address) { ProxyEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .remoteAccessFailure(e -> e + .remoteAccessFailed(e -> e .traceId(traceId) .bindingId(routedId) .address(address) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index df4ecd7e23..3b33adee33 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -319,7 +319,7 @@ private void onNetRejected( { final long traceId = supplyTraceId.getAsLong(); String address = remoteAddress == null ? null : remoteAddress.toString(); - event.remoteAccessFailure(traceId, routedId, address); + event.remoteAccessFailed(traceId, routedId, address); cleanup(traceId); } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 789efba194..cb7a45dce4 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -42,13 +42,13 @@ public TlsEventContext( this.logEvent = context::logEvent; } - public void tlsFailure( + public void tlsFailed( TlsError error, long traceId) { ProxyEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .tlsFailure(e -> e + .tlsFailed(e -> e .traceId(traceId) .error(r -> r.set(error)) ) diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index 3b19840c4f..9eec1ab601 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -621,7 +621,7 @@ private int decodeNotHandshaking( } catch (SSLException ex) { - event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -785,7 +785,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException ex) { - event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -1628,7 +1628,7 @@ private void onNetSignalHandshakeTimeout( final long traceId = signal.traceId(); cleanupNet(traceId); - event.tlsFailure(TlsError.HANDSHAKE_TIMEOUT, traceId); + event.tlsFailed(TlsError.HANDSHAKE_TIMEOUT, traceId); decoder = decodeIgnoreAll; } } @@ -1649,7 +1649,7 @@ private void doNetBegin( } catch (SSLException ex) { - event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } @@ -2032,7 +2032,7 @@ private void doEncodeWrap( } catch (SSLException ex) { - event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index 3d22432b35..440efa06c2 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -532,7 +532,7 @@ private int decodeBeforeHandshake( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -651,7 +651,7 @@ private int decodeNotHandshaking( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -833,7 +833,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); server.doEncodeWrapIfNecessary(traceId, budgetId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; @@ -1312,7 +1312,7 @@ private void onNetSignalHandshakeTimeout( handshakeTimeoutFutureId = NO_CANCEL_ID; cleanupNet(traceId); - event.tlsFailure(TlsError.HANDSHAKE_TIMEOUT, traceId); + event.tlsFailed(TlsError.HANDSHAKE_TIMEOUT, traceId); decoder = decodeIgnoreAll; } } @@ -1689,7 +1689,7 @@ private void doEncodeWrap( } catch (SSLException | RuntimeException ex) { - event.tlsFailure(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); cleanupNet(traceId); } } diff --git a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl index d7540a5447..65bfb24c50 100644 --- a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl +++ b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl @@ -132,8 +132,8 @@ scope proxy { enum ProxyEventType (uint8) { - REMOTE_ACCESS_FAILURE (1), - TLS_FAILURE (2) + REMOTE_ACCESS_FAILED (1), + TLS_FAILED (2) } enum TlsError (uint8) @@ -142,20 +142,20 @@ scope proxy UNKNOWN_ERROR (2) } - struct ProxyRemoteAccessFailure extends core::event::BindingEvent + struct ProxyRemoteAccessFailedEvent extends core::event::BindingEvent { string16 address; } - struct ProxyTlsFailure extends core::event::BindingEvent + struct ProxyTlsFailed extends core::event::BindingEvent { TlsError error; } union ProxyEvent switch (ProxyEventType) { - case REMOTE_ACCESS_FAILURE: ProxyRemoteAccessFailure remoteAccessFailure; - case TLS_FAILURE: ProxyTlsFailure tlsFailure; + case REMOTE_ACCESS_FAILED: ProxyRemoteAccessFailedEvent remoteAccessFailed; + case TLS_FAILED: ProxyTlsFailed tlsFailed; } } } From 6af5130b702c578ab147a23612d3ae7cc84edb5f Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 30 Jan 2024 11:10:02 +0100 Subject: [PATCH 029/167] fix 7 --- .../binding/tls/internal/TlsEventContext.java | 33 +++++++++++++++++++ .../tls/internal/stream/TlsClientFactory.java | 10 +++--- .../tls/internal/stream/TlsServerFactory.java | 10 +++--- .../main/resources/META-INF/zilla/proxy.idl | 7 ++-- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index cb7a45dce4..992f2cb7b2 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -17,6 +17,11 @@ import java.nio.ByteBuffer; +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLKeyException; +import javax.net.ssl.SSLPeerUnverifiedException; +import javax.net.ssl.SSLProtocolException; + import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -56,4 +61,32 @@ public void tlsFailed( System.out.println(event); // TODO: Ati logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); } + + public void tlsFailed( + Exception ex, + long traceId) + { + TlsError error; + if (ex instanceof SSLProtocolException) + { + error = TlsError.PROTOCOL_ERROR; + } + else if (ex instanceof SSLKeyException) + { + error = TlsError.KEY_ERROR; + } + else if (ex instanceof SSLHandshakeException) + { + error = TlsError.HANDSHAKE_ERROR; + } + else if (ex instanceof SSLPeerUnverifiedException) + { + error = TlsError.PEER_UNVERIFIED_ERROR; + } + else + { + error = TlsError.UNSPECIFIED_ERROR; + } + tlsFailed(error, traceId); + } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index 9eec1ab601..50dc37bd64 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -621,7 +621,7 @@ private int decodeNotHandshaking( } catch (SSLException ex) { - event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(ex, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -785,7 +785,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException ex) { - event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(ex, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -1628,7 +1628,7 @@ private void onNetSignalHandshakeTimeout( final long traceId = signal.traceId(); cleanupNet(traceId); - event.tlsFailed(TlsError.HANDSHAKE_TIMEOUT, traceId); + event.tlsFailed(TlsError.HANDSHAKE_ERROR, traceId); decoder = decodeIgnoreAll; } } @@ -1649,7 +1649,7 @@ private void doNetBegin( } catch (SSLException ex) { - event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(TlsError.HANDSHAKE_ERROR, traceId); cleanupNet(traceId); } @@ -2032,7 +2032,7 @@ private void doEncodeWrap( } catch (SSLException ex) { - event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(ex, traceId); cleanupNet(traceId); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index 440efa06c2..4c4402cc8a 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -532,7 +532,7 @@ private int decodeBeforeHandshake( } catch (SSLException | RuntimeException ex) { - event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(ex, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -651,7 +651,7 @@ private int decodeNotHandshaking( } catch (SSLException | RuntimeException ex) { - event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(ex, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -833,7 +833,7 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLException | RuntimeException ex) { - event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(ex, traceId); server.doEncodeWrapIfNecessary(traceId, budgetId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; @@ -1312,7 +1312,7 @@ private void onNetSignalHandshakeTimeout( handshakeTimeoutFutureId = NO_CANCEL_ID; cleanupNet(traceId); - event.tlsFailed(TlsError.HANDSHAKE_TIMEOUT, traceId); + event.tlsFailed(TlsError.HANDSHAKE_ERROR, traceId); decoder = decodeIgnoreAll; } } @@ -1689,7 +1689,7 @@ private void doEncodeWrap( } catch (SSLException | RuntimeException ex) { - event.tlsFailed(TlsError.UNKNOWN_ERROR, traceId); + event.tlsFailed(ex, traceId); cleanupNet(traceId); } } diff --git a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl index 65bfb24c50..d8df7c7236 100644 --- a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl +++ b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl @@ -138,8 +138,11 @@ scope proxy enum TlsError (uint8) { - HANDSHAKE_TIMEOUT (1), - UNKNOWN_ERROR (2) + PROTOCOL_ERROR (1), + KEY_ERROR (2), + HANDSHAKE_ERROR (3), + PEER_UNVERIFIED_ERROR (4), + UNSPECIFIED_ERROR (5) } struct ProxyRemoteAccessFailedEvent extends core::event::BindingEvent From 4efa893e0f89ae264b5f771bc9ab80bab9db5ff7 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 31 Jan 2024 16:30:15 +0100 Subject: [PATCH 030/167] WIP kafka api version --- .../internal/stream/KafkaClientDescribeFactory.java | 1 + .../internal/stream/KafkaClientFetchFactory.java | 2 ++ .../internal/stream/KafkaClientGroupFactory.java | 7 +++++++ .../kafka/internal/stream/KafkaClientMetaFactory.java | 2 ++ .../stream/KafkaClientOffsetCommitFactory.java | 1 + .../stream/KafkaClientOffsetFetchFactory.java | 1 + .../internal/stream/KafkaClientProduceFactory.java | 6 +----- .../internal/stream/KafkaClientSaslHandshaker.java | 11 +++++++++++ 8 files changed, 26 insertions(+), 5 deletions(-) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java index 3676b3fff5..62ae3fdcf0 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java @@ -534,6 +534,7 @@ private int decodeDescribeResponse( final String resourceName = resource.name().asString(); final int resourceError = resource.errorCode(); + checkUnsupportedVersionError(resourceError, traceId); client.onDecodeResource(traceId, client.authorization, resourceError, resourceName); // TODO: use different decoder for configs diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java index 63998ac9e7..38532b326d 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java @@ -756,6 +756,7 @@ private int decodeOffsetsPartition( final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); + checkUnsupportedVersionError(errorCode, traceId); final long partitionOffset = partition.offset$(); progress = partition.limit(); @@ -901,6 +902,7 @@ else if (length != 0) { final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); + checkUnsupportedVersionError(errorCode, traceId); client.stableOffset = partition.lastStableOffset() - 1; client.latestOffset = partition.highWatermark() - 1; diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java index 00036a309f..ba2d26ec8c 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java @@ -780,6 +780,7 @@ private int decodeDescribeResponse( final String resourceName = resource.name().asString(); final short errorCode = resource.errorCode(); + checkUnsupportedVersionError(errorCode, traceId); if (errorCode != ERROR_NONE || !client.delegate.nodeId.equals(resourceName)) { @@ -880,6 +881,7 @@ private int decodeFindCoordinatorResponse( findCoordinatorResponse.host(), findCoordinatorResponse.port()); break; default: + checkUnsupportedVersionError(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeClusterReject; break; @@ -970,6 +972,7 @@ private int decodeJoinGroupResponse( joinGroupResponseRO.tryWrap(buffer, progress, limit); final short errorCode = joinGroupResponse != null ? joinGroupResponse.errorCode() : ERROR_EXISTS; + checkUnsupportedVersionError(errorCode, traceId); if (joinGroupResponse == null) { @@ -1056,6 +1059,7 @@ private int decodeSyncGroupResponse( syncGroupResponseRO.tryWrap(buffer, progress, limit); final short errorCode = syncGroupResponse != null ? syncGroupResponse.errorCode() : ERROR_EXISTS; + checkUnsupportedVersionError(errorCode, traceId); if (syncGroupResponse == null) { @@ -1122,6 +1126,7 @@ private int decodeHeartbeatResponse( progress = heartbeatResponse.limit(); final short errorCode = heartbeatResponse.errorCode(); + checkUnsupportedVersionError(errorCode, traceId); switch (errorCode) { @@ -1199,6 +1204,7 @@ private int decodeLeaveGroupResponse( } else { + checkUnsupportedVersionError(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } @@ -1213,6 +1219,7 @@ private int decodeLeaveGroupResponse( } else { + checkUnsupportedVersionError(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java index d243e2058a..07116b40fc 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java @@ -701,6 +701,7 @@ private int decodeMetaTopic( final String topic = topicMetadata.topic().asString(); final int topicError = topicMetadata.errorCode(); + checkUnsupportedVersionError(topicError, traceId); client.onDecodeTopic(traceId, authorization, topicError, topic); @@ -765,6 +766,7 @@ private int decodeMetaPartition( } final int partitionError = partition.errorCode(); + checkUnsupportedVersionError(partitionError, traceId); final int partitionId = partition.partitionId(); final int leaderId = partition.leader(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java index 43e284dc7a..9bb620f195 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java @@ -579,6 +579,7 @@ private int decodeOffsetCommitPartition( } else { + checkUnsupportedVersionError(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeReject; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java index 9961f19c07..b1632fadf3 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java @@ -658,6 +658,7 @@ private int decodeOffsetFetchPartition( client.decoder = decodeOffsetFetchPartitions; break; default: + checkUnsupportedVersionError(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeReject; break; diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index b9637a9185..6cf7a06d29 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -106,7 +106,6 @@ public final class KafkaClientProduceFactory extends KafkaClientSaslHandshaker i private static final int RECORD_LENGTH_MAX = 5; // varint32(max_value) private static final int ERROR_NONE = 0; - private static final int ERROR_UNSUPPORTED_VERSION = 35; private static final int SIGNAL_NEXT_REQUEST = 1; @@ -796,10 +795,7 @@ private int decodeProducePartition( final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); - if (errorCode == ERROR_UNSUPPORTED_VERSION) - { - event.apiVersionRejected(traceId); - } + checkUnsupportedVersionError(errorCode, traceId); progress = partition.limit(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index 9f3ca1f4c8..391b1abc8d 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -59,6 +59,7 @@ public abstract class KafkaClientSaslHandshaker private static final short SASL_AUTHENTICATE_API_VERSION = 1; private static final int ERROR_SASL_AUTHENTICATION_FAILED = 58; private static final int ERROR_NONE = 0; + private static final int ERROR_UNSUPPORTED_VERSION = 35; private static final String CLIENT_KEY = "Client Key"; private static final String SERVER_KEY = "Server Key"; @@ -790,6 +791,16 @@ private int decodeSaslScramAuthenticateFinal( return progress; } + protected void checkUnsupportedVersionError( + int errorCode, + long traceId) + { + if (errorCode == ERROR_UNSUPPORTED_VERSION) + { + event.apiVersionRejected(traceId); + } + } + public byte[] hmac(byte[] key, byte[] bytes) { try From 3be3ed3f592d14f960770c215f3c7cee46622ca7 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 5 Feb 2024 10:55:39 +0100 Subject: [PATCH 031/167] fix --- incubator/catalog-schema-registry/pom.xml | 18 +----------------- .../registry/internal/SchemaRegistryIT.java | 10 +++++----- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/incubator/catalog-schema-registry/pom.xml b/incubator/catalog-schema-registry/pom.xml index a806f633ba..22c39b3d02 100644 --- a/incubator/catalog-schema-registry/pom.xml +++ b/incubator/catalog-schema-registry/pom.xml @@ -76,7 +76,7 @@ flyweight-maven-plugin ${project.version} - core schema_registry + core schema_registry internal io.aklivity.zilla.runtime.catalog.schema.registry.internal.types @@ -91,22 +91,6 @@ com.mycila license-maven-plugin - - ${project.groupId} - flyweight-maven-plugin - ${project.version} - - internal - io.aklivity.zilla.runtime.catalog.schema.registry.internal.types - - - - - generate - - - - maven-checkstyle-plugin diff --git a/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java b/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java index 2a58d31030..f04ed60d0b 100644 --- a/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java +++ b/incubator/catalog-schema-registry/src/test/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryIT.java @@ -36,9 +36,9 @@ import org.kaazing.k3po.junit.rules.K3poRule; import io.aklivity.zilla.runtime.catalog.schema.registry.internal.config.SchemaRegistryOptionsConfig; +import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.catalog.CatalogHandler; import io.aklivity.zilla.runtime.engine.model.function.ValueConsumer; -import io.aklivity.zilla.runtime.engine.EngineContext; public class SchemaRegistryIT { @@ -170,7 +170,7 @@ public void shouldResolveSchemaViaSubjectVersionFromCache() throws Exception @Test public void shouldVerifyMaxPadding() { - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); assertEquals(5, catalog.encodePadding()); } @@ -178,7 +178,7 @@ public void shouldVerifyMaxPadding() @Test public void shouldVerifyEncodedData() { - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); DirectBuffer data = new UnsafeBuffer(); @@ -194,7 +194,7 @@ public void shouldVerifyEncodedData() public void shouldResolveSchemaIdAndProcessData() { - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); DirectBuffer data = new UnsafeBuffer(); @@ -210,7 +210,7 @@ public void shouldResolveSchemaIdAndProcessData() @Test public void shouldResolveSchemaIdFromData() { - SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config); + SchemaRegistryCatalogHandler catalog = new SchemaRegistryCatalogHandler(config, context, 0L); DirectBuffer data = new UnsafeBuffer(); From 377ca3c7b733f90262ba0e2e802f44853ca6ffcd Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 5 Feb 2024 11:41:51 +0100 Subject: [PATCH 032/167] ref proxy.idl to tls.idl --- runtime/binding-tls/pom.xml | 2 +- .../binding/tls/internal/TlsEventContext.java | 6 +-- .../main/resources/META-INF/zilla/proxy.idl | 18 +------- .../src/main/resources/META-INF/zilla/tls.idl | 44 +++++++++++++++++++ 4 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl diff --git a/runtime/binding-tls/pom.xml b/runtime/binding-tls/pom.xml index 6b6779e140..4e4f751993 100644 --- a/runtime/binding-tls/pom.xml +++ b/runtime/binding-tls/pom.xml @@ -109,7 +109,7 @@ flyweight-maven-plugin ${project.version} - core proxy protocol + core proxy tls protocol io.aklivity.zilla.runtime.binding.tls.internal.types diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 992f2cb7b2..1dd6ac9b83 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -25,8 +25,8 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.ProxyEventFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsError; +import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -34,7 +34,7 @@ public class TlsEventContext { private static final int EVENT_BUFFER_CAPACITY = 1024; - private final ProxyEventFW.Builder proxyEventRW = new ProxyEventFW.Builder(); + private final TlsEventFW.Builder tlsEventRW = new TlsEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int typeId; private final MessageConsumer logEvent; @@ -51,7 +51,7 @@ public void tlsFailed( TlsError error, long traceId) { - ProxyEventFW event = proxyEventRW + TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsFailed(e -> e .traceId(traceId) diff --git a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl index d8df7c7236..597a238c1a 100644 --- a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl +++ b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl @@ -132,17 +132,7 @@ scope proxy { enum ProxyEventType (uint8) { - REMOTE_ACCESS_FAILED (1), - TLS_FAILED (2) - } - - enum TlsError (uint8) - { - PROTOCOL_ERROR (1), - KEY_ERROR (2), - HANDSHAKE_ERROR (3), - PEER_UNVERIFIED_ERROR (4), - UNSPECIFIED_ERROR (5) + REMOTE_ACCESS_FAILED (1) } struct ProxyRemoteAccessFailedEvent extends core::event::BindingEvent @@ -150,15 +140,9 @@ scope proxy string16 address; } - struct ProxyTlsFailed extends core::event::BindingEvent - { - TlsError error; - } - union ProxyEvent switch (ProxyEventType) { case REMOTE_ACCESS_FAILED: ProxyRemoteAccessFailedEvent remoteAccessFailed; - case TLS_FAILED: ProxyTlsFailed tlsFailed; } } } diff --git a/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl b/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl new file mode 100644 index 0000000000..b91656f357 --- /dev/null +++ b/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl @@ -0,0 +1,44 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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. + */ +scope tls +{ + scope event + { + enum TlsEventType (uint8) + { + TLS_FAILED (1) + } + + enum TlsError (uint8) + { + PROTOCOL_ERROR (1), + KEY_ERROR (2), + HANDSHAKE_ERROR (3), + PEER_UNVERIFIED_ERROR (4), + UNSPECIFIED_ERROR (5) + } + + struct TlsFailedEvent extends core::event::BindingEvent + { + TlsError error; + } + + union TlsEvent switch (TlsEventType) + { + case TLS_FAILED: TlsFailedEvent tlsFailed; + } + } +} From 45d33e4efc4d6caf7ef019a50e66b94514c10e88 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 5 Feb 2024 12:00:03 +0100 Subject: [PATCH 033/167] ref proxy.idl to tcp.idl --- runtime/binding-tcp/pom.xml | 2 +- .../src/main/resources/META-INF/zilla/tcp.idl | 35 +++++++++++++++++++ .../main/resources/META-INF/zilla/proxy.idl | 18 ---------- 3 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl diff --git a/runtime/binding-tcp/pom.xml b/runtime/binding-tcp/pom.xml index c28cdc4b4e..6753ca7a65 100644 --- a/runtime/binding-tcp/pom.xml +++ b/runtime/binding-tcp/pom.xml @@ -123,7 +123,7 @@ flyweight-maven-plugin ${project.version} - core proxy + core tcp proxy io.aklivity.zilla.runtime.binding.tcp.internal.types diff --git a/runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl b/runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl new file mode 100644 index 0000000000..d8cfd6aa86 --- /dev/null +++ b/runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl @@ -0,0 +1,35 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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. + */ +scope tcp +{ + scope event + { + enum ProxyEventType (uint8) + { + REMOTE_ACCESS_FAILED (1) + } + + struct ProxyRemoteAccessFailedEvent extends core::event::BindingEvent + { + string16 address; + } + + union ProxyEvent switch (ProxyEventType) + { + case REMOTE_ACCESS_FAILED: ProxyRemoteAccessFailedEvent remoteAccessFailed; + } + } +} diff --git a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl index 597a238c1a..7088aa8e85 100644 --- a/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl +++ b/specs/binding-proxy.spec/src/main/resources/META-INF/zilla/proxy.idl @@ -127,22 +127,4 @@ scope proxy ProxyInfo[] infos; } } - - scope event - { - enum ProxyEventType (uint8) - { - REMOTE_ACCESS_FAILED (1) - } - - struct ProxyRemoteAccessFailedEvent extends core::event::BindingEvent - { - string16 address; - } - - union ProxyEvent switch (ProxyEventType) - { - case REMOTE_ACCESS_FAILED: ProxyRemoteAccessFailedEvent remoteAccessFailed; - } - } } From ded82351cc0d13ae73297306b6f3a1c0401805c9 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 5 Feb 2024 12:08:04 +0100 Subject: [PATCH 034/167] fix --- .../runtime/binding/tcp/internal/TcpEventContext.java | 6 +++--- .../binding-tcp/src/main/resources/META-INF/zilla/tcp.idl | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 0216c21d08..908b9d1b86 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -20,7 +20,7 @@ import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.ProxyEventFW; +import io.aklivity.zilla.runtime.binding.tcp.internal.types.event.TcpEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -28,7 +28,7 @@ public class TcpEventContext { private static final int EVENT_BUFFER_CAPACITY = 1024; - private final ProxyEventFW.Builder proxyEventRW = new ProxyEventFW.Builder(); + private final TcpEventFW.Builder proxyEventRW = new TcpEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int typeId; private final MessageConsumer logEvent; @@ -46,7 +46,7 @@ public void remoteAccessFailed( long routedId, String address) { - ProxyEventFW event = proxyEventRW + TcpEventFW event = proxyEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessFailed(e -> e .traceId(traceId) diff --git a/runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl b/runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl index d8cfd6aa86..4dbd4917e4 100644 --- a/runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl +++ b/runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl @@ -17,19 +17,19 @@ scope tcp { scope event { - enum ProxyEventType (uint8) + enum TcpEventType (uint8) { REMOTE_ACCESS_FAILED (1) } - struct ProxyRemoteAccessFailedEvent extends core::event::BindingEvent + struct TcpRemoteAccessFailedEvent extends core::event::BindingEvent { string16 address; } - union ProxyEvent switch (ProxyEventType) + union TcpEvent switch (TcpEventType) { - case REMOTE_ACCESS_FAILED: ProxyRemoteAccessFailedEvent remoteAccessFailed; + case REMOTE_ACCESS_FAILED: TcpRemoteAccessFailedEvent remoteAccessFailed; } } } From 431300d3696a5b7c6ff478a65fea1cb3cab3e886 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 5 Feb 2024 12:14:09 +0100 Subject: [PATCH 035/167] fix --- .../zilla/runtime/binding/tcp/internal/TcpEventContext.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 908b9d1b86..8f02bd6ca1 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -28,7 +28,7 @@ public class TcpEventContext { private static final int EVENT_BUFFER_CAPACITY = 1024; - private final TcpEventFW.Builder proxyEventRW = new TcpEventFW.Builder(); + private final TcpEventFW.Builder tcpEventRW = new TcpEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int typeId; private final MessageConsumer logEvent; @@ -46,7 +46,7 @@ public void remoteAccessFailed( long routedId, String address) { - TcpEventFW event = proxyEventRW + TcpEventFW event = tcpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessFailed(e -> e .traceId(traceId) From 33d1745132e6d8cac5f1a17098f46182428637fa Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 5 Feb 2024 12:54:38 +0100 Subject: [PATCH 036/167] WIP EventsLayout --- .../internal/SchemaRegistryEventContext.java | 2 +- .../http/internal/HttpEventContext.java | 2 +- .../kafka/internal/KafkaEventContext.java | 2 +- .../mqtt/internal/MqttEventContext.java | 2 +- .../binding/tcp/internal/TcpEventContext.java | 2 +- .../binding/tls/internal/TlsEventContext.java | 2 +- .../zilla/runtime/engine/EngineContext.java | 6 +- .../engine/internal/layouts/EventsLayout.java | 112 ++++++++++++++++++ .../internal/registry/EngineWorker.java | 18 +-- 9 files changed, 129 insertions(+), 19 deletions(-) create mode 100644 runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index fff3bf6003..63c2329841 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -36,7 +36,7 @@ public SchemaRegistryEventContext( EngineContext context) { this.typeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); - this.logEvent = context::logEvent; + this.logEvent = context.logEvent(); } public void remoteAccessRejected( diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index a459589710..a9f74487a7 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -39,7 +39,7 @@ public HttpEventContext( EngineContext context) { this.httpTypeId = httpTypeId; - this.logEvent = context::logEvent; + this.logEvent = context.logEvent(); } public void accessDenied( diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 166c4f363e..e361929a02 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -39,7 +39,7 @@ public KafkaEventContext( EngineContext context) { this.kafkaTypeId = kafkaTypeId; - this.logEvent = context::logEvent; + this.logEvent = context.logEvent(); } public void authorization( diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 32856f3b54..9a1c00b67b 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -39,7 +39,7 @@ public MqttEventContext( EngineContext context) { this.mqttTypeId = mqttTypeId; - this.logEvent = context::logEvent; + this.logEvent = context.logEvent(); } public void authorization( diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 8f02bd6ca1..687242759a 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -38,7 +38,7 @@ public TcpEventContext( EngineContext context) { this.typeId = typeId; - this.logEvent = context::logEvent; + this.logEvent = context.logEvent(); } public void remoteAccessFailed( diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 1dd6ac9b83..ac95abd3e2 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -44,7 +44,7 @@ public TlsEventContext( EngineContext context) { this.typeId = typeId; - this.logEvent = context::logEvent; + this.logEvent = context.logEvent(); } public void tlsFailed( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index be6094c516..b4f0de7786 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -20,7 +20,6 @@ import java.nio.channels.SelectableChannel; import java.util.function.LongSupplier; -import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; import io.aklivity.zilla.runtime.engine.binding.BindingHandler; @@ -150,8 +149,5 @@ void onExporterAttached( void onExporterDetached( long exporterId); - void logEvent(int msgTypeId, - DirectBuffer buffer, - int index, - int length); + MessageConsumer logEvent(); } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java new file mode 100644 index 0000000000..2839008147 --- /dev/null +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -0,0 +1,112 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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.aklivity.zilla.runtime.engine.internal.layouts; + +import static org.agrona.IoUtil.createEmptyFile; +import static org.agrona.IoUtil.mapExistingFile; +import static org.agrona.IoUtil.unmap; + +import java.io.File; +import java.nio.MappedByteBuffer; +import java.nio.file.Path; + +import org.agrona.CloseHelper; +import org.agrona.DirectBuffer; +import org.agrona.concurrent.AtomicBuffer; +import org.agrona.concurrent.UnsafeBuffer; + +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; + +public final class EventsLayout implements AutoCloseable +{ + private final AtomicBuffer buffer; + + private int position; + + private EventsLayout( + AtomicBuffer buffer) + { + this.buffer = buffer; + this.position = 0; + } + + public MessageConsumer supplyWriter() + { + return this::writeEvent; + } + + private void writeEvent( + int msgTypeId, + DirectBuffer recordBuffer, + int index, + int length) + { + // TODO: Ati - include timestamp + System.out.printf("%d %s %d %d%n", msgTypeId, buffer, index, length); // TODO: Ati + if (position + length > buffer.capacity()) + { + throw new IllegalStateException("Event buffer is full."); + } + buffer.putBytes(position, recordBuffer, index, length); + position += length; + } + + @Override + public void close() + { + unmap(buffer.byteBuffer()); + } + + public static final class Builder + { + private long capacity; + private Path path; + private boolean readonly; + + public Builder streamsCapacity( + long streamsCapacity) + { + this.capacity = streamsCapacity; + return this; + } + + public Builder path( + Path path) + { + this.path = path; + return this; + } + + public Builder readonly( + boolean readonly) + { + this.readonly = readonly; + return this; + } + + public EventsLayout build() + { + final File layoutFile = path.toFile(); + if (!readonly) + { + CloseHelper.close(createEmptyFile(layoutFile, capacity)); + } + final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); + final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); + return new EventsLayout(atomicBuffer); + } + } +} diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 733ecaff43..17dd4e39e1 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -108,6 +108,7 @@ import io.aklivity.zilla.runtime.engine.internal.exporter.ExporterAgent; import io.aklivity.zilla.runtime.engine.internal.layouts.BudgetsLayout; import io.aklivity.zilla.runtime.engine.internal.layouts.BufferPoolLayout; +import io.aklivity.zilla.runtime.engine.internal.layouts.EventsLayout; import io.aklivity.zilla.runtime.engine.internal.layouts.StreamsLayout; import io.aklivity.zilla.runtime.engine.internal.layouts.metrics.HistogramsLayout; import io.aklivity.zilla.runtime.engine.internal.layouts.metrics.ScalarsLayout; @@ -210,6 +211,7 @@ public class EngineWorker implements EngineContext, Agent private final ScalarsLayout countersLayout; private final ScalarsLayout gaugesLayout; private final HistogramsLayout histogramsLayout; + private final EventsLayout eventsLayout; private long initialId; private long promiseId; private long traceId; @@ -285,6 +287,12 @@ public EngineWorker( .readonly(readonly) .build(); + this.eventsLayout = new EventsLayout.Builder() + .path(config.directory().resolve(String.format("events%d", index))) + .streamsCapacity(config.streamsBufferCapacity()) + .readonly(readonly) + .build(); + this.agentName = String.format("engine/data#%d", index); this.streamsLayout = streamsLayout; this.bufferPoolLayout = bufferPoolLayout; @@ -896,15 +904,9 @@ public LongConsumer supplyHistogramWriter( } @Override - public void logEvent( - int msgTypeId, - DirectBuffer buffer, - int index, - int length) + public MessageConsumer logEvent() { - // TODO: Ati - write record - // TODO: Ati - include timestamp - System.out.printf("%d %s %d %d%n", msgTypeId, buffer, index, length); + return this.eventsLayout.supplyWriter(); } private void onSystemMessage( From f8e4cede0aed0cd224a1654f5f6adb1f26b54652 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 5 Feb 2024 17:28:24 +0100 Subject: [PATCH 037/167] WIP timestamp --- .../registry/internal/SchemaRegistryEventContext.java | 4 ++++ .../runtime/binding/http/internal/HttpEventContext.java | 5 +++++ .../runtime/binding/kafka/internal/KafkaEventContext.java | 5 +++++ .../runtime/binding/mqtt/internal/MqttEventContext.java | 4 ++++ .../zilla/runtime/binding/tcp/internal/TcpEventContext.java | 4 ++++ .../zilla/runtime/binding/tls/internal/TlsEventContext.java | 4 ++++ .../io/aklivity/zilla/runtime/engine/EngineContext.java | 2 ++ .../runtime/engine/internal/registry/EngineWorker.java | 6 ++++++ 8 files changed, 34 insertions(+) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 63c2329841..d566ce190b 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -15,6 +15,7 @@ package io.aklivity.zilla.runtime.catalog.schema.registry.internal; import java.nio.ByteBuffer; +import java.util.function.LongSupplier; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -31,12 +32,14 @@ public class SchemaRegistryEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int typeId; private final MessageConsumer logEvent; + private final LongSupplier timestamp; public SchemaRegistryEventContext( EngineContext context) { this.typeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); this.logEvent = context.logEvent(); + this.timestamp = context.timestamp(); } public void remoteAccessRejected( @@ -48,6 +51,7 @@ public void remoteAccessRejected( SchemaRegistryEventFW event = schemaRegistryEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessRejected(e -> e + .timestamp(timestamp.getAsLong()) .catalogId(catalogId) .url(url) .method(method) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index a9f74487a7..d70037eb0d 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -16,6 +16,7 @@ package io.aklivity.zilla.runtime.binding.http.internal; import java.nio.ByteBuffer; +import java.util.function.LongSupplier; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -33,6 +34,7 @@ public class HttpEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int httpTypeId; private final MessageConsumer logEvent; + private final LongSupplier timestamp; public HttpEventContext( int httpTypeId, @@ -40,6 +42,7 @@ public HttpEventContext( { this.httpTypeId = httpTypeId; this.logEvent = context.logEvent(); + this.timestamp = context.timestamp(); } public void accessDenied( @@ -49,6 +52,7 @@ public void accessDenied( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .accessDenied(e -> e + .timestamp(timestamp.getAsLong()) .traceId(traceId) .bindingId(routedId) ) @@ -66,6 +70,7 @@ public void authorization( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e + .timestamp(timestamp.getAsLong()) .traceId(traceId) .bindingId(routedId) .result(r -> r.set(result)) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index e361929a02..2005e4d473 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -16,6 +16,7 @@ package io.aklivity.zilla.runtime.binding.kafka.internal; import java.nio.ByteBuffer; +import java.util.function.LongSupplier; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -33,6 +34,7 @@ public class KafkaEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int kafkaTypeId; private final MessageConsumer logEvent; + private final LongSupplier timestamp; public KafkaEventContext( int kafkaTypeId, @@ -40,6 +42,7 @@ public KafkaEventContext( { this.kafkaTypeId = kafkaTypeId; this.logEvent = context.logEvent(); + this.timestamp = context.timestamp(); } public void authorization( @@ -50,6 +53,7 @@ public void authorization( KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e + .timestamp(timestamp.getAsLong()) .traceId(traceId) .bindingId(routedId) .result(r -> r.set(result)) @@ -65,6 +69,7 @@ public void apiVersionRejected( KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .apiVersionRejected(e -> e + .timestamp(timestamp.getAsLong()) .traceId(traceId) ) .build(); diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 9a1c00b67b..97e0d31e36 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -16,6 +16,7 @@ package io.aklivity.zilla.runtime.binding.mqtt.internal; import java.nio.ByteBuffer; +import java.util.function.LongSupplier; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -33,6 +34,7 @@ public class MqttEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int mqttTypeId; private final MessageConsumer logEvent; + private final LongSupplier timestamp; public MqttEventContext( int mqttTypeId, @@ -40,6 +42,7 @@ public MqttEventContext( { this.mqttTypeId = mqttTypeId; this.logEvent = context.logEvent(); + this.timestamp = context.timestamp(); } public void authorization( @@ -51,6 +54,7 @@ public void authorization( MqttEventFW event = mqttEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e + .timestamp(timestamp.getAsLong()) .traceId(traceId) .bindingId(routedId) .result(r -> r.set(result)) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 687242759a..b7f4c53c49 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -16,6 +16,7 @@ package io.aklivity.zilla.runtime.binding.tcp.internal; import java.nio.ByteBuffer; +import java.util.function.LongSupplier; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -32,6 +33,7 @@ public class TcpEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int typeId; private final MessageConsumer logEvent; + private final LongSupplier timestamp; public TcpEventContext( int typeId, @@ -39,6 +41,7 @@ public TcpEventContext( { this.typeId = typeId; this.logEvent = context.logEvent(); + this.timestamp = context.timestamp(); } public void remoteAccessFailed( @@ -49,6 +52,7 @@ public void remoteAccessFailed( TcpEventFW event = tcpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessFailed(e -> e + .timestamp(timestamp.getAsLong()) .traceId(traceId) .bindingId(routedId) .address(address) diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index ac95abd3e2..574720ccbc 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -16,6 +16,7 @@ package io.aklivity.zilla.runtime.binding.tls.internal; import java.nio.ByteBuffer; +import java.util.function.LongSupplier; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLKeyException; @@ -38,6 +39,7 @@ public class TlsEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int typeId; private final MessageConsumer logEvent; + private final LongSupplier timestamp; public TlsEventContext( int typeId, @@ -45,6 +47,7 @@ public TlsEventContext( { this.typeId = typeId; this.logEvent = context.logEvent(); + this.timestamp = context.timestamp(); } public void tlsFailed( @@ -54,6 +57,7 @@ public void tlsFailed( TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsFailed(e -> e + .timestamp(timestamp.getAsLong()) .traceId(traceId) .error(r -> r.set(error)) ) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index b4f0de7786..ccad66987f 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -150,4 +150,6 @@ void onExporterDetached( long exporterId); MessageConsumer logEvent(); + + LongSupplier timestamp(); } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 17dd4e39e1..b74cab22cf 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -909,6 +909,12 @@ public MessageConsumer logEvent() return this.eventsLayout.supplyWriter(); } + @Override + public LongSupplier timestamp() + { + return () -> timestamps ? System.nanoTime() : 0L; + } + private void onSystemMessage( int msgTypeId, DirectBuffer buffer, From a8d6b19a3fe86088e53d5ee47eae1efd0b321e33 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 6 Feb 2024 14:51:48 +0100 Subject: [PATCH 038/167] WIP StdoutExporter --- cloud/docker-image/pom.xml | 6 + .../src/main/docker/zpm.json.template | 1 + incubator/exporter-stdout.spec/COPYRIGHT | 12 + incubator/exporter-stdout.spec/LICENSE | 114 +++++++ incubator/exporter-stdout.spec/NOTICE | 18 + .../exporter-stdout.spec/NOTICE.template | 13 + incubator/exporter-stdout.spec/mvnw | 310 ++++++++++++++++++ incubator/exporter-stdout.spec/mvnw.cmd | 182 ++++++++++ incubator/exporter-stdout.spec/pom.xml | 161 +++++++++ .../src/main/moditect/module-info.java | 18 + .../stdout/schema/stdout.schema.patch.json | 51 +++ incubator/exporter-stdout/COPYRIGHT | 12 + incubator/exporter-stdout/LICENSE | 114 +++++++ incubator/exporter-stdout/NOTICE | 13 + incubator/exporter-stdout/NOTICE.template | 13 + incubator/exporter-stdout/mvnw | 310 ++++++++++++++++++ incubator/exporter-stdout/mvnw.cmd | 182 ++++++++++ incubator/exporter-stdout/pom.xml | 250 ++++++++++++++ .../stdout/internal/StdoutExporter.java | 54 +++ .../internal/StdoutExporterContext.java | 59 ++++ .../internal/StdoutExporterFactorySpi.java | 36 ++ .../internal/StdoutExporterHandler.java | 51 +++ .../internal/config/StdoutExporterConfig.java | 33 ++ .../internal/config/StdoutOptionsConfig.java | 21 ++ .../config/StdoutOptionsConfigAdapter.java | 56 ++++ .../src/main/moditect/module-info.java | 24 ++ ...time.engine.config.OptionsConfigAdapterSpi | 1 + ...runtime.engine.exporter.ExporterFactorySpi | 1 + .../internal/StdoutExporterFactoryTest.java | 51 +++ .../StdoutOptionsConfigAdapterTest.java | 68 ++++ incubator/pom.xml | 7 + .../engine/internal/layouts/EventsLayout.java | 1 - 32 files changed, 2242 insertions(+), 1 deletion(-) create mode 100644 incubator/exporter-stdout.spec/COPYRIGHT create mode 100644 incubator/exporter-stdout.spec/LICENSE create mode 100644 incubator/exporter-stdout.spec/NOTICE create mode 100644 incubator/exporter-stdout.spec/NOTICE.template create mode 100755 incubator/exporter-stdout.spec/mvnw create mode 100644 incubator/exporter-stdout.spec/mvnw.cmd create mode 100644 incubator/exporter-stdout.spec/pom.xml create mode 100644 incubator/exporter-stdout.spec/src/main/moditect/module-info.java create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json create mode 100644 incubator/exporter-stdout/COPYRIGHT create mode 100644 incubator/exporter-stdout/LICENSE create mode 100644 incubator/exporter-stdout/NOTICE create mode 100644 incubator/exporter-stdout/NOTICE.template create mode 100755 incubator/exporter-stdout/mvnw create mode 100644 incubator/exporter-stdout/mvnw.cmd create mode 100644 incubator/exporter-stdout/pom.xml create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporter.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactorySpi.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutExporterConfig.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfig.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfigAdapter.java create mode 100644 incubator/exporter-stdout/src/main/moditect/module-info.java create mode 100644 incubator/exporter-stdout/src/main/resources/META-INF/services/io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi create mode 100644 incubator/exporter-stdout/src/main/resources/META-INF/services/io.aklivity.zilla.runtime.engine.exporter.ExporterFactorySpi create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactoryTest.java create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfigAdapterTest.java diff --git a/cloud/docker-image/pom.xml b/cloud/docker-image/pom.xml index 180f6eb1cd..7f594c2d7f 100644 --- a/cloud/docker-image/pom.xml +++ b/cloud/docker-image/pom.xml @@ -223,6 +223,12 @@ ${project.version} runtime + + ${project.groupId} + exporter-stdout + ${project.version} + runtime + ${project.groupId} metrics-stream diff --git a/cloud/docker-image/src/main/docker/zpm.json.template b/cloud/docker-image/src/main/docker/zpm.json.template index 427e9b3f99..0f5dc078a4 100644 --- a/cloud/docker-image/src/main/docker/zpm.json.template +++ b/cloud/docker-image/src/main/docker/zpm.json.template @@ -44,6 +44,7 @@ "io.aklivity.zilla:command-tune", "io.aklivity.zilla:engine", "io.aklivity.zilla:exporter-prometheus", + "io.aklivity.zilla:exporter-stdout", "io.aklivity.zilla:exporter-otlp", "io.aklivity.zilla:guard-jwt", "io.aklivity.zilla:metrics-stream", diff --git a/incubator/exporter-stdout.spec/COPYRIGHT b/incubator/exporter-stdout.spec/COPYRIGHT new file mode 100644 index 0000000000..0cb10b6f62 --- /dev/null +++ b/incubator/exporter-stdout.spec/COPYRIGHT @@ -0,0 +1,12 @@ +Copyright ${copyrightYears} Aklivity Inc + +Licensed under the Aklivity Community License (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + https://www.aklivity.io/aklivity-community-license/ + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. diff --git a/incubator/exporter-stdout.spec/LICENSE b/incubator/exporter-stdout.spec/LICENSE new file mode 100644 index 0000000000..f3cf11c3ad --- /dev/null +++ b/incubator/exporter-stdout.spec/LICENSE @@ -0,0 +1,114 @@ + Aklivity Community License Agreement + Version 1.0 + +This Aklivity Community License Agreement Version 1.0 (the “Agreement”) sets +forth the terms on which Aklivity, Inc. (“Aklivity”) makes available certain +software made available by Aklivity under this Agreement (the “Software”). BY +INSTALLING, DOWNLOADING, ACCESSING, USING OR DISTRIBUTING ANY OF THE SOFTWARE, +YOU AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO +SUCH TERMS AND CONDITIONS, YOU MUST NOT USE THE SOFTWARE. IF YOU ARE RECEIVING +THE SOFTWARE ON BEHALF OF A LEGAL ENTITY, YOU REPRESENT AND WARRANT THAT YOU +HAVE THE ACTUAL AUTHORITY TO AGREE TO THE TERMS AND CONDITIONS OF THIS +AGREEMENT ON BEHALF OF SUCH ENTITY. “Licensee” means you, an individual, or +the entity on whose behalf you are receiving the Software. + + 1. LICENSE GRANT AND CONDITIONS. + + 1.1 License. Subject to the terms and conditions of this Agreement, + Aklivity hereby grants to Licensee a non-exclusive, royalty-free, + worldwide, non-transferable, non-sublicenseable license during the term + of this Agreement to: (a) use the Software; (b) prepare modifications and + derivative works of the Software; (c) distribute the Software (including + without limitation in source code or object code form); and (d) reproduce + copies of the Software (the “License”). Licensee is not granted the + right to, and Licensee shall not, exercise the License for an Excluded + Purpose. For purposes of this Agreement, “Excluded Purpose” means making + available any software-as-a-service, platform-as-a-service, + infrastructure-as-a-service or other similar online service that competes + with Aklivity products or services that provide the Software. + + 1.2 Conditions. In consideration of the License, Licensee’s distribution + of the Software is subject to the following conditions: + + (a) Licensee must cause any Software modified by Licensee to carry + prominent notices stating that Licensee modified the Software. + + (b) On each Software copy, Licensee shall reproduce and not remove or + alter all Aklivity or third party copyright or other proprietary + notices contained in the Software, and Licensee must provide the + notice below with each copy. + + “This software is made available by Aklivity, Inc., under the + terms of the Aklivity Community License Agreement, Version 1.0 + located at http://www.Aklivity.io/Aklivity-community-license. BY + INSTALLING, DOWNLOADING, ACCESSING, USING OR DISTRIBUTING ANY OF + THE SOFTWARE, YOU AGREE TO THE TERMS OF SUCH LICENSE AGREEMENT.” + + 1.3 Licensee Modifications. Licensee may add its own copyright notices + to modifications made by Licensee and may provide additional or different + license terms and conditions for use, reproduction, or distribution of + Licensee’s modifications. While redistributing the Software or + modifications thereof, Licensee may choose to offer, for a fee or free of + charge, support, warranty, indemnity, or other obligations. Licensee, and + not Aklivity, will be responsible for any such obligations. + + 1.4 No Sublicensing. The License does not include the right to + sublicense the Software, however, each recipient to which Licensee + provides the Software may exercise the Licenses so long as such recipient + agrees to the terms and conditions of this Agreement. + + 2. TERM AND TERMINATION. This Agreement will continue unless and until + earlier terminated as set forth herein. If Licensee breaches any of its + conditions or obligations under this Agreement, this Agreement will + terminate automatically and the License will terminate automatically and + permanently. + + 3. INTELLECTUAL PROPERTY. As between the parties, Aklivity will retain all + right, title, and interest in the Software, and all intellectual property + rights therein. Aklivity hereby reserves all rights not expressly granted + to Licensee in this Agreement. Aklivity hereby reserves all rights in its + trademarks and service marks, and no licenses therein are granted in this + Agreement. + + 4. DISCLAIMER. Aklivity HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND + CONDITIONS, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND SPECIFICALLY + DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR + PURPOSE, WITH RESPECT TO THE SOFTWARE. + + 5. LIMITATION OF LIABILITY. Aklivity WILL NOT BE LIABLE FOR ANY DAMAGES OF + ANY KIND, INCLUDING BUT NOT LIMITED TO, LOST PROFITS OR ANY CONSEQUENTIAL, + SPECIAL, INCIDENTAL, INDIRECT, OR DIRECT DAMAGES, HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, ARISING OUT OF THIS AGREEMENT. THE FOREGOING SHALL + APPLY TO THE EXTENT PERMITTED BY APPLICABLE LAW. + + 6.GENERAL. + + 6.1 Governing Law. This Agreement will be governed by and interpreted in + accordance with the laws of the state of California, without reference to + its conflict of laws principles. If Licensee is located within the + United States, all disputes arising out of this Agreement are subject to + the exclusive jurisdiction of courts located in Santa Clara County, + California. USA. If Licensee is located outside of the United States, + any dispute, controversy or claim arising out of or relating to this + Agreement will be referred to and finally determined by arbitration in + accordance with the JAMS International Arbitration Rules. The tribunal + will consist of one arbitrator. The place of arbitration will be Palo + Alto, California. The language to be used in the arbitral proceedings + will be English. Judgment upon the award rendered by the arbitrator may + be entered in any court having jurisdiction thereof. + + 6.2 Assignment. Licensee is not authorized to assign its rights under + this Agreement to any third party. Aklivity may freely assign its rights + under this Agreement to any third party. + + 6.3 Other. This Agreement is the entire agreement between the parties + regarding the subject matter hereof. No amendment or modification of + this Agreement will be valid or binding upon the parties unless made in + writing and signed by the duly authorized representatives of both + parties. In the event that any provision, including without limitation + any condition, of this Agreement is held to be unenforceable, this + Agreement and all licenses and rights granted hereunder will immediately + terminate. Waiver by Aklivity of a breach of any provision of this + Agreement or the failure by Aklivity to exercise any right hereunder + will not be construed as a waiver of any subsequent breach of that right + or as a waiver of any other right. \ No newline at end of file diff --git a/incubator/exporter-stdout.spec/NOTICE b/incubator/exporter-stdout.spec/NOTICE new file mode 100644 index 0000000000..cf99769e41 --- /dev/null +++ b/incubator/exporter-stdout.spec/NOTICE @@ -0,0 +1,18 @@ +Licensed under the Aklivity Community License (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + https://www.aklivity.io/aklivity-community-license/ + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + +This project includes: + agrona under The Apache License, Version 2.0 + ICU4J under Unicode/ICU License + Jakarta JSON Processing API under Eclipse Public License 2.0 or GNU General Public License, version 2 with the GNU Classpath Exception + org.leadpony.justify under The Apache Software License, Version 2.0 + zilla::specs::engine.spec under The Apache Software License, Version 2.0 + diff --git a/incubator/exporter-stdout.spec/NOTICE.template b/incubator/exporter-stdout.spec/NOTICE.template new file mode 100644 index 0000000000..209ca12f74 --- /dev/null +++ b/incubator/exporter-stdout.spec/NOTICE.template @@ -0,0 +1,13 @@ +Licensed under the Aklivity Community License (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + https://www.aklivity.io/aklivity-community-license/ + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + +This project includes: +#GENERATED_NOTICES# diff --git a/incubator/exporter-stdout.spec/mvnw b/incubator/exporter-stdout.spec/mvnw new file mode 100755 index 0000000000..d2f0ea3808 --- /dev/null +++ b/incubator/exporter-stdout.spec/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/incubator/exporter-stdout.spec/mvnw.cmd b/incubator/exporter-stdout.spec/mvnw.cmd new file mode 100644 index 0000000000..b26ab24f03 --- /dev/null +++ b/incubator/exporter-stdout.spec/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/incubator/exporter-stdout.spec/pom.xml b/incubator/exporter-stdout.spec/pom.xml new file mode 100644 index 0000000000..4ed5662b0f --- /dev/null +++ b/incubator/exporter-stdout.spec/pom.xml @@ -0,0 +1,161 @@ + + + + 4.0.0 + + io.aklivity.zilla + specs + develop-SNAPSHOT + ../../specs/pom.xml + + + exporter-stdout.spec + zilla::specs::exporter-stdout.spec + + + + Aklivity Community License Agreement + https://www.aklivity.io/aklivity-community-license/ + repo + + + + + 11 + 11 + 1.00 + 0 + + + + + org.kaazing + k3po.lang + provided + + + ${project.groupId} + engine.spec + ${project.version} + + + junit + junit + test + + + org.kaazing + k3po.junit + test + + + org.hamcrest + hamcrest-library + test + + + + + + + src/main/resources + + + src/main/scripts + + + + + + org.jasig.maven + maven-notice-plugin + + + ${project.groupId} + flyweight-maven-plugin + ${project.version} + + core + io.aklivity.zilla.specs.exporter.stdout.internal.types + + + + + validate + generate + + + + + + com.mycila + license-maven-plugin + + + maven-checkstyle-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.moditect + moditect-maven-plugin + + + org.kaazing + k3po-maven-plugin + + + ${project.groupId} + engine + ${project.version} + test-jar + + + ${project.groupId} + engine + ${project.version} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + org.jacoco + jacoco-maven-plugin + + + io/aklivity/zilla/specs/exporter/stdout/internal/types/**/*.class + + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + ${jacoco.coverage.ratio} + + + CLASS + MISSEDCOUNT + ${jacoco.missed.count} + + + + + + + + + diff --git a/incubator/exporter-stdout.spec/src/main/moditect/module-info.java b/incubator/exporter-stdout.spec/src/main/moditect/module-info.java new file mode 100644 index 0000000000..9b8473aaae --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/moditect/module-info.java @@ -0,0 +1,18 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +open module io.aklivity.zilla.specs.exporter.stdout +{ + requires transitive io.aklivity.zilla.specs.engine; +} diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json new file mode 100644 index 0000000000..19fbaa407b --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json @@ -0,0 +1,51 @@ +[ + { + "op": "add", + "path": "/$defs/telemetry/exporter/properties/type/enum/-", + "value": "stdout" + }, + { + "op": "add", + "path": "/$defs/telemetry/exporter/allOf/-", + "value": + { + "if": + { + "properties": + { + "type": + { + "const": "stdout" + } + } + }, + "then": + { + "properties": + { + "type": + { + "const": "stdout" + }, + "options": + { + "properties": + { + "level": + { + "enum": + [ + "info", + "warning", + "error" + ], + "default": "info" + } + }, + "additionalProperties": false + } + } + } + } + } +] diff --git a/incubator/exporter-stdout/COPYRIGHT b/incubator/exporter-stdout/COPYRIGHT new file mode 100644 index 0000000000..0cb10b6f62 --- /dev/null +++ b/incubator/exporter-stdout/COPYRIGHT @@ -0,0 +1,12 @@ +Copyright ${copyrightYears} Aklivity Inc + +Licensed under the Aklivity Community License (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + https://www.aklivity.io/aklivity-community-license/ + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. diff --git a/incubator/exporter-stdout/LICENSE b/incubator/exporter-stdout/LICENSE new file mode 100644 index 0000000000..f3cf11c3ad --- /dev/null +++ b/incubator/exporter-stdout/LICENSE @@ -0,0 +1,114 @@ + Aklivity Community License Agreement + Version 1.0 + +This Aklivity Community License Agreement Version 1.0 (the “Agreement”) sets +forth the terms on which Aklivity, Inc. (“Aklivity”) makes available certain +software made available by Aklivity under this Agreement (the “Software”). BY +INSTALLING, DOWNLOADING, ACCESSING, USING OR DISTRIBUTING ANY OF THE SOFTWARE, +YOU AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO +SUCH TERMS AND CONDITIONS, YOU MUST NOT USE THE SOFTWARE. IF YOU ARE RECEIVING +THE SOFTWARE ON BEHALF OF A LEGAL ENTITY, YOU REPRESENT AND WARRANT THAT YOU +HAVE THE ACTUAL AUTHORITY TO AGREE TO THE TERMS AND CONDITIONS OF THIS +AGREEMENT ON BEHALF OF SUCH ENTITY. “Licensee” means you, an individual, or +the entity on whose behalf you are receiving the Software. + + 1. LICENSE GRANT AND CONDITIONS. + + 1.1 License. Subject to the terms and conditions of this Agreement, + Aklivity hereby grants to Licensee a non-exclusive, royalty-free, + worldwide, non-transferable, non-sublicenseable license during the term + of this Agreement to: (a) use the Software; (b) prepare modifications and + derivative works of the Software; (c) distribute the Software (including + without limitation in source code or object code form); and (d) reproduce + copies of the Software (the “License”). Licensee is not granted the + right to, and Licensee shall not, exercise the License for an Excluded + Purpose. For purposes of this Agreement, “Excluded Purpose” means making + available any software-as-a-service, platform-as-a-service, + infrastructure-as-a-service or other similar online service that competes + with Aklivity products or services that provide the Software. + + 1.2 Conditions. In consideration of the License, Licensee’s distribution + of the Software is subject to the following conditions: + + (a) Licensee must cause any Software modified by Licensee to carry + prominent notices stating that Licensee modified the Software. + + (b) On each Software copy, Licensee shall reproduce and not remove or + alter all Aklivity or third party copyright or other proprietary + notices contained in the Software, and Licensee must provide the + notice below with each copy. + + “This software is made available by Aklivity, Inc., under the + terms of the Aklivity Community License Agreement, Version 1.0 + located at http://www.Aklivity.io/Aklivity-community-license. BY + INSTALLING, DOWNLOADING, ACCESSING, USING OR DISTRIBUTING ANY OF + THE SOFTWARE, YOU AGREE TO THE TERMS OF SUCH LICENSE AGREEMENT.” + + 1.3 Licensee Modifications. Licensee may add its own copyright notices + to modifications made by Licensee and may provide additional or different + license terms and conditions for use, reproduction, or distribution of + Licensee’s modifications. While redistributing the Software or + modifications thereof, Licensee may choose to offer, for a fee or free of + charge, support, warranty, indemnity, or other obligations. Licensee, and + not Aklivity, will be responsible for any such obligations. + + 1.4 No Sublicensing. The License does not include the right to + sublicense the Software, however, each recipient to which Licensee + provides the Software may exercise the Licenses so long as such recipient + agrees to the terms and conditions of this Agreement. + + 2. TERM AND TERMINATION. This Agreement will continue unless and until + earlier terminated as set forth herein. If Licensee breaches any of its + conditions or obligations under this Agreement, this Agreement will + terminate automatically and the License will terminate automatically and + permanently. + + 3. INTELLECTUAL PROPERTY. As between the parties, Aklivity will retain all + right, title, and interest in the Software, and all intellectual property + rights therein. Aklivity hereby reserves all rights not expressly granted + to Licensee in this Agreement. Aklivity hereby reserves all rights in its + trademarks and service marks, and no licenses therein are granted in this + Agreement. + + 4. DISCLAIMER. Aklivity HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND + CONDITIONS, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND SPECIFICALLY + DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR + PURPOSE, WITH RESPECT TO THE SOFTWARE. + + 5. LIMITATION OF LIABILITY. Aklivity WILL NOT BE LIABLE FOR ANY DAMAGES OF + ANY KIND, INCLUDING BUT NOT LIMITED TO, LOST PROFITS OR ANY CONSEQUENTIAL, + SPECIAL, INCIDENTAL, INDIRECT, OR DIRECT DAMAGES, HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, ARISING OUT OF THIS AGREEMENT. THE FOREGOING SHALL + APPLY TO THE EXTENT PERMITTED BY APPLICABLE LAW. + + 6.GENERAL. + + 6.1 Governing Law. This Agreement will be governed by and interpreted in + accordance with the laws of the state of California, without reference to + its conflict of laws principles. If Licensee is located within the + United States, all disputes arising out of this Agreement are subject to + the exclusive jurisdiction of courts located in Santa Clara County, + California. USA. If Licensee is located outside of the United States, + any dispute, controversy or claim arising out of or relating to this + Agreement will be referred to and finally determined by arbitration in + accordance with the JAMS International Arbitration Rules. The tribunal + will consist of one arbitrator. The place of arbitration will be Palo + Alto, California. The language to be used in the arbitral proceedings + will be English. Judgment upon the award rendered by the arbitrator may + be entered in any court having jurisdiction thereof. + + 6.2 Assignment. Licensee is not authorized to assign its rights under + this Agreement to any third party. Aklivity may freely assign its rights + under this Agreement to any third party. + + 6.3 Other. This Agreement is the entire agreement between the parties + regarding the subject matter hereof. No amendment or modification of + this Agreement will be valid or binding upon the parties unless made in + writing and signed by the duly authorized representatives of both + parties. In the event that any provision, including without limitation + any condition, of this Agreement is held to be unenforceable, this + Agreement and all licenses and rights granted hereunder will immediately + terminate. Waiver by Aklivity of a breach of any provision of this + Agreement or the failure by Aklivity to exercise any right hereunder + will not be construed as a waiver of any subsequent breach of that right + or as a waiver of any other right. \ No newline at end of file diff --git a/incubator/exporter-stdout/NOTICE b/incubator/exporter-stdout/NOTICE new file mode 100644 index 0000000000..9024d8926d --- /dev/null +++ b/incubator/exporter-stdout/NOTICE @@ -0,0 +1,13 @@ +Licensed under the Aklivity Community License (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + https://www.aklivity.io/aklivity-community-license/ + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + +This project includes: + diff --git a/incubator/exporter-stdout/NOTICE.template b/incubator/exporter-stdout/NOTICE.template new file mode 100644 index 0000000000..209ca12f74 --- /dev/null +++ b/incubator/exporter-stdout/NOTICE.template @@ -0,0 +1,13 @@ +Licensed under the Aklivity Community License (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + https://www.aklivity.io/aklivity-community-license/ + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + +This project includes: +#GENERATED_NOTICES# diff --git a/incubator/exporter-stdout/mvnw b/incubator/exporter-stdout/mvnw new file mode 100755 index 0000000000..d2f0ea3808 --- /dev/null +++ b/incubator/exporter-stdout/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/incubator/exporter-stdout/mvnw.cmd b/incubator/exporter-stdout/mvnw.cmd new file mode 100644 index 0000000000..b26ab24f03 --- /dev/null +++ b/incubator/exporter-stdout/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml new file mode 100644 index 0000000000..36f6a94359 --- /dev/null +++ b/incubator/exporter-stdout/pom.xml @@ -0,0 +1,250 @@ + + + + 4.0.0 + + io.aklivity.zilla + runtime + develop-SNAPSHOT + ../pom.xml + + + exporter-stdout + zilla::runtime::exporter-stdout + + + + Aklivity Community License Agreement + https://www.aklivity.io/aklivity-community-license/ + repo + + + + + 11 + 11 + 0.65 + 2 + + + + + ${project.groupId} + exporter-stdout.spec + ${project.version} + provided + + + ${project.groupId} + engine + ${project.version} + provided + + + ${project.groupId} + engine + test-jar + ${project.version} + test + + + junit + junit + test + + + org.hamcrest + hamcrest + test + + + com.vtence.hamcrest + hamcrest-jpa + test + + + com.github.npathai + hamcrest-optional + test + + + org.mockito + mockito-core + test + + + org.kaazing + k3po.junit + test + + + org.kaazing + k3po.lang + test + + + org.openjdk.jmh + jmh-core + test + + + org.openjdk.jmh + jmh-generator-annprocess + test + + + + + + + org.jasig.maven + maven-notice-plugin + + + ${project.groupId} + flyweight-maven-plugin + ${project.version} + + core + io.aklivity.zilla.runtime.exporter.stdout.internal.types + + + + + generate + + + + + + com.mycila + license-maven-plugin + + + **/org.mockito.plugins.MockMaker + + + + + maven-checkstyle-plugin + + + maven-dependency-plugin + + + process-resources + + unpack + + + + + ${project.groupId} + exporter-stdout.spec + + + ^\Qio/aklivity/zilla/specs/exporter/stdout/\E + io/aklivity/zilla/runtime/exporter/stdout/internal/ + + + + + io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json + ${project.build.directory}/classes + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.moditect + moditect-maven-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + org.kaazing + k3po-maven-plugin + + + ${project.groupId} + engine + ${project.version} + test-jar + + + ${project.groupId} + engine + ${project.version} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + org.jacoco + jacoco-maven-plugin + + + io/aklivity/zilla/runtime/exporter/stdout/internal/types/**/*.class + + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + ${jacoco.coverage.ratio} + + + CLASS + MISSEDCOUNT + ${jacoco.missed.count} + + + + + + + + io.gatling + maven-shade-plugin + + + + org.agrona:agrona + io.aklivity.zilla:engine + org.openjdk.jmh:jmh-core + net.sf.jopt-simple:jopt-simple + org.apache.commons:commons-math3 + commons-cli:commons-cli + com.github.biboudis:jmh-profilers + + + + + + + diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporter.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporter.java new file mode 100644 index 0000000000..8e63ed8338 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporter.java @@ -0,0 +1,54 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal; + +import java.net.URL; + +import io.aklivity.zilla.runtime.engine.EngineConfiguration; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.exporter.Exporter; +import io.aklivity.zilla.runtime.engine.exporter.ExporterContext; + +public class StdoutExporter implements Exporter +{ + public static final String NAME = "stdout"; + + private final EngineConfiguration config; + + public StdoutExporter( + EngineConfiguration config) + { + this.config = config; + } + + @Override + public String name() + { + return NAME; + } + + @Override + public URL type() + { + return getClass().getResource("schema/stdout.schema.patch.json"); + } + + @Override + public ExporterContext supply( + EngineContext context) + { + return new StdoutExporterContext(config, context); + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java new file mode 100644 index 0000000000..f50d89a44b --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java @@ -0,0 +1,59 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal; + +import java.util.List; +import java.util.function.LongFunction; + +import io.aklivity.zilla.runtime.engine.EngineConfiguration; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.config.AttributeConfig; +import io.aklivity.zilla.runtime.engine.config.ExporterConfig; +import io.aklivity.zilla.runtime.engine.config.KindConfig; +import io.aklivity.zilla.runtime.engine.exporter.ExporterContext; +import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; +import io.aklivity.zilla.runtime.engine.metrics.Collector; +import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; + +public class StdoutExporterContext implements ExporterContext +{ + private final EngineConfiguration config; + private final EngineContext context; + + public StdoutExporterContext( + EngineConfiguration config, + EngineContext context) + { + this.config = config; + this.context = context; + } + + @Override + public ExporterHandler attach( + ExporterConfig exporter, + List attributes, + Collector collector, + LongFunction resolveKind) + { + StdoutExporterConfig stdoutExporter = new StdoutExporterConfig(exporter); + return new StdoutExporterHandler(config, context, stdoutExporter); + } + + @Override + public void detach( + long exporterId) + { + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactorySpi.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactorySpi.java new file mode 100644 index 0000000000..1497dd382a --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactorySpi.java @@ -0,0 +1,36 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal; + +import io.aklivity.zilla.runtime.engine.Configuration; +import io.aklivity.zilla.runtime.engine.EngineConfiguration; +import io.aklivity.zilla.runtime.engine.exporter.Exporter; +import io.aklivity.zilla.runtime.engine.exporter.ExporterFactorySpi; + +public class StdoutExporterFactorySpi implements ExporterFactorySpi +{ + @Override + public String type() + { + return StdoutExporter.NAME; + } + + @Override + public Exporter create( + Configuration config) + { + return new StdoutExporter(new EngineConfiguration(config)); + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java new file mode 100644 index 0000000000..b59027da4d --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -0,0 +1,51 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal; + +import io.aklivity.zilla.runtime.engine.EngineConfiguration; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; +import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; + +public class StdoutExporterHandler implements ExporterHandler +{ + private final EngineContext context; + + public StdoutExporterHandler( + EngineConfiguration config, + EngineContext context, + StdoutExporterConfig exporter) + { + this.context = context; + } + + @Override + public void start() + { + // TODO: Ati + System.out.println("Hello, I am StdoutExporterHandler!"); + } + + @Override + public int export() + { + return 0; + } + + @Override + public void stop() + { + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutExporterConfig.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutExporterConfig.java new file mode 100644 index 0000000000..8f9f7ca38a --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutExporterConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.config; + +import io.aklivity.zilla.runtime.engine.config.ExporterConfig; + +public class StdoutExporterConfig +{ + private final StdoutOptionsConfig options; + + public StdoutExporterConfig( + ExporterConfig exporter) + { + this.options = (StdoutOptionsConfig)exporter.options; + } + + public StdoutOptionsConfig options() + { + return options; + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfig.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfig.java new file mode 100644 index 0000000000..43f11bb071 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfig.java @@ -0,0 +1,21 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.config; + +import io.aklivity.zilla.runtime.engine.config.OptionsConfig; + +public class StdoutOptionsConfig extends OptionsConfig +{ +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfigAdapter.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfigAdapter.java new file mode 100644 index 0000000000..fb2bbf8068 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfigAdapter.java @@ -0,0 +1,56 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.config; + +import static io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi.Kind.EXPORTER; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonObjectBuilder; +import jakarta.json.bind.adapter.JsonbAdapter; + +import io.aklivity.zilla.runtime.engine.config.OptionsConfig; +import io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporter; + +public class StdoutOptionsConfigAdapter implements OptionsConfigAdapterSpi, JsonbAdapter +{ + @Override + public Kind kind() + { + return EXPORTER; + } + + @Override + public String type() + { + return StdoutExporter.NAME; + } + + @Override + public JsonObject adaptToJson( + OptionsConfig options) + { + JsonObjectBuilder object = Json.createObjectBuilder(); + return object.build(); + } + + @Override + public OptionsConfig adaptFromJson( + JsonObject object) + { + return new StdoutOptionsConfig(); + } +} diff --git a/incubator/exporter-stdout/src/main/moditect/module-info.java b/incubator/exporter-stdout/src/main/moditect/module-info.java new file mode 100644 index 0000000000..c89775c1c8 --- /dev/null +++ b/incubator/exporter-stdout/src/main/moditect/module-info.java @@ -0,0 +1,24 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +module io.aklivity.zilla.runtime.exporter.stdout +{ + requires io.aklivity.zilla.runtime.engine; + + provides io.aklivity.zilla.runtime.engine.exporter.ExporterFactorySpi + with io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterFactorySpi; + + provides io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi + with io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutOptionsConfigAdapter; +} diff --git a/incubator/exporter-stdout/src/main/resources/META-INF/services/io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi b/incubator/exporter-stdout/src/main/resources/META-INF/services/io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi new file mode 100644 index 0000000000..c0bfc37413 --- /dev/null +++ b/incubator/exporter-stdout/src/main/resources/META-INF/services/io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi @@ -0,0 +1 @@ +io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutOptionsConfigAdapter \ No newline at end of file diff --git a/incubator/exporter-stdout/src/main/resources/META-INF/services/io.aklivity.zilla.runtime.engine.exporter.ExporterFactorySpi b/incubator/exporter-stdout/src/main/resources/META-INF/services/io.aklivity.zilla.runtime.engine.exporter.ExporterFactorySpi new file mode 100644 index 0000000000..8f575d444b --- /dev/null +++ b/incubator/exporter-stdout/src/main/resources/META-INF/services/io.aklivity.zilla.runtime.engine.exporter.ExporterFactorySpi @@ -0,0 +1 @@ +io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterFactorySpi \ No newline at end of file diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactoryTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactoryTest.java new file mode 100644 index 0000000000..3389e46b3a --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactoryTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.mock; + +import java.net.URL; + +import org.junit.Test; + +import io.aklivity.zilla.runtime.engine.Configuration; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.exporter.Exporter; +import io.aklivity.zilla.runtime.engine.exporter.ExporterContext; +import io.aklivity.zilla.runtime.engine.exporter.ExporterFactory; + +public final class StdoutExporterFactoryTest +{ + @Test + public void shouldLoadAndCreate() + { + // GIVEN + Configuration config = new Configuration(); + ExporterFactory factory = ExporterFactory.instantiate(); + + // WHEN + Exporter exporter = factory.create("stdout", config); + ExporterContext context = exporter.supply(mock(EngineContext.class)); + + // THEN + assertThat(exporter, instanceOf(StdoutExporter.class)); + assertThat(exporter.name(), equalTo("stdout")); + assertThat(exporter.type(), instanceOf(URL.class)); + assertThat(context, instanceOf(ExporterContext.class)); + } +} diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfigAdapterTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfigAdapterTest.java new file mode 100644 index 0000000000..a0fdab3dbe --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/config/StdoutOptionsConfigAdapterTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.config; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +import jakarta.json.bind.Jsonb; +import jakarta.json.bind.JsonbBuilder; +import jakarta.json.bind.JsonbConfig; + +import org.junit.Before; +import org.junit.Test; + +public class StdoutOptionsConfigAdapterTest +{ + private Jsonb jsonb; + + @Before + public void initJson() + { + JsonbConfig config = new JsonbConfig() + .withAdapters(new StdoutOptionsConfigAdapter()); + jsonb = JsonbBuilder.create(config); + } + + @Test + public void shouldReadOptions() + { + // GIVEN + String text = "{}"; + + // WHEN + StdoutOptionsConfig options = jsonb.fromJson(text, StdoutOptionsConfig.class); + + // THEN + assertThat(options, not(nullValue())); + } + + @Test + public void shouldWriteOptions() + { + // GIVEN + String expectedText = "{}"; + StdoutOptionsConfig config = new StdoutOptionsConfig(); + + // WHEN + String text = jsonb.toJson(config); + + // THEN + assertThat(text, not(nullValue())); + assertThat(text, equalTo(expectedText)); + } +} diff --git a/incubator/pom.xml b/incubator/pom.xml index faa3f73b59..7f57daef52 100644 --- a/incubator/pom.xml +++ b/incubator/pom.xml @@ -21,6 +21,7 @@ catalog-inline.spec catalog-schema-registry.spec exporter-otlp.spec + exporter-stdout.spec model-avro.spec model-core.spec model-json.spec @@ -37,6 +38,7 @@ command-tune exporter-otlp + exporter-stdout model-avro model-core @@ -86,6 +88,11 @@ exporter-otlp ${project.version} + + ${project.groupId} + exporter-stdout + ${project.version} + ${project.groupId} model-avro diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index 2839008147..e9d09acb7f 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -54,7 +54,6 @@ private void writeEvent( int index, int length) { - // TODO: Ati - include timestamp System.out.printf("%d %s %d %d%n", msgTypeId, buffer, index, length); // TODO: Ati if (position + length > buffer.capacity()) { From a675aac0774f74e2ac4695765c4716ac954179be Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 7 Feb 2024 14:03:21 +0100 Subject: [PATCH 039/167] WIP EventsLayout --- incubator/exporter-stdout/pom.xml | 2 +- .../engine/internal/layouts/EventsLayout.java | 29 ++++++++----------- .../internal/registry/EngineWorker.java | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 36f6a94359..fa454d606a 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,7 +26,7 @@ 11 11 - 0.65 + 0.50 2 diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index e9d09acb7f..fe9c0b8754 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -27,20 +27,20 @@ import org.agrona.DirectBuffer; import org.agrona.concurrent.AtomicBuffer; import org.agrona.concurrent.UnsafeBuffer; +import org.agrona.concurrent.ringbuffer.OneToOneRingBuffer; +import org.agrona.concurrent.ringbuffer.RingBuffer; +import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; public final class EventsLayout implements AutoCloseable { - private final AtomicBuffer buffer; - - private int position; + private final RingBuffer buffer; private EventsLayout( - AtomicBuffer buffer) + RingBuffer buffer) { this.buffer = buffer; - this.position = 0; } public MessageConsumer supplyWriter() @@ -55,18 +55,13 @@ private void writeEvent( int length) { System.out.printf("%d %s %d %d%n", msgTypeId, buffer, index, length); // TODO: Ati - if (position + length > buffer.capacity()) - { - throw new IllegalStateException("Event buffer is full."); - } - buffer.putBytes(position, recordBuffer, index, length); - position += length; + buffer.write(msgTypeId, recordBuffer, index, length); } @Override public void close() { - unmap(buffer.byteBuffer()); + unmap(buffer.buffer().byteBuffer()); } public static final class Builder @@ -75,10 +70,10 @@ public static final class Builder private Path path; private boolean readonly; - public Builder streamsCapacity( - long streamsCapacity) + public Builder capacity( + long capacity) { - this.capacity = streamsCapacity; + this.capacity = capacity; return this; } @@ -101,11 +96,11 @@ public EventsLayout build() final File layoutFile = path.toFile(); if (!readonly) { - CloseHelper.close(createEmptyFile(layoutFile, capacity)); + CloseHelper.close(createEmptyFile(layoutFile, capacity + RingBufferDescriptor.TRAILER_LENGTH)); } final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); - return new EventsLayout(atomicBuffer); + return new EventsLayout(new OneToOneRingBuffer(atomicBuffer)); } } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index b74cab22cf..b7a03f0bb4 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -289,7 +289,7 @@ public EngineWorker( this.eventsLayout = new EventsLayout.Builder() .path(config.directory().resolve(String.format("events%d", index))) - .streamsCapacity(config.streamsBufferCapacity()) + .capacity(config.streamsBufferCapacity()) .readonly(readonly) .build(); From da360317695e849c3d8e8a38d55fea6f1236ed81 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 7 Feb 2024 15:40:13 +0100 Subject: [PATCH 040/167] WIP spy --- incubator/exporter-stdout/pom.xml | 42 ++++- .../internal/StdoutExporterHandler.java | 79 +++++++++- .../stdout/internal/labels/LabelManager.java | 130 +++++++++++++++ .../stdout/internal/layouts/EventsLayout.java | 107 +++++++++++++ .../printer/PrintableEventsStream.java | 109 +++++++++++++ .../internal/spy/OneToOneRingBufferSpy.java | 149 ++++++++++++++++++ .../stdout/internal/spy/RingBufferSpy.java | 39 +++++ .../binding/tcp/internal/TcpEventContext.java | 2 +- specs/binding-tcp.spec/pom.xml | 16 ++ .../src/main/resources/META-INF/zilla/tcp.idl | 0 specs/binding-tls.spec/pom.xml | 16 ++ 11 files changed, 682 insertions(+), 7 deletions(-) create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayout.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/OneToOneRingBufferSpy.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/RingBufferSpy.java rename {runtime/binding-tcp => specs/binding-tcp.spec}/src/main/resources/META-INF/zilla/tcp.idl (100%) diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index fa454d606a..83a00b73b5 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,8 +26,8 @@ 11 11 - 0.50 - 2 + 0.01 + 99 @@ -43,6 +43,42 @@ ${project.version} provided + + ${project.groupId} + binding-http.spec + ${project.version} + provided + + + ${project.groupId} + binding-kafka.spec + ${project.version} + provided + + + ${project.groupId} + binding-mqtt.spec + ${project.version} + provided + + + ${project.groupId} + binding-tcp.spec + ${project.version} + provided + + + ${project.groupId} + binding-tls.spec + ${project.version} + provided + + + ${project.groupId} + catalog-schema-registry.spec + ${project.version} + provided + ${project.groupId} engine @@ -108,7 +144,7 @@ flyweight-maven-plugin ${project.version} - core + core http kafka mqtt schema_registry tcp tls io.aklivity.zilla.runtime.exporter.stdout.internal.types diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index b59027da4d..87aabf6c83 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -14,14 +14,35 @@ */ package io.aklivity.zilla.runtime.exporter.stdout.internal; +import static java.lang.Integer.parseInt; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +import org.agrona.LangUtil; + import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; +import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelManager; +import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayout; +import io.aklivity.zilla.runtime.exporter.stdout.internal.printer.PrintableEventsStream; +import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy.SpyPosition; public class StdoutExporterHandler implements ExporterHandler { + private static final Pattern EVENTS_PATTERN = Pattern.compile("events(\\d+)"); + private final EngineContext context; + private final Path directory; + private final LabelManager labels; + + private PrintableEventsStream[] printables; public StdoutExporterHandler( EngineConfiguration config, @@ -29,23 +50,75 @@ public StdoutExporterHandler( StdoutExporterConfig exporter) { this.context = context; + this.directory = config.directory(); + this.labels = new LabelManager(directory); } @Override public void start() { - // TODO: Ati - System.out.println("Hello, I am StdoutExporterHandler!"); + System.out.println("Hello, I am StdoutExporterHandler.start!"); // TODO: Ati + try (Stream files = Files.walk(directory, 3)) + { + this.printables = files.filter(this::isEventsFile) + .map(this::newPrintable) + .toArray(PrintableEventsStream[]::new); + } + catch (IOException ex) + { + LangUtil.rethrowUnchecked(ex); + } + } @Override public int export() { - return 0; + int workCount = 0; + if (printables != null) + { + for (int i = 0; i < printables.length; i++) + { + // TODO: Ati + workCount += printables[i].process(); + } + } + return workCount; } @Override public void stop() { } + + private boolean isEventsFile( + Path path) + { + final int depth = path.getNameCount() - directory.getNameCount(); + if (depth != 1 || !Files.isRegularFile(path)) + { + return false; + } + + final Matcher matcher = EVENTS_PATTERN.matcher(path.getName(path.getNameCount() - 1).toString()); + return matcher.matches(); + } + + private PrintableEventsStream newPrintable( + Path path) + { + final String filename = path.getFileName().toString(); + final Matcher matcher = EVENTS_PATTERN.matcher(filename); + matcher.matches(); + final int index = parseInt(matcher.group(1)); + + EventsLayout layout = new EventsLayout.Builder() + .path(path) + .readonly(true) + .spyAt(SpyPosition.ZERO) + .build(); + + System.out.printf("hello this is a new PrintableEventsStream: %d%n", index); + return new PrintableEventsStream(index, labels, layout); // TODO: Ati + } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java new file mode 100644 index 0000000000..59bf6ae093 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java @@ -0,0 +1,130 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.labels; + +import static java.nio.channels.Channels.newReader; +import static java.nio.channels.Channels.newWriter; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.nio.file.StandardOpenOption.APPEND; +import static java.nio.file.StandardOpenOption.CREATE; +import static java.nio.file.StandardOpenOption.READ; +import static java.nio.file.StandardOpenOption.WRITE; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.agrona.LangUtil; + +public final class LabelManager +{ + private final List labels; + private final Map labelIds; + private final Path labelsPath; + + private long sizeInBytes; + + public LabelManager( + Path directory) + { + this.labels = new ArrayList<>(); + this.labelIds = new HashMap<>(); + + this.labelsPath = directory.resolve("labels"); + this.sizeInBytes = -1L; + } + + public synchronized int supplyLabelId( + String label) + { + checkSnapshot(); + return labelIds.computeIfAbsent(label, this::nextLabelId); + } + + public synchronized String lookupLabel( + int labelId) + { + if (labelId < 1 || labelId > labels.size()) + { + checkSnapshot(); + } + + return labels.get(labelId - 1); + } + + private int nextLabelId( + String nextLabel) + { + try (FileChannel channel = FileChannel.open(labelsPath, APPEND)) + { + try (BufferedWriter out = new BufferedWriter(newWriter(channel, UTF_8.name()))) + { + out.write(nextLabel); + out.write('\n'); + } + } + catch (IOException ex) + { + LangUtil.rethrowUnchecked(ex); + } + + labels.add(nextLabel); + + return labels.size(); + } + + private void checkSnapshot() + { + try + { + if (!Files.exists(labelsPath)) + { + this.sizeInBytes = -1L; + } + + if (this.sizeInBytes == -1L || this.sizeInBytes < Files.size(labelsPath)) + { + Files.createDirectories(labelsPath.getParent()); + try (FileChannel channel = FileChannel.open(labelsPath, CREATE, READ, WRITE)) + { + labels.clear(); + labelIds.clear(); + + try (BufferedReader in = new BufferedReader(newReader(channel, UTF_8.name()))) + { + for (String label = in.readLine(); label != null; label = in.readLine()) + { + labels.add(label); + labelIds.put(label, labels.size()); + } + + this.sizeInBytes = channel.position(); + } + } + } + } + catch (final IOException ex) + { + LangUtil.rethrowUnchecked(ex); + } + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayout.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayout.java new file mode 100644 index 0000000000..0e58dd7d9a --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayout.java @@ -0,0 +1,107 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.layouts; + +import static org.agrona.IoUtil.createEmptyFile; +import static org.agrona.IoUtil.mapExistingFile; +import static org.agrona.IoUtil.unmap; + +import java.io.File; +import java.nio.MappedByteBuffer; +import java.nio.file.Path; + +import org.agrona.CloseHelper; +import org.agrona.concurrent.AtomicBuffer; +import org.agrona.concurrent.UnsafeBuffer; +import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.OneToOneRingBufferSpy; +import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy.SpyPosition; + +public final class EventsLayout implements AutoCloseable +{ + private final RingBufferSpy buffer; + + private EventsLayout( + RingBufferSpy buffer) + { + this.buffer = buffer; + } + + public RingBufferSpy eventsBuffer() + { + return buffer; + } + + @Override + public void close() + { + unmap(buffer.buffer().byteBuffer()); + } + + public static final class Builder + { + private long capacity; + private Path path; + private boolean readonly; + private SpyPosition position; + + public Builder capacity( + long capacity) + { + this.capacity = capacity; + return this; + } + + public Builder path( + Path path) + { + this.path = path; + return this; + } + + public Builder spyAt( + SpyPosition position) + { + this.position = position; + return this; + } + + public Builder readonly( + boolean readonly) + { + this.readonly = readonly; + return this; + } + + public EventsLayout build() + { + final File layoutFile = path.toFile(); + if (!readonly) + { + CloseHelper.close(createEmptyFile(layoutFile, capacity + RingBufferDescriptor.TRAILER_LENGTH)); + } + final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); + final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); + final OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); + if (position != null) + { + spy.spyAt(position); + } + return new EventsLayout(spy); + } + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java new file mode 100644 index 0000000000..6f0c8b9f12 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java @@ -0,0 +1,109 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.printer; + +import org.agrona.DirectBuffer; +import org.agrona.collections.Int2ObjectHashMap; + +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelManager; +import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayout; +import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; + +public class PrintableEventsStream +{ + private final EventFW eventRO = new EventFW(); + private final HttpEventFW httpEventRO = new HttpEventFW(); + private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); + private final MqttEventFW mqttEventRO = new MqttEventFW(); + private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); + private final TcpEventFW tcpEventRO = new TcpEventFW(); + private final TlsEventFW tlsEventRO = new TlsEventFW(); + private final Int2ObjectHashMap eventHandlers; + private final int index; + private final LabelManager labels; + private final RingBufferSpy eventsBuffer; + + public PrintableEventsStream( + int index, + LabelManager labels, + EventsLayout layout) + { + this.index = index; + this.labels = labels; + this.eventsBuffer = layout.eventsBuffer(); + + final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); + eventHandlers.put(6, (t, b, i, l) -> onTcpEvent(tcpEventRO.wrap(b, i, i + l))); // TODO: Ati + + this.eventHandlers = eventHandlers; + } + + public int process() + { + return eventsBuffer.spy(this::handleFrame, 1); + } + + @SuppressWarnings("checkstyle:Regexp") + private boolean handleFrame( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + // TODO: Ati + System.out.printf("[PrintableEventsStream.handleFrame] %d %s %d %d%n", msgTypeId, buffer, index, length); + + final EventFW event = eventRO.wrap(buffer, index, index + length); + final long timestamp = event.timestamp(); + + // TODO: Ati - chk timestamp ? + + final MessageConsumer handler = eventHandlers.get(msgTypeId); + if (handler != null) + { + handler.accept(msgTypeId, buffer, index, length); + } + + /*final FrameFW frame = frameRO.wrap(buffer, index, index + length); + final long timestamp = frame.timestamp(); + + if (!nextTimestamp.test(timestamp)) + { + return false; + } + + final MessageConsumer handler = frameHandlers.get(msgTypeId); + if (handler != null) + { + handler.accept(msgTypeId, buffer, index, length); + }*/ + + return true; + } + + private void onTcpEvent( + final TcpEventFW tcpEvent) + { + System.out.printf("hello onTcpEvent %s%n", tcpEvent); + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/OneToOneRingBufferSpy.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/OneToOneRingBufferSpy.java new file mode 100644 index 0000000000..c2db6c7280 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/OneToOneRingBufferSpy.java @@ -0,0 +1,149 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.spy; + +import static org.agrona.BitUtil.align; +import static org.agrona.concurrent.ringbuffer.RecordDescriptor.ALIGNMENT; +import static org.agrona.concurrent.ringbuffer.RecordDescriptor.HEADER_LENGTH; +import static org.agrona.concurrent.ringbuffer.RecordDescriptor.lengthOffset; +import static org.agrona.concurrent.ringbuffer.RecordDescriptor.typeOffset; +import static org.agrona.concurrent.ringbuffer.RingBuffer.PADDING_MSG_TYPE_ID; +import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.HEAD_POSITION_OFFSET; +import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.TAIL_POSITION_OFFSET; +import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.TRAILER_LENGTH; +import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.checkCapacity; + +import java.util.concurrent.atomic.AtomicLong; + +import org.agrona.DirectBuffer; +import org.agrona.concurrent.AtomicBuffer; + +import io.aklivity.zilla.runtime.engine.binding.function.MessagePredicate; + +public class OneToOneRingBufferSpy implements RingBufferSpy +{ + private final int capacity; + private final AtomicLong spyPosition; + private final AtomicBuffer buffer; + + public OneToOneRingBufferSpy( + final AtomicBuffer buffer) + { + this.buffer = buffer; + checkCapacity(buffer.capacity()); + capacity = buffer.capacity() - TRAILER_LENGTH; + + buffer.verifyAlignment(); + + spyPosition = new AtomicLong(); + } + + @Override + public void spyAt( + SpyPosition position) + { + switch (position) + { + case ZERO: + spyPosition.lazySet(0); + break; + case HEAD: + spyPosition.lazySet(buffer.getLong(capacity + HEAD_POSITION_OFFSET)); + break; + case TAIL: + spyPosition.lazySet(buffer.getLong(capacity + TAIL_POSITION_OFFSET)); + break; + } + } + + @Override + public DirectBuffer buffer() + { + return buffer; + } + + @Override + public long producerPosition() + { + return buffer.getLong(buffer.capacity() - TRAILER_LENGTH + TAIL_POSITION_OFFSET); + } + + @Override + public long consumerPosition() + { + return buffer.getLong(buffer.capacity() - TRAILER_LENGTH + HEAD_POSITION_OFFSET); + } + + @Override + public int spy( + final MessagePredicate handler) + { + return spy(handler, Integer.MAX_VALUE); + } + + @Override + public int spy( + final MessagePredicate handler, + final int messageCountLimit) + { + int messagesRead = 0; + + final AtomicBuffer buffer = this.buffer; + final long head = spyPosition.get(); + + int bytesRead = 0; + + final int capacity = this.capacity; + final int headIndex = (int)head & (capacity - 1); + final int contiguousBlockLength = capacity - headIndex; + + try + { + while (bytesRead < contiguousBlockLength && messagesRead < messageCountLimit) + { + final int recordIndex = headIndex + bytesRead; + final int recordLength = buffer.getIntVolatile(lengthOffset(recordIndex)); + if (recordLength <= 0) + { + break; + } + + bytesRead += align(recordLength, ALIGNMENT); + + final int messageTypeId = buffer.getInt(typeOffset(recordIndex)); + if (PADDING_MSG_TYPE_ID == messageTypeId) + { + continue; + } + + ++messagesRead; + if (!handler.test(messageTypeId, buffer, recordIndex + HEADER_LENGTH, recordLength - HEADER_LENGTH)) + { + bytesRead -= align(recordLength, ALIGNMENT); + break; + } + } + } + finally + { + if (bytesRead != 0) + { + spyPosition.lazySet(head + bytesRead); + } + } + + return messagesRead; + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/RingBufferSpy.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/RingBufferSpy.java new file mode 100644 index 0000000000..56ed048be8 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/RingBufferSpy.java @@ -0,0 +1,39 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.spy; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.engine.binding.function.MessagePredicate; + +public interface RingBufferSpy +{ + enum SpyPosition + { + ZERO, + HEAD, + TAIL + } + + void spyAt(SpyPosition position); + + int spy(MessagePredicate handler); + int spy(MessagePredicate handler, int messageCountLimit); + + long producerPosition(); + long consumerPosition(); + + DirectBuffer buffer(); +} diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index b7f4c53c49..e6e5700f9e 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -59,6 +59,6 @@ public void remoteAccessFailed( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); + logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); // TODO: Ati - typeId: proxy -> tcp|tls } } diff --git a/specs/binding-tcp.spec/pom.xml b/specs/binding-tcp.spec/pom.xml index 3a64fc98ba..94ef266ac7 100644 --- a/specs/binding-tcp.spec/pom.xml +++ b/specs/binding-tcp.spec/pom.xml @@ -73,6 +73,22 @@ org.jasig.maven maven-notice-plugin + + ${project.groupId} + flyweight-maven-plugin + ${project.version} + + core tcp proxy + io.aklivity.zilla.specs.binding.tcp.internal.types + + + + + generate + + + + com.mycila license-maven-plugin diff --git a/runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl b/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl similarity index 100% rename from runtime/binding-tcp/src/main/resources/META-INF/zilla/tcp.idl rename to specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl diff --git a/specs/binding-tls.spec/pom.xml b/specs/binding-tls.spec/pom.xml index dd0ca5341e..d38dbf81e7 100644 --- a/specs/binding-tls.spec/pom.xml +++ b/specs/binding-tls.spec/pom.xml @@ -78,6 +78,22 @@ org.jasig.maven maven-notice-plugin + + ${project.groupId} + flyweight-maven-plugin + ${project.version} + + core tls proxy + io.aklivity.zilla.specs.binding.tls.internal.types + + + + + generate + + + + com.mycila license-maven-plugin From 907aacca90744943ef1c016c292c3712102829d8 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 8 Feb 2024 12:08:09 +0100 Subject: [PATCH 041/167] WIP PrintableEventsStream --- .../internal/StdoutExporterContext.java | 2 +- .../internal/StdoutExporterHandler.java | 22 ++--- .../stdout/internal/labels/LabelManager.java | 28 +----- .../printer/PrintableEventsStream.java | 87 ++++++++++++------- .../tcp/internal/stream/TcpClientFactory.java | 2 +- .../tls/internal/stream/TlsClientFactory.java | 2 +- .../tls/internal/stream/TlsServerFactory.java | 2 +- 7 files changed, 76 insertions(+), 69 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java index f50d89a44b..7d038890a7 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java @@ -48,7 +48,7 @@ public ExporterHandler attach( LongFunction resolveKind) { StdoutExporterConfig stdoutExporter = new StdoutExporterConfig(exporter); - return new StdoutExporterHandler(config, context, stdoutExporter); + return new StdoutExporterHandler(config, context, stdoutExporter, System.out); } @Override diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 87aabf6c83..db90d5df0d 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -14,9 +14,8 @@ */ package io.aklivity.zilla.runtime.exporter.stdout.internal; -import static java.lang.Integer.parseInt; - import java.io.IOException; +import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.regex.Matcher; @@ -41,23 +40,26 @@ public class StdoutExporterHandler implements ExporterHandler private final EngineContext context; private final Path directory; private final LabelManager labels; + private final PrintStream out; private PrintableEventsStream[] printables; public StdoutExporterHandler( EngineConfiguration config, EngineContext context, - StdoutExporterConfig exporter) + StdoutExporterConfig exporter, + PrintStream out) { this.context = context; this.directory = config.directory(); this.labels = new LabelManager(directory); + this.out = out; } @Override public void start() { - System.out.println("Hello, I am StdoutExporterHandler.start!"); // TODO: Ati + //System.out.println("Hello, I am StdoutExporterHandler.start!"); // TODO: Ati try (Stream files = Files.walk(directory, 3)) { this.printables = files.filter(this::isEventsFile) @@ -107,10 +109,10 @@ private boolean isEventsFile( private PrintableEventsStream newPrintable( Path path) { - final String filename = path.getFileName().toString(); - final Matcher matcher = EVENTS_PATTERN.matcher(filename); - matcher.matches(); - final int index = parseInt(matcher.group(1)); + //final String filename = path.getFileName().toString(); + //final Matcher matcher = EVENTS_PATTERN.matcher(filename); + //matcher.matches(); + //final int index = parseInt(matcher.group(1)); EventsLayout layout = new EventsLayout.Builder() .path(path) @@ -118,7 +120,7 @@ private PrintableEventsStream newPrintable( .spyAt(SpyPosition.ZERO) .build(); - System.out.printf("hello this is a new PrintableEventsStream: %d%n", index); - return new PrintableEventsStream(index, labels, layout); // TODO: Ati + //System.out.printf("hello this is a new PrintableEventsStream: %d%n", index); + return new PrintableEventsStream(labels, layout, out); // TODO: Ati } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java index 59bf6ae093..203a7f9cc6 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java @@ -15,15 +15,12 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.labels; import static java.nio.channels.Channels.newReader; -import static java.nio.channels.Channels.newWriter; import static java.nio.charset.StandardCharsets.UTF_8; -import static java.nio.file.StandardOpenOption.APPEND; import static java.nio.file.StandardOpenOption.CREATE; import static java.nio.file.StandardOpenOption.READ; import static java.nio.file.StandardOpenOption.WRITE; import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.IOException; import java.nio.channels.FileChannel; import java.nio.file.Files; @@ -53,11 +50,11 @@ public LabelManager( this.sizeInBytes = -1L; } - public synchronized int supplyLabelId( + public synchronized int lookupLabelId( String label) { checkSnapshot(); - return labelIds.computeIfAbsent(label, this::nextLabelId); + return labelIds.getOrDefault(label, 0); } public synchronized String lookupLabel( @@ -71,27 +68,6 @@ public synchronized String lookupLabel( return labels.get(labelId - 1); } - private int nextLabelId( - String nextLabel) - { - try (FileChannel channel = FileChannel.open(labelsPath, APPEND)) - { - try (BufferedWriter out = new BufferedWriter(newWriter(channel, UTF_8.name()))) - { - out.write(nextLabel); - out.write('\n'); - } - } - catch (IOException ex) - { - LangUtil.rethrowUnchecked(ex); - } - - labels.add(nextLabel); - - return labels.size(); - } - private void checkSnapshot() { try diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java index 6f0c8b9f12..e098c44126 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java @@ -14,6 +14,8 @@ */ package io.aklivity.zilla.runtime.exporter.stdout.internal.printer; +import java.io.PrintStream; + import org.agrona.DirectBuffer; import org.agrona.collections.Int2ObjectHashMap; @@ -21,61 +23,77 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelManager; import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayout; import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpRemoteAccessFailedEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; public class PrintableEventsStream { + private static final String TCP_REMOTE_ACCESS_FAILED_FORMAT = + "ERROR: Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [bindingId = 0x%016x] [address = %s]%n"; + private final EventFW eventRO = new EventFW(); private final HttpEventFW httpEventRO = new HttpEventFW(); private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); private final MqttEventFW mqttEventRO = new MqttEventFW(); private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); private final TcpEventFW tcpEventRO = new TcpEventFW(); + private final TcpRemoteAccessFailedEventFW tcpRemoteAccessFailedEventRO = new TcpRemoteAccessFailedEventFW(); private final TlsEventFW tlsEventRO = new TlsEventFW(); - private final Int2ObjectHashMap eventHandlers; - private final int index; + private final LabelManager labels; private final RingBufferSpy eventsBuffer; + private final PrintStream out; + private final Int2ObjectHashMap eventHandlers; public PrintableEventsStream( - int index, LabelManager labels, - EventsLayout layout) + EventsLayout layout, + PrintStream out) { - this.index = index; this.labels = labels; this.eventsBuffer = layout.eventsBuffer(); + this.out = out; final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); - eventHandlers.put(6, (t, b, i, l) -> onTcpEvent(tcpEventRO.wrap(b, i, i + l))); // TODO: Ati - + addEventHandler(labels, eventHandlers, "tcp", this::handleTcpEvent); + addEventHandler(labels, eventHandlers, "http", this::handleHttpEvent); + // TODO: Ati - add more this.eventHandlers = eventHandlers; } + private void addEventHandler( + LabelManager labels, + Int2ObjectHashMap eventHandlers, + String type, + MessageConsumer consumer) + { + int labelId = labels.lookupLabelId(type); + if (labelId != 0) + { + eventHandlers.put(labelId, consumer); + } + } + public int process() { - return eventsBuffer.spy(this::handleFrame, 1); + return eventsBuffer.spy(this::handleEvent, 1); } - @SuppressWarnings("checkstyle:Regexp") - private boolean handleFrame( + private boolean handleEvent( int msgTypeId, DirectBuffer buffer, int index, int length) { - // TODO: Ati - System.out.printf("[PrintableEventsStream.handleFrame] %d %s %d %d%n", msgTypeId, buffer, index, length); - final EventFW event = eventRO.wrap(buffer, index, index + length); final long timestamp = event.timestamp(); - // TODO: Ati - chk timestamp ? final MessageConsumer handler = eventHandlers.get(msgTypeId); @@ -83,27 +101,38 @@ private boolean handleFrame( { handler.accept(msgTypeId, buffer, index, length); } + return true; + } - /*final FrameFW frame = frameRO.wrap(buffer, index, index + length); - final long timestamp = frame.timestamp(); - - if (!nextTimestamp.test(timestamp)) + private void handleTcpEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + final TcpEventFW event = tcpEventRO.wrap(buffer, index, index + length); + switch (event.kind()) { - return false; + case REMOTE_ACCESS_FAILED: + TcpRemoteAccessFailedEventFW e = event.remoteAccessFailed(); + out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), e.bindingId(), asString(e.address())); + break; } + } - final MessageConsumer handler = frameHandlers.get(msgTypeId); - if (handler != null) - { - handler.accept(msgTypeId, buffer, index, length); - }*/ - - return true; + private void handleHttpEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + // TODO: Ati } - private void onTcpEvent( - final TcpEventFW tcpEvent) + private String asString( + StringFW stringFW) { - System.out.printf("hello onTcpEvent %s%n", tcpEvent); + String s = stringFW.asString(); + return s == null ? "" : s; } } diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 3b33adee33..497753e6a9 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -117,7 +117,7 @@ public TcpClientFactory( this.initialMax = bufferPool.slotCapacity(); this.windowThreshold = (bufferPool.slotCapacity() * config.windowThreshold()) / 100; - this.event = new TcpEventContext(proxyTypeId, context); + this.event = new TcpEventContext(context.supplyTypeId("tcp"), context); } @Override diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index 50dc37bd64..1fa9873d64 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -171,7 +171,7 @@ public TlsClientFactory( this.initialPadAdjust = Math.max(context.bufferPool().slotCapacity() >> 14, 1) * MAXIMUM_HEADER_SIZE; this.bindings = new Long2ObjectHashMap<>(); - this.event = new TlsEventContext(proxyTypeId, context); + this.event = new TlsEventContext(context.supplyTypeId("tls"), context); this.inNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity()); this.inNetBuffer = new UnsafeBuffer(inNetByteBuffer); this.outNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity() << 1); diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index 4c4402cc8a..9f8e484344 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -186,7 +186,7 @@ public TlsServerFactory( this.handshakeMax = Math.min(config.handshakeWindowBytes(), decodeMax); this.handshakeTimeoutMillis = SECONDS.toMillis(config.handshakeTimeout()); this.bindings = new Long2ObjectHashMap<>(); - this.event = new TlsEventContext(proxyTypeId, context); + this.event = new TlsEventContext(context.supplyTypeId("tls"), context); this.inNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity()); this.inNetBuffer = new UnsafeBuffer(inNetByteBuffer); From b972881fee8804d01e050526734e6c4210e74fa0 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 8 Feb 2024 12:23:16 +0100 Subject: [PATCH 042/167] fix --- .../zilla/runtime/binding/tcp/internal/TcpEventContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index e6e5700f9e..b7f4c53c49 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -59,6 +59,6 @@ public void remoteAccessFailed( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); // TODO: Ati - typeId: proxy -> tcp|tls + logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); } } From 50837581fb538e8fc138d7cc98c0cf6b384bce5f Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 8 Feb 2024 12:33:54 +0100 Subject: [PATCH 043/167] fix --- .../internal/StdoutExporterHandler.java | 11 +------ .../printer/PrintableEventsStream.java | 31 ++++++++++++++----- .../binding/tcp/internal/TcpEventContext.java | 1 - .../engine/internal/layouts/EventsLayout.java | 1 - 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index db90d5df0d..49bd12913e 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -59,7 +59,6 @@ public StdoutExporterHandler( @Override public void start() { - //System.out.println("Hello, I am StdoutExporterHandler.start!"); // TODO: Ati try (Stream files = Files.walk(directory, 3)) { this.printables = files.filter(this::isEventsFile) @@ -81,7 +80,6 @@ public int export() { for (int i = 0; i < printables.length; i++) { - // TODO: Ati workCount += printables[i].process(); } } @@ -109,18 +107,11 @@ private boolean isEventsFile( private PrintableEventsStream newPrintable( Path path) { - //final String filename = path.getFileName().toString(); - //final Matcher matcher = EVENTS_PATTERN.matcher(filename); - //matcher.matches(); - //final int index = parseInt(matcher.group(1)); - EventsLayout layout = new EventsLayout.Builder() .path(path) .readonly(true) .spyAt(SpyPosition.ZERO) .build(); - - //System.out.printf("hello this is a new PrintableEventsStream: %d%n", index); - return new PrintableEventsStream(labels, layout, out); // TODO: Ati + return new PrintableEventsStream(labels, layout, out); } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java index e098c44126..4a976eddd5 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java @@ -36,7 +36,7 @@ public class PrintableEventsStream { private static final String TCP_REMOTE_ACCESS_FAILED_FORMAT = - "ERROR: Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [bindingId = 0x%016x] [address = %s]%n"; + "ERROR: Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s] [address = %s]%n"; private final EventFW eventRO = new EventFW(); private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -92,10 +92,6 @@ private boolean handleEvent( int index, int length) { - final EventFW event = eventRO.wrap(buffer, index, index + length); - final long timestamp = event.timestamp(); - // TODO: Ati - chk timestamp ? - final MessageConsumer handler = eventHandlers.get(msgTypeId); if (handler != null) { @@ -115,7 +111,8 @@ private void handleTcpEvent( { case REMOTE_ACCESS_FAILED: TcpRemoteAccessFailedEventFW e = event.remoteAccessFailed(); - out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), e.bindingId(), asString(e.address())); + out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), asBinding(e.bindingId()), + asString(e.address())); break; } } @@ -129,10 +126,30 @@ private void handleHttpEvent( // TODO: Ati } - private String asString( + private String asBinding( + long bindingId) + { + String namespace = labels.lookupLabel(namespaceId(bindingId)); + String binding = labels.lookupLabel(localId(bindingId)); + return String.format("%s.%s", namespace, binding); + } + + private static String asString( StringFW stringFW) { String s = stringFW.asString(); return s == null ? "" : s; } + + public static int namespaceId( + long bindingId) + { + return (int)(bindingId >> Integer.SIZE) & 0xffff_ffff; + } + + private static int localId( + long bindingId) + { + return (int)(bindingId >> 0) & 0xffff_ffff; + } } diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index b7f4c53c49..dafcae76ba 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -58,7 +58,6 @@ public void remoteAccessFailed( .address(address) ) .build(); - System.out.println(event); // TODO: Ati logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index fe9c0b8754..010dc30c83 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -54,7 +54,6 @@ private void writeEvent( int index, int length) { - System.out.printf("%d %s %d %d%n", msgTypeId, buffer, index, length); // TODO: Ati buffer.write(msgTypeId, recordBuffer, index, length); } From 168cad4e57622f29cadc23b38b7f1922f73670e6 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 8 Feb 2024 15:37:43 +0100 Subject: [PATCH 044/167] fix --- .../runtime/exporter/stdout/internal/StdoutExporterHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 49bd12913e..245287dfbc 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -62,6 +62,7 @@ public void start() try (Stream files = Files.walk(directory, 3)) { this.printables = files.filter(this::isEventsFile) + .sorted() .map(this::newPrintable) .toArray(PrintableEventsStream[]::new); } From 54447ad5d9603aef935aedc354a5b91131e63329 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 8 Feb 2024 16:15:20 +0100 Subject: [PATCH 045/167] fix capacity --- .../zilla/runtime/engine/EngineConfiguration.java | 14 ++++++++++++++ .../engine/internal/registry/EngineWorker.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineConfiguration.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineConfiguration.java index 8ef1e2723a..4cd79e9eed 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineConfiguration.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineConfiguration.java @@ -52,6 +52,7 @@ public class EngineConfiguration extends Configuration public static final IntPropertyDef ENGINE_BUFFER_POOL_CAPACITY; public static final IntPropertyDef ENGINE_BUFFER_SLOT_CAPACITY; public static final IntPropertyDef ENGINE_STREAMS_BUFFER_CAPACITY; + public static final IntPropertyDef ENGINE_EVENTS_BUFFER_CAPACITY; public static final IntPropertyDef ENGINE_COUNTERS_BUFFER_CAPACITY; public static final IntPropertyDef ENGINE_BUDGETS_BUFFER_CAPACITY; public static final BooleanPropertyDef ENGINE_TIMESTAMPS; @@ -88,6 +89,8 @@ public class EngineConfiguration extends Configuration ENGINE_BUFFER_SLOT_CAPACITY = config.property("buffer.slot.capacity", 64 * 1024); ENGINE_STREAMS_BUFFER_CAPACITY = config.property("streams.buffer.capacity", EngineConfiguration::defaultStreamsBufferCapacity); + ENGINE_EVENTS_BUFFER_CAPACITY = config.property("events.buffer.capacity", + EngineConfiguration::defaultEventsBufferCapacity); ENGINE_BUDGETS_BUFFER_CAPACITY = config.property("budgets.buffer.capacity", EngineConfiguration::defaultBudgetsBufferCapacity); ENGINE_COUNTERS_BUFFER_CAPACITY = config.property("counters.buffer.capacity", 1024 * 1024); @@ -179,6 +182,11 @@ public int streamsBufferCapacity() return ENGINE_STREAMS_BUFFER_CAPACITY.getAsInt(this); } + public int eventsBufferCapacity() + { + return ENGINE_EVENTS_BUFFER_CAPACITY.getAsInt(this); + } + public int countersBufferCapacity() { return ENGINE_COUNTERS_BUFFER_CAPACITY.getAsInt(this); @@ -276,6 +284,12 @@ private static int defaultStreamsBufferCapacity( return ENGINE_BUFFER_SLOT_CAPACITY.get(config) * ENGINE_WORKER_CAPACITY.getAsInt(config); } + private static int defaultEventsBufferCapacity( + Configuration config) + { + return ENGINE_BUFFER_SLOT_CAPACITY.get(config) * ENGINE_WORKER_CAPACITY.getAsInt(config); + } + private static int defaultBudgetsBufferCapacity( Configuration config) { diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index b7a03f0bb4..8ec283672e 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -289,7 +289,7 @@ public EngineWorker( this.eventsLayout = new EventsLayout.Builder() .path(config.directory().resolve(String.format("events%d", index))) - .capacity(config.streamsBufferCapacity()) + .capacity(config.eventsBufferCapacity()) .readonly(readonly) .build(); From a04f78f8b78756ad0ce4acbb415d075de35127c0 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 8 Feb 2024 17:02:26 +0100 Subject: [PATCH 046/167] WIP EventsLayoutReader rotate --- .../internal/StdoutExporterHandler.java | 10 +-- .../{LabelManager.java => LabelReader.java} | 6 +- ...ntsLayout.java => EventsLayoutReader.java} | 83 ++++++++++++++----- .../printer/PrintableEventsStream.java | 19 ++--- .../engine/internal/layouts/EventsLayout.java | 69 ++++++++++++--- 5 files changed, 136 insertions(+), 51 deletions(-) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/{LabelManager.java => LabelReader.java} (96%) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/{EventsLayout.java => EventsLayoutReader.java} (50%) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 245287dfbc..4af84e27fd 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -28,8 +28,8 @@ import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; -import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelManager; -import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayout; +import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelReader; +import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayoutReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.printer.PrintableEventsStream; import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy.SpyPosition; @@ -39,7 +39,7 @@ public class StdoutExporterHandler implements ExporterHandler private final EngineContext context; private final Path directory; - private final LabelManager labels; + private final LabelReader labels; private final PrintStream out; private PrintableEventsStream[] printables; @@ -52,7 +52,7 @@ public StdoutExporterHandler( { this.context = context; this.directory = config.directory(); - this.labels = new LabelManager(directory); + this.labels = new LabelReader(directory); this.out = out; } @@ -108,7 +108,7 @@ private boolean isEventsFile( private PrintableEventsStream newPrintable( Path path) { - EventsLayout layout = new EventsLayout.Builder() + EventsLayoutReader layout = new EventsLayoutReader.Builder() .path(path) .readonly(true) .spyAt(SpyPosition.ZERO) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java similarity index 96% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java index 203a7f9cc6..6eca187312 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelManager.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java @@ -32,7 +32,7 @@ import org.agrona.LangUtil; -public final class LabelManager +public final class LabelReader { private final List labels; private final Map labelIds; @@ -40,10 +40,10 @@ public final class LabelManager private long sizeInBytes; - public LabelManager( + public LabelReader( Path directory) { - this.labels = new ArrayList<>(); + this.labels = new ArrayList<>(); this.labelIds = new HashMap<>(); this.labelsPath = directory.resolve("labels"); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayout.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayoutReader.java similarity index 50% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayout.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayoutReader.java index 0e58dd7d9a..4c075b27fa 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayout.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayoutReader.java @@ -14,31 +14,42 @@ */ package io.aklivity.zilla.runtime.exporter.stdout.internal.layouts; -import static org.agrona.IoUtil.createEmptyFile; import static org.agrona.IoUtil.mapExistingFile; import static org.agrona.IoUtil.unmap; +import static org.agrona.LangUtil.rethrowUnchecked; import java.io.File; import java.nio.MappedByteBuffer; +import java.nio.file.FileSystems; import java.nio.file.Path; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; -import org.agrona.CloseHelper; import org.agrona.concurrent.AtomicBuffer; import org.agrona.concurrent.UnsafeBuffer; -import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.OneToOneRingBufferSpy; import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy; import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy.SpyPosition; -public final class EventsLayout implements AutoCloseable +public final class EventsLayoutReader implements AutoCloseable { - private final RingBufferSpy buffer; + private final Path path; + private final SpyPosition position; + private RingBufferSpy buffer; - private EventsLayout( + private EventsLayoutReader( + Path path, + SpyPosition position, RingBufferSpy buffer) { + this.path = path; + this.position = position; this.buffer = buffer; + Thread watcher = new Thread(this::watch); + watcher.start(); } public RingBufferSpy eventsBuffer() @@ -52,6 +63,49 @@ public void close() unmap(buffer.buffer().byteBuffer()); } + private void watch() + { + try + { + WatchService watchService = FileSystems.getDefault().newWatchService(); + path.getParent().register(watchService, StandardWatchEventKinds.ENTRY_MODIFY); + while (true) + { + WatchKey key = watchService.take(); + for (WatchEvent event : key.pollEvents()) + { + Path changedPath = (Path) event.context(); + if (path.getFileName().equals(changedPath.getFileName())) + { + close(); + buffer = createRingBufferSpy(path, position); + } + } + key.reset(); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + rethrowUnchecked(ex); + } + } + + private static RingBufferSpy createRingBufferSpy( + Path path, + SpyPosition position) + { + final File layoutFile = path.toFile(); + final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); + final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); + final OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); + if (position != null) + { + spy.spyAt(position); + } + return spy; + } + public static final class Builder { private long capacity; @@ -87,21 +141,10 @@ public Builder readonly( return this; } - public EventsLayout build() + public EventsLayoutReader build() { - final File layoutFile = path.toFile(); - if (!readonly) - { - CloseHelper.close(createEmptyFile(layoutFile, capacity + RingBufferDescriptor.TRAILER_LENGTH)); - } - final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); - final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); - final OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); - if (position != null) - { - spy.spyAt(position); - } - return new EventsLayout(spy); + RingBufferSpy spy = createRingBufferSpy(path, position); + return new EventsLayoutReader(path, position, spy); } } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java index 4a976eddd5..bd5acf22ef 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java @@ -20,9 +20,8 @@ import org.agrona.collections.Int2ObjectHashMap; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelManager; -import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayout; -import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelReader; +import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayoutReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; @@ -47,18 +46,18 @@ public class PrintableEventsStream private final TcpRemoteAccessFailedEventFW tcpRemoteAccessFailedEventRO = new TcpRemoteAccessFailedEventFW(); private final TlsEventFW tlsEventRO = new TlsEventFW(); - private final LabelManager labels; - private final RingBufferSpy eventsBuffer; + private final LabelReader labels; + private final EventsLayoutReader layout; private final PrintStream out; private final Int2ObjectHashMap eventHandlers; public PrintableEventsStream( - LabelManager labels, - EventsLayout layout, + LabelReader labels, + EventsLayoutReader layout, PrintStream out) { this.labels = labels; - this.eventsBuffer = layout.eventsBuffer(); + this.layout = layout; this.out = out; final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); @@ -69,7 +68,7 @@ public PrintableEventsStream( } private void addEventHandler( - LabelManager labels, + LabelReader labels, Int2ObjectHashMap eventHandlers, String type, MessageConsumer consumer) @@ -83,7 +82,7 @@ private void addEventHandler( public int process() { - return eventsBuffer.spy(this::handleEvent, 1); + return layout.eventsBuffer().spy(this::handleEvent, 1); } private boolean handleEvent( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index 010dc30c83..6fe93fee75 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -18,10 +18,16 @@ import static org.agrona.IoUtil.createEmptyFile; import static org.agrona.IoUtil.mapExistingFile; import static org.agrona.IoUtil.unmap; +import static org.agrona.LangUtil.rethrowUnchecked; import java.io.File; +import java.io.IOException; import java.nio.MappedByteBuffer; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.text.SimpleDateFormat; +import java.util.Date; import org.agrona.CloseHelper; import org.agrona.DirectBuffer; @@ -35,12 +41,18 @@ public final class EventsLayout implements AutoCloseable { - private final RingBuffer buffer; + private final Path path; + private final long capacity; + private RingBuffer buffer; private EventsLayout( + Path path, + long capacity, RingBuffer buffer) { this.buffer = buffer; + this.capacity = capacity; + this.path = path; } public MessageConsumer supplyWriter() @@ -48,19 +60,56 @@ public MessageConsumer supplyWriter() return this::writeEvent; } + @Override + public void close() + { + unmap(buffer.buffer().byteBuffer()); + } + private void writeEvent( int msgTypeId, DirectBuffer recordBuffer, int index, int length) { - buffer.write(msgTypeId, recordBuffer, index, length); + boolean success = buffer.write(msgTypeId, recordBuffer, index, length); + if (!success) + { + rotateFile(); + buffer.write(msgTypeId, recordBuffer, index, length); + } } - @Override - public void close() + private void rotateFile() { - unmap(buffer.buffer().byteBuffer()); + close(); + String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); + Path newPath = Path.of(String.format("%s_%s", path, timestamp)); + try + { + Files.move(path, newPath, StandardCopyOption.REPLACE_EXISTING); + } + catch (IOException ex) + { + ex.printStackTrace(); + rethrowUnchecked(ex); + } + buffer = createRingBuffer(path, capacity, false); + } + + private static RingBuffer createRingBuffer( + Path path, + long capacity, + boolean readonly) + { + final File layoutFile = path.toFile(); + if (!readonly) + { + CloseHelper.close(createEmptyFile(layoutFile, capacity + RingBufferDescriptor.TRAILER_LENGTH)); + } + final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); + final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); + return new OneToOneRingBuffer(atomicBuffer); } public static final class Builder @@ -92,14 +141,8 @@ public Builder readonly( public EventsLayout build() { - final File layoutFile = path.toFile(); - if (!readonly) - { - CloseHelper.close(createEmptyFile(layoutFile, capacity + RingBufferDescriptor.TRAILER_LENGTH)); - } - final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); - final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); - return new EventsLayout(new OneToOneRingBuffer(atomicBuffer)); + RingBuffer ringBuffer = createRingBuffer(path, capacity, readonly); + return new EventsLayout(path, capacity, ringBuffer); } } } From 056a1a8ff53c379810dab41146e22670b66f70ee Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 10:46:13 +0100 Subject: [PATCH 047/167] fix StdoutEventsStream --- .../internal/StdoutExporterHandler.java | 20 +++++++++---------- .../StdoutEventsStream.java} | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/{printer/PrintableEventsStream.java => stream/StdoutEventsStream.java} (97%) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 4af84e27fd..8bfd4d1054 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -30,8 +30,8 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayoutReader; -import io.aklivity.zilla.runtime.exporter.stdout.internal.printer.PrintableEventsStream; import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.exporter.stdout.internal.stream.StdoutEventsStream; public class StdoutExporterHandler implements ExporterHandler { @@ -42,7 +42,7 @@ public class StdoutExporterHandler implements ExporterHandler private final LabelReader labels; private final PrintStream out; - private PrintableEventsStream[] printables; + private StdoutEventsStream[] stdoutEventStreams; public StdoutExporterHandler( EngineConfiguration config, @@ -61,10 +61,10 @@ public void start() { try (Stream files = Files.walk(directory, 3)) { - this.printables = files.filter(this::isEventsFile) + this.stdoutEventStreams = files.filter(this::isEventsFile) .sorted() - .map(this::newPrintable) - .toArray(PrintableEventsStream[]::new); + .map(this::newStdoutEventsStream) + .toArray(StdoutEventsStream[]::new); } catch (IOException ex) { @@ -77,11 +77,11 @@ public void start() public int export() { int workCount = 0; - if (printables != null) + if (stdoutEventStreams != null) { - for (int i = 0; i < printables.length; i++) + for (int i = 0; i < stdoutEventStreams.length; i++) { - workCount += printables[i].process(); + workCount += stdoutEventStreams[i].process(); } } return workCount; @@ -105,7 +105,7 @@ private boolean isEventsFile( return matcher.matches(); } - private PrintableEventsStream newPrintable( + private StdoutEventsStream newStdoutEventsStream( Path path) { EventsLayoutReader layout = new EventsLayoutReader.Builder() @@ -113,6 +113,6 @@ private PrintableEventsStream newPrintable( .readonly(true) .spyAt(SpyPosition.ZERO) .build(); - return new PrintableEventsStream(labels, layout, out); + return new StdoutEventsStream(labels, layout, out); } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java similarity index 97% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index bd5acf22ef..be027a04df 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/printer/PrintableEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -12,7 +12,7 @@ * WARRANTIES OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package io.aklivity.zilla.runtime.exporter.stdout.internal.printer; +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; @@ -32,7 +32,7 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpRemoteAccessFailedEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; -public class PrintableEventsStream +public class StdoutEventsStream { private static final String TCP_REMOTE_ACCESS_FAILED_FORMAT = "ERROR: Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s] [address = %s]%n"; @@ -51,7 +51,7 @@ public class PrintableEventsStream private final PrintStream out; private final Int2ObjectHashMap eventHandlers; - public PrintableEventsStream( + public StdoutEventsStream( LabelReader labels, EventsLayoutReader layout, PrintStream out) From 9ff65ea595fc99bc0fda06729395e6dbf40b44c1 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 10:49:56 +0100 Subject: [PATCH 048/167] fix schema --- .../stdout/schema/stdout.schema.patch.json | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json index 19fbaa407b..f3f7450945 100644 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/exporter/stdout/schema/stdout.schema.patch.json @@ -26,23 +26,6 @@ "type": { "const": "stdout" - }, - "options": - { - "properties": - { - "level": - { - "enum": - [ - "info", - "warning", - "error" - ], - "default": "info" - } - }, - "additionalProperties": false } } } From c3b8844a1b3caacae89d50e8f89313250512561d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 10:58:08 +0100 Subject: [PATCH 049/167] fix typeId --- .../registry/internal/SchemaRegistryEventContext.java | 6 +++--- .../runtime/binding/http/internal/HttpEventContext.java | 3 +-- .../binding/http/internal/stream/HttpServerFactory.java | 2 +- .../runtime/binding/kafka/internal/KafkaEventContext.java | 3 +-- .../kafka/internal/stream/KafkaClientProduceFactory.java | 2 +- .../kafka/internal/stream/KafkaClientSaslHandshaker.java | 2 +- .../runtime/binding/mqtt/internal/MqttEventContext.java | 3 +-- .../binding/mqtt/internal/stream/MqttServerFactory.java | 2 +- .../runtime/binding/tcp/internal/TcpEventContext.java | 7 +++---- .../binding/tcp/internal/stream/TcpClientFactory.java | 2 +- .../runtime/binding/tls/internal/TlsEventContext.java | 7 +++---- .../binding/tls/internal/stream/TlsClientFactory.java | 2 +- .../binding/tls/internal/stream/TlsServerFactory.java | 2 +- 13 files changed, 19 insertions(+), 24 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index d566ce190b..745cbd1088 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -30,14 +30,14 @@ public class SchemaRegistryEventContext private final SchemaRegistryEventFW.Builder schemaRegistryEventRW = new SchemaRegistryEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); - private final int typeId; + private final int schemaRegistryTypeId; private final MessageConsumer logEvent; private final LongSupplier timestamp; public SchemaRegistryEventContext( EngineContext context) { - this.typeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); + this.schemaRegistryTypeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); this.logEvent = context.logEvent(); this.timestamp = context.timestamp(); } @@ -59,6 +59,6 @@ public void remoteAccessRejected( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); + logEvent.accept(schemaRegistryTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index d70037eb0d..61b8aedd6f 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -37,10 +37,9 @@ public class HttpEventContext private final LongSupplier timestamp; public HttpEventContext( - int httpTypeId, EngineContext context) { - this.httpTypeId = httpTypeId; + this.httpTypeId = context.supplyTypeId(HttpBinding.NAME); this.logEvent = context.logEvent(); this.timestamp = context.timestamp(); } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 7b91743123..910fd7cd51 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -579,7 +579,7 @@ public HttpServerFactory( this.supplyValidator = context::supplyValidator; this.encodeMax = bufferPool.slotCapacity(); this.bindings = new Long2ObjectHashMap<>(); - this.event = new HttpEventContext(httpTypeId, context); + this.event = new HttpEventContext(context); this.headers200 = initHeaders(config, STATUS_200); this.headers204 = initHeaders(config, STATUS_204); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 2005e4d473..718e74db7d 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -37,10 +37,9 @@ public class KafkaEventContext private final LongSupplier timestamp; public KafkaEventContext( - int kafkaTypeId, EngineContext context) { - this.kafkaTypeId = kafkaTypeId; + this.kafkaTypeId = context.supplyTypeId(KafkaBinding.NAME); this.logEvent = context.logEvent(); this.timestamp = context.timestamp(); } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index d66d247471..fe25486485 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -219,7 +219,7 @@ public KafkaClientProduceFactory( this.encodeMaxBytes = Math.min(config.clientProduceMaxBytes(), encodePool.slotCapacity() - PRODUCE_REQUEST_RECORDS_OFFSET_MAX); this.crc32c = new CRC32C(); - this.event = new KafkaEventContext(kafkaTypeId, context); + this.event = new KafkaEventContext(context); } @Override diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index 8e53941e00..d1255dc1f4 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -130,7 +130,7 @@ public KafkaClientSaslHandshaker( this.writeBuffer = new UnsafeBuffer(new byte[context.writeBuffer().capacity()]); this.nonceSupplier = config.nonceSupplier(); this.clientIdsByServer = new Object2ObjectHashMap<>(); - this.event = new KafkaEventContext(context.supplyTypeId(KafkaBinding.NAME), context); + this.event = new KafkaEventContext(context); } public abstract class KafkaSaslClient diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 97e0d31e36..86623b13be 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -37,10 +37,9 @@ public class MqttEventContext private final LongSupplier timestamp; public MqttEventContext( - int mqttTypeId, EngineContext context) { - this.mqttTypeId = mqttTypeId; + this.mqttTypeId = context.supplyTypeId(MqttBinding.NAME); this.logEvent = context.logEvent(); this.timestamp = context.timestamp(); } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index f92731a1e7..5c6be35413 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -530,7 +530,7 @@ public MqttServerFactory( this.decodePacketTypeByVersion.put(MQTT_PROTOCOL_VERSION_5, this::decodePacketTypeV5); this.unreleasedPacketIdsByClientId = unreleasedPacketIdsByClientId; this.supplyValidator = context::supplyValidator; - this.event = new MqttEventContext(mqttTypeId, context); + this.event = new MqttEventContext(context); } @Override diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index dafcae76ba..573e224164 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -31,15 +31,14 @@ public class TcpEventContext private final TcpEventFW.Builder tcpEventRW = new TcpEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); - private final int typeId; + private final int tcpTypeId; private final MessageConsumer logEvent; private final LongSupplier timestamp; public TcpEventContext( - int typeId, EngineContext context) { - this.typeId = typeId; + this.tcpTypeId = context.supplyTypeId(TcpBinding.NAME); this.logEvent = context.logEvent(); this.timestamp = context.timestamp(); } @@ -58,6 +57,6 @@ public void remoteAccessFailed( .address(address) ) .build(); - logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); + logEvent.accept(tcpTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 497753e6a9..c8d5b2b2ed 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -117,7 +117,7 @@ public TcpClientFactory( this.initialMax = bufferPool.slotCapacity(); this.windowThreshold = (bufferPool.slotCapacity() * config.windowThreshold()) / 100; - this.event = new TcpEventContext(context.supplyTypeId("tcp"), context); + this.event = new TcpEventContext(context); } @Override diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 574720ccbc..791cd3c5ea 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -37,15 +37,14 @@ public class TlsEventContext private final TlsEventFW.Builder tlsEventRW = new TlsEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); - private final int typeId; + private final int tlsTypeId; private final MessageConsumer logEvent; private final LongSupplier timestamp; public TlsEventContext( - int typeId, EngineContext context) { - this.typeId = typeId; + this.tlsTypeId = context.supplyTypeId(TlsBinding.NAME); this.logEvent = context.logEvent(); this.timestamp = context.timestamp(); } @@ -63,7 +62,7 @@ public void tlsFailed( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(typeId, event.buffer(), event.offset(), event.limit()); + logEvent.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); } public void tlsFailed( diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index 1fa9873d64..fdd1e46a44 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -171,7 +171,7 @@ public TlsClientFactory( this.initialPadAdjust = Math.max(context.bufferPool().slotCapacity() >> 14, 1) * MAXIMUM_HEADER_SIZE; this.bindings = new Long2ObjectHashMap<>(); - this.event = new TlsEventContext(context.supplyTypeId("tls"), context); + this.event = new TlsEventContext(context); this.inNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity()); this.inNetBuffer = new UnsafeBuffer(inNetByteBuffer); this.outNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity() << 1); diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index 9f8e484344..e262880031 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -186,7 +186,7 @@ public TlsServerFactory( this.handshakeMax = Math.min(config.handshakeWindowBytes(), decodeMax); this.handshakeTimeoutMillis = SECONDS.toMillis(config.handshakeTimeout()); this.bindings = new Long2ObjectHashMap<>(); - this.event = new TlsEventContext(context.supplyTypeId("tls"), context); + this.event = new TlsEventContext(context); this.inNetByteBuffer = ByteBuffer.allocate(writeBuffer.capacity()); this.inNetBuffer = new UnsafeBuffer(inNetByteBuffer); From ada8412d0e6103e9586c7e8e4750e21857635483 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 10:59:13 +0100 Subject: [PATCH 050/167] fix logger --- .../schema/registry/internal/SchemaRegistryEventContext.java | 2 +- .../zilla/runtime/binding/http/internal/HttpEventContext.java | 2 +- .../zilla/runtime/binding/kafka/internal/KafkaEventContext.java | 2 +- .../zilla/runtime/binding/mqtt/internal/MqttEventContext.java | 2 +- .../zilla/runtime/binding/tcp/internal/TcpEventContext.java | 2 +- .../zilla/runtime/binding/tls/internal/TlsEventContext.java | 2 +- .../java/io/aklivity/zilla/runtime/engine/EngineContext.java | 2 +- .../zilla/runtime/engine/internal/registry/EngineWorker.java | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 745cbd1088..27d98ca85b 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -38,7 +38,7 @@ public SchemaRegistryEventContext( EngineContext context) { this.schemaRegistryTypeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); - this.logEvent = context.logEvent(); + this.logEvent = context.logger(); this.timestamp = context.timestamp(); } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 61b8aedd6f..81e4c2ef77 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -40,7 +40,7 @@ public HttpEventContext( EngineContext context) { this.httpTypeId = context.supplyTypeId(HttpBinding.NAME); - this.logEvent = context.logEvent(); + this.logEvent = context.logger(); this.timestamp = context.timestamp(); } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 718e74db7d..777575ddd9 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -40,7 +40,7 @@ public KafkaEventContext( EngineContext context) { this.kafkaTypeId = context.supplyTypeId(KafkaBinding.NAME); - this.logEvent = context.logEvent(); + this.logEvent = context.logger(); this.timestamp = context.timestamp(); } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 86623b13be..d20a1b50a7 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -40,7 +40,7 @@ public MqttEventContext( EngineContext context) { this.mqttTypeId = context.supplyTypeId(MqttBinding.NAME); - this.logEvent = context.logEvent(); + this.logEvent = context.logger(); this.timestamp = context.timestamp(); } diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 573e224164..8fb3260b44 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -39,7 +39,7 @@ public TcpEventContext( EngineContext context) { this.tcpTypeId = context.supplyTypeId(TcpBinding.NAME); - this.logEvent = context.logEvent(); + this.logEvent = context.logger(); this.timestamp = context.timestamp(); } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 791cd3c5ea..1c0fbfeb41 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -45,7 +45,7 @@ public TlsEventContext( EngineContext context) { this.tlsTypeId = context.supplyTypeId(TlsBinding.NAME); - this.logEvent = context.logEvent(); + this.logEvent = context.logger(); this.timestamp = context.timestamp(); } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index ccad66987f..96f64bd4e0 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -149,7 +149,7 @@ void onExporterAttached( void onExporterDetached( long exporterId); - MessageConsumer logEvent(); + MessageConsumer logger(); LongSupplier timestamp(); } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 8ec283672e..c03be3e5ad 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -904,7 +904,7 @@ public LongConsumer supplyHistogramWriter( } @Override - public MessageConsumer logEvent() + public MessageConsumer logger() { return this.eventsLayout.supplyWriter(); } From c0f74bb0cd29d918cf08a89220fc95648853c8ff Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 11:14:44 +0100 Subject: [PATCH 051/167] fix authorization --- .../runtime/binding/http/internal/HttpEventContext.java | 3 ++- .../binding/http/internal/stream/HttpServerFactory.java | 9 ++------- .../binding/kafka/internal/KafkaEventContext.java | 4 +++- .../kafka/internal/stream/KafkaClientSaslHandshaker.java | 7 ++----- .../runtime/binding/mqtt/internal/MqttEventContext.java | 3 ++- .../binding/mqtt/internal/stream/MqttServerFactory.java | 5 +---- 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 81e4c2ef77..a1ee4f04bf 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -61,11 +61,12 @@ public void accessDenied( } public void authorization( - Result result, + long sessionId, long traceId, long routedId, String identity) { + Result result = sessionId == 0 ? Result.FAILURE : Result.SUCCESS; HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 910fd7cd51..9a219e9a52 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -116,7 +116,6 @@ import io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW; import io.aklivity.zilla.runtime.binding.http.internal.types.String16FW; import io.aklivity.zilla.runtime.binding.http.internal.types.String8FW; -import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.http.internal.types.stream.Capability; @@ -1061,9 +1060,7 @@ else if (!isCorsRequestAllowed(server.binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); - event.authorization( - exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, - traceId, server.routedId, guard.identity(authorization)); + event.authorization(exchangeAuth, traceId, server.routedId, guard.identity(authorization)); } } @@ -4978,9 +4975,7 @@ else if (!isCorsRequestAllowed(binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(initialId, credentialsMatch); - event.authorization( - exchangeAuth == 0 ? Result.FAILURE : Result.SUCCESS, - traceId, routedId, guard.identity(authorization)); + event.authorization(exchangeAuth, traceId, routedId, guard.identity(authorization)); } } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 777575ddd9..32513a535f 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -29,6 +29,7 @@ public class KafkaEventContext { private static final int EVENT_BUFFER_CAPACITY = 1024; + private static final int ERROR_NONE = 0; private final KafkaEventFW.Builder kafkaEventRW = new KafkaEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); @@ -45,10 +46,11 @@ public KafkaEventContext( } public void authorization( - Result result, + int errorCode, long traceId, long routedId) { + Result result = errorCode == ERROR_NONE ? Result.SUCCESS : Result.FAILURE; KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index d1255dc1f4..8b9c498898 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -695,9 +695,7 @@ private int decodeSaslPlainAuthenticate( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); - event.authorization( - errorCode == ERROR_NONE ? Result.SUCCESS : Result.FAILURE, - traceId, client.routedId); + event.authorization(errorCode, traceId, client.routedId); progress = authenticateResponse.limit(); @@ -732,6 +730,7 @@ private int decodeSaslScramAuthenticateFirst( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); + event.authorization(errorCode, traceId, client.routedId); progress = authenticateResponse.limit(); @@ -756,13 +755,11 @@ private int decodeSaslScramAuthenticateFirst( client.decodeSaslAuthenticate = decodeSaslScramAuthenticateFinal; client.onDecodeSaslResponse(traceId); client.onDecodeSaslHandshakeResponse(traceId, authorization, ERROR_NONE); - event.authorization(Result.SUCCESS, traceId, client.routedId); } else { client.onDecodeSaslResponse(traceId); client.onDecodeSaslAuthenticateResponse(traceId, authorization, ERROR_SASL_AUTHENTICATION_FAILED); - event.authorization(Result.FAILURE, traceId, client.routedId); } } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index d20a1b50a7..7ee11f083e 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -45,11 +45,12 @@ public MqttEventContext( } public void authorization( - Result result, + long sessionId, long traceId, long routedId, String identity) { + Result result = sessionId == 0 ? Result.FAILURE : Result.SUCCESS; MqttEventFW event = mqttEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index 5c6be35413..d9f8833480 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -167,7 +167,6 @@ import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttUserPropertyFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttWillV4FW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.codec.MqttWillV5FW; -import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.stream.DataFW; @@ -2918,9 +2917,7 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) if (credentialsMatch != null) { sessionAuth = guard.reauthorize(initialId, credentialsMatch); - event.authorization( - sessionAuth == 0 ? Result.FAILURE : Result.SUCCESS, - traceId, routedId, guard.identity(sessionId)); + event.authorization(sessionAuth, traceId, routedId, guard.identity(sessionId)); } } From 62ed116d0fe22bc6839e3f3b558b87c55d62bdbb Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 11:35:38 +0100 Subject: [PATCH 052/167] fix namespacedId --- .../main/resources/META-INF/zilla/schema_registry.idl | 2 +- .../registry/internal/SchemaRegistryEventContext.java | 2 +- .../stdout/internal/stream/StdoutEventsStream.java | 2 +- .../binding/http/internal/HttpEventContext.java | 4 ++-- .../binding/kafka/internal/KafkaEventContext.java | 2 +- .../internal/stream/KafkaClientSaslHandshaker.java | 2 -- .../binding/mqtt/internal/MqttEventContext.java | 2 +- .../runtime/binding/tcp/internal/TcpEventContext.java | 2 +- .../src/main/resources/META-INF/zilla/http.idl | 4 ++-- .../src/main/resources/META-INF/zilla/kafka.idl | 4 ++-- .../src/main/resources/META-INF/zilla/mqtt.idl | 2 +- .../src/main/resources/META-INF/zilla/tcp.idl | 2 +- .../src/main/resources/META-INF/zilla/tls.idl | 2 +- .../src/main/resources/META-INF/zilla/core.idl | 11 +---------- 14 files changed, 16 insertions(+), 27 deletions(-) diff --git a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl index 59da33fb3f..a9125e3964 100644 --- a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl +++ b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl @@ -21,7 +21,7 @@ scope schema_registry REMOTE_ACCESS_REJECTED (1) } - struct SchemaRegistryRemoteAccessRejectedEvent extends core::event::CatalogEvent + struct SchemaRegistryRemoteAccessRejectedEvent extends core::event::Event { string16 url; string8 method; diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 27d98ca85b..ffbd2225a9 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -52,7 +52,7 @@ public void remoteAccessRejected( .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessRejected(e -> e .timestamp(timestamp.getAsLong()) - .catalogId(catalogId) + .namespacedId(catalogId) .url(url) .method(method) .status((short) status) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index be027a04df..e1510e0c11 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -110,7 +110,7 @@ private void handleTcpEvent( { case REMOTE_ACCESS_FAILED: TcpRemoteAccessFailedEventFW e = event.remoteAccessFailed(); - out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), asBinding(e.bindingId()), + out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), asBinding(e.namespacedId()), asString(e.address())); break; } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index a1ee4f04bf..8d66944c49 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -53,7 +53,7 @@ public void accessDenied( .accessDenied(e -> e .timestamp(timestamp.getAsLong()) .traceId(traceId) - .bindingId(routedId) + .namespacedId(routedId) ) .build(); System.out.println(event); // TODO: Ati @@ -72,7 +72,7 @@ public void authorization( .authorization(e -> e .timestamp(timestamp.getAsLong()) .traceId(traceId) - .bindingId(routedId) + .namespacedId(routedId) .result(r -> r.set(result)) .identity(identity) ) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 32513a535f..b53be2773e 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -56,7 +56,7 @@ public void authorization( .authorization(e -> e .timestamp(timestamp.getAsLong()) .traceId(traceId) - .bindingId(routedId) + .namespacedId(routedId) .result(r -> r.set(result)) ) .build(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index 8b9c498898..c8d8e0bca3 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -42,7 +42,6 @@ import io.aklivity.zilla.runtime.binding.kafka.config.KafkaSaslConfig; import io.aklivity.zilla.runtime.binding.kafka.config.KafkaServerConfig; import io.aklivity.zilla.runtime.binding.kafka.identity.KafkaClientIdSupplier; -import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaBinding; import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaConfiguration; import io.aklivity.zilla.runtime.binding.kafka.internal.KafkaEventContext; import io.aklivity.zilla.runtime.binding.kafka.internal.config.KafkaScramMechanism; @@ -54,7 +53,6 @@ import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeMechanismResponseFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeRequestFW; import io.aklivity.zilla.runtime.binding.kafka.internal.types.codec.sasl.SaslHandshakeResponseFW; -import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Result; import io.aklivity.zilla.runtime.binding.kafka.internal.types.stream.DataFW; import io.aklivity.zilla.runtime.engine.EngineContext; diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 7ee11f083e..06f76da090 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -56,7 +56,7 @@ public void authorization( .authorization(e -> e .timestamp(timestamp.getAsLong()) .traceId(traceId) - .bindingId(routedId) + .namespacedId(routedId) .result(r -> r.set(result)) .identity(identity) ) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 8fb3260b44..65a7ef56a8 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -53,7 +53,7 @@ public void remoteAccessFailed( .remoteAccessFailed(e -> e .timestamp(timestamp.getAsLong()) .traceId(traceId) - .bindingId(routedId) + .namespacedId(routedId) .address(address) ) .build(); diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 50e193674a..5bd3f39086 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -64,7 +64,7 @@ scope http FAILURE (1) } - struct HttpAuthorizationEvent extends core::event::BindingEvent + struct HttpAuthorizationEvent extends core::event::Event { Result result; string8 identity; @@ -73,7 +73,7 @@ scope http union HttpEvent switch (HttpEventType) { case AUTHORIZATION: HttpAuthorizationEvent authorization; - case ACCESS_DENIED: core::event::BindingEvent accessDenied; + case ACCESS_DENIED: core::event::Event accessDenied; } } } diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index cb636d1e02..04cea5aa52 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -534,7 +534,7 @@ scope kafka FAILURE (1) } - struct KafkaAuthorizationEvent extends core::event::BindingEvent + struct KafkaAuthorizationEvent extends core::event::Event { Result result; } @@ -542,7 +542,7 @@ scope kafka union KafkaEvent switch (KafkaEventType) { case AUTHORIZATION: KafkaAuthorizationEvent authorization; - case API_VERSION_REJECTED: core::event::BindingEvent apiVersionRejected; + case API_VERSION_REJECTED: core::event::Event apiVersionRejected; } } } diff --git a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl index 97a92405ed..e031c17636 100644 --- a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl +++ b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl @@ -272,7 +272,7 @@ scope mqtt FAILURE (1) } - struct MqttAuthorizationEvent extends core::event::BindingEvent + struct MqttAuthorizationEvent extends core::event::Event { Result result; string8 identity; diff --git a/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl b/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl index 4dbd4917e4..e0eaa1efc4 100644 --- a/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl +++ b/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl @@ -22,7 +22,7 @@ scope tcp REMOTE_ACCESS_FAILED (1) } - struct TcpRemoteAccessFailedEvent extends core::event::BindingEvent + struct TcpRemoteAccessFailedEvent extends core::event::Event { string16 address; } diff --git a/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl b/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl index b91656f357..aa6a1d8926 100644 --- a/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl +++ b/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl @@ -31,7 +31,7 @@ scope tls UNSPECIFIED_ERROR (5) } - struct TlsFailedEvent extends core::event::BindingEvent + struct TlsFailedEvent extends core::event::Event { TlsError error; } diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index c9c53150e2..44699df113 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -107,16 +107,7 @@ scope core { int64 timestamp = 0; int64 traceId = 0; - } - - struct BindingEvent extends Event - { - int64 bindingId = 0; - } - - struct CatalogEvent extends Event - { - int64 catalogId = 0; + int64 namespacedId = 0; } } } From cd263c6280d4773e87a3d102a7c3aa4d5bf0e496 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 12:29:23 +0100 Subject: [PATCH 053/167] fix supply* --- .../stdout/internal/StdoutExporterHandler.java | 2 +- .../stdout/internal/labels/LabelReader.java | 11 ----------- .../stdout/internal/stream/StdoutEventsStream.java | 13 +++++++++---- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 8bfd4d1054..be1dc4c71d 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -113,6 +113,6 @@ private StdoutEventsStream newStdoutEventsStream( .readonly(true) .spyAt(SpyPosition.ZERO) .build(); - return new StdoutEventsStream(labels, layout, out); + return new StdoutEventsStream(labels, layout, context::supplyNamespace, context::supplyLocalName, out); } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java index 6eca187312..af8cfbb783 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java @@ -57,17 +57,6 @@ public synchronized int lookupLabelId( return labelIds.getOrDefault(label, 0); } - public synchronized String lookupLabel( - int labelId) - { - if (labelId < 1 || labelId > labels.size()) - { - checkSnapshot(); - } - - return labels.get(labelId - 1); - } - private void checkSnapshot() { try diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index e1510e0c11..254d774512 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -15,6 +15,7 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; +import java.util.function.LongFunction; import org.agrona.DirectBuffer; import org.agrona.collections.Int2ObjectHashMap; @@ -46,18 +47,22 @@ public class StdoutEventsStream private final TcpRemoteAccessFailedEventFW tcpRemoteAccessFailedEventRO = new TcpRemoteAccessFailedEventFW(); private final TlsEventFW tlsEventRO = new TlsEventFW(); - private final LabelReader labels; private final EventsLayoutReader layout; private final PrintStream out; private final Int2ObjectHashMap eventHandlers; + private final LongFunction supplyNamespace; + private final LongFunction supplyLocalName; public StdoutEventsStream( LabelReader labels, EventsLayoutReader layout, + LongFunction supplyNamespace, + LongFunction supplyLocalName, PrintStream out) { - this.labels = labels; this.layout = layout; + this.supplyNamespace = supplyNamespace; + this.supplyLocalName = supplyLocalName; this.out = out; final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); @@ -128,8 +133,8 @@ private void handleHttpEvent( private String asBinding( long bindingId) { - String namespace = labels.lookupLabel(namespaceId(bindingId)); - String binding = labels.lookupLabel(localId(bindingId)); + String namespace = supplyNamespace.apply(bindingId); + String binding = supplyLocalName.apply(bindingId); return String.format("%s.%s", namespace, binding); } From f8c01746c4ac30efab498cb7082f7fa17e60f3b9 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 12:31:18 +0100 Subject: [PATCH 054/167] fix logger --- .../registry/internal/SchemaRegistryEventContext.java | 6 +++--- .../runtime/binding/http/internal/HttpEventContext.java | 8 ++++---- .../runtime/binding/kafka/internal/KafkaEventContext.java | 8 ++++---- .../runtime/binding/mqtt/internal/MqttEventContext.java | 6 +++--- .../runtime/binding/tcp/internal/TcpEventContext.java | 6 +++--- .../runtime/binding/tls/internal/TlsEventContext.java | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index ffbd2225a9..96ad0fd185 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -31,14 +31,14 @@ public class SchemaRegistryEventContext private final SchemaRegistryEventFW.Builder schemaRegistryEventRW = new SchemaRegistryEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int schemaRegistryTypeId; - private final MessageConsumer logEvent; + private final MessageConsumer logger; private final LongSupplier timestamp; public SchemaRegistryEventContext( EngineContext context) { this.schemaRegistryTypeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); - this.logEvent = context.logger(); + this.logger = context.logger(); this.timestamp = context.timestamp(); } @@ -59,6 +59,6 @@ public void remoteAccessRejected( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(schemaRegistryTypeId, event.buffer(), event.offset(), event.limit()); + logger.accept(schemaRegistryTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 8d66944c49..31852591ce 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -33,14 +33,14 @@ public class HttpEventContext private final HttpEventFW.Builder httpEventRW = new HttpEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int httpTypeId; - private final MessageConsumer logEvent; + private final MessageConsumer logger; private final LongSupplier timestamp; public HttpEventContext( EngineContext context) { this.httpTypeId = context.supplyTypeId(HttpBinding.NAME); - this.logEvent = context.logger(); + this.logger = context.logger(); this.timestamp = context.timestamp(); } @@ -57,7 +57,7 @@ public void accessDenied( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } public void authorization( @@ -78,6 +78,6 @@ public void authorization( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index b53be2773e..47fc7d60fd 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -34,14 +34,14 @@ public class KafkaEventContext private final KafkaEventFW.Builder kafkaEventRW = new KafkaEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int kafkaTypeId; - private final MessageConsumer logEvent; + private final MessageConsumer logger; private final LongSupplier timestamp; public KafkaEventContext( EngineContext context) { this.kafkaTypeId = context.supplyTypeId(KafkaBinding.NAME); - this.logEvent = context.logger(); + this.logger = context.logger(); this.timestamp = context.timestamp(); } @@ -61,7 +61,7 @@ public void authorization( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); + logger.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } public void apiVersionRejected( @@ -75,6 +75,6 @@ public void apiVersionRejected( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); + logger.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 06f76da090..12382396bf 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -33,14 +33,14 @@ public class MqttEventContext private final MqttEventFW.Builder mqttEventRW = new MqttEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int mqttTypeId; - private final MessageConsumer logEvent; + private final MessageConsumer logger; private final LongSupplier timestamp; public MqttEventContext( EngineContext context) { this.mqttTypeId = context.supplyTypeId(MqttBinding.NAME); - this.logEvent = context.logger(); + this.logger = context.logger(); this.timestamp = context.timestamp(); } @@ -62,6 +62,6 @@ public void authorization( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); + logger.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 65a7ef56a8..792e0cb498 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -32,14 +32,14 @@ public class TcpEventContext private final TcpEventFW.Builder tcpEventRW = new TcpEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int tcpTypeId; - private final MessageConsumer logEvent; + private final MessageConsumer logger; private final LongSupplier timestamp; public TcpEventContext( EngineContext context) { this.tcpTypeId = context.supplyTypeId(TcpBinding.NAME); - this.logEvent = context.logger(); + this.logger = context.logger(); this.timestamp = context.timestamp(); } @@ -57,6 +57,6 @@ public void remoteAccessFailed( .address(address) ) .build(); - logEvent.accept(tcpTypeId, event.buffer(), event.offset(), event.limit()); + logger.accept(tcpTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 1c0fbfeb41..ae8080dd35 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -38,14 +38,14 @@ public class TlsEventContext private final TlsEventFW.Builder tlsEventRW = new TlsEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int tlsTypeId; - private final MessageConsumer logEvent; + private final MessageConsumer logger; private final LongSupplier timestamp; public TlsEventContext( EngineContext context) { this.tlsTypeId = context.supplyTypeId(TlsBinding.NAME); - this.logEvent = context.logger(); + this.logger = context.logger(); this.timestamp = context.timestamp(); } @@ -62,7 +62,7 @@ public void tlsFailed( ) .build(); System.out.println(event); // TODO: Ati - logEvent.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); + logger.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); } public void tlsFailed( From e33e09b83d068f9002498a6e4dfe9d2ce66d9611 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 12:36:44 +0100 Subject: [PATCH 055/167] fix --- .../internal/stream/StdoutEventsStream.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 254d774512..1c60be457b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -24,7 +24,6 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayoutReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; @@ -36,9 +35,8 @@ public class StdoutEventsStream { private static final String TCP_REMOTE_ACCESS_FAILED_FORMAT = - "ERROR: Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s] [address = %s]%n"; + "ERROR: Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; - private final EventFW eventRO = new EventFW(); private final HttpEventFW httpEventRO = new HttpEventFW(); private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); private final MqttEventFW mqttEventRO = new MqttEventFW(); @@ -115,8 +113,9 @@ private void handleTcpEvent( { case REMOTE_ACCESS_FAILED: TcpRemoteAccessFailedEventFW e = event.remoteAccessFailed(); - out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), asBinding(e.namespacedId()), - asString(e.address())); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.address())); break; } } @@ -130,14 +129,6 @@ private void handleHttpEvent( // TODO: Ati } - private String asBinding( - long bindingId) - { - String namespace = supplyNamespace.apply(bindingId); - String binding = supplyLocalName.apply(bindingId); - return String.format("%s.%s", namespace, binding); - } - private static String asString( StringFW stringFW) { From 7a8e33e9ff0c122f8779fcf788f2b9c25ab66c81 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 12:40:22 +0100 Subject: [PATCH 056/167] fix --- .../internal/stream/StdoutEventsStream.java | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 1c60be457b..568393da7d 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -42,14 +42,13 @@ public class StdoutEventsStream private final MqttEventFW mqttEventRO = new MqttEventFW(); private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); private final TcpEventFW tcpEventRO = new TcpEventFW(); - private final TcpRemoteAccessFailedEventFW tcpRemoteAccessFailedEventRO = new TcpRemoteAccessFailedEventFW(); private final TlsEventFW tlsEventRO = new TlsEventFW(); private final EventsLayoutReader layout; - private final PrintStream out; - private final Int2ObjectHashMap eventHandlers; private final LongFunction supplyNamespace; private final LongFunction supplyLocalName; + private final PrintStream out; + private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( LabelReader labels, @@ -135,16 +134,4 @@ private static String asString( String s = stringFW.asString(); return s == null ? "" : s; } - - public static int namespaceId( - long bindingId) - { - return (int)(bindingId >> Integer.SIZE) & 0xffff_ffff; - } - - private static int localId( - long bindingId) - { - return (int)(bindingId >> 0) & 0xffff_ffff; - } } From c712d7b1656ac316bdf820380578c42518053b7c Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 15:40:54 +0100 Subject: [PATCH 057/167] fix lookupLabelId --- .../internal/StdoutExporterHandler.java | 5 +- .../stdout/internal/labels/LabelReader.java | 95 ------------------- .../internal/stream/StdoutEventsStream.java | 56 +++++++++-- .../zilla/runtime/engine/EngineContext.java | 3 + .../runtime/engine/internal/LabelManager.java | 7 ++ .../internal/registry/EngineWorker.java | 7 ++ 6 files changed, 66 insertions(+), 107 deletions(-) delete mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index be1dc4c71d..61a5bf6f61 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -28,7 +28,6 @@ import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; -import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayoutReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.exporter.stdout.internal.stream.StdoutEventsStream; @@ -39,7 +38,6 @@ public class StdoutExporterHandler implements ExporterHandler private final EngineContext context; private final Path directory; - private final LabelReader labels; private final PrintStream out; private StdoutEventsStream[] stdoutEventStreams; @@ -52,7 +50,6 @@ public StdoutExporterHandler( { this.context = context; this.directory = config.directory(); - this.labels = new LabelReader(directory); this.out = out; } @@ -113,6 +110,6 @@ private StdoutEventsStream newStdoutEventsStream( .readonly(true) .spyAt(SpyPosition.ZERO) .build(); - return new StdoutEventsStream(labels, layout, context::supplyNamespace, context::supplyLocalName, out); + return new StdoutEventsStream(layout, context::supplyNamespace, context::supplyLocalName, context::lookupLabelId, out); } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java deleted file mode 100644 index af8cfbb783..0000000000 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/labels/LabelReader.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc - * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at - * - * https://www.aklivity.io/aklivity-community-license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package io.aklivity.zilla.runtime.exporter.stdout.internal.labels; - -import static java.nio.channels.Channels.newReader; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.nio.file.StandardOpenOption.CREATE; -import static java.nio.file.StandardOpenOption.READ; -import static java.nio.file.StandardOpenOption.WRITE; - -import java.io.BufferedReader; -import java.io.IOException; -import java.nio.channels.FileChannel; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.agrona.LangUtil; - -public final class LabelReader -{ - private final List labels; - private final Map labelIds; - private final Path labelsPath; - - private long sizeInBytes; - - public LabelReader( - Path directory) - { - this.labels = new ArrayList<>(); - this.labelIds = new HashMap<>(); - - this.labelsPath = directory.resolve("labels"); - this.sizeInBytes = -1L; - } - - public synchronized int lookupLabelId( - String label) - { - checkSnapshot(); - return labelIds.getOrDefault(label, 0); - } - - private void checkSnapshot() - { - try - { - if (!Files.exists(labelsPath)) - { - this.sizeInBytes = -1L; - } - - if (this.sizeInBytes == -1L || this.sizeInBytes < Files.size(labelsPath)) - { - Files.createDirectories(labelsPath.getParent()); - try (FileChannel channel = FileChannel.open(labelsPath, CREATE, READ, WRITE)) - { - labels.clear(); - labelIds.clear(); - - try (BufferedReader in = new BufferedReader(newReader(channel, UTF_8.name()))) - { - for (String label = in.readLine(); label != null; label = in.readLine()) - { - labels.add(label); - labelIds.put(label, labels.size()); - } - - this.sizeInBytes = channel.position(); - } - } - } - } - catch (final IOException ex) - { - LangUtil.rethrowUnchecked(ex); - } - } -} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 568393da7d..406074d405 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -15,13 +15,13 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; +import java.util.function.Function; import java.util.function.LongFunction; import org.agrona.DirectBuffer; import org.agrona.collections.Int2ObjectHashMap; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.labels.LabelReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayoutReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; @@ -47,35 +47,39 @@ public class StdoutEventsStream private final EventsLayoutReader layout; private final LongFunction supplyNamespace; private final LongFunction supplyLocalName; + private final Function lookupLabelId; private final PrintStream out; private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( - LabelReader labels, EventsLayoutReader layout, LongFunction supplyNamespace, LongFunction supplyLocalName, + Function lookupLabelId, PrintStream out) { this.layout = layout; this.supplyNamespace = supplyNamespace; this.supplyLocalName = supplyLocalName; + this.lookupLabelId = lookupLabelId; this.out = out; final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); - addEventHandler(labels, eventHandlers, "tcp", this::handleTcpEvent); - addEventHandler(labels, eventHandlers, "http", this::handleHttpEvent); - // TODO: Ati - add more + addEventHandler(eventHandlers, "http", this::handleHttpEvent); + addEventHandler(eventHandlers, "kafka", this::handleKafkaEvent); + addEventHandler(eventHandlers, "mqtt", this::handleMqttEvent); + addEventHandler(eventHandlers, "schema-registry", this::handleSchemaRegistryEvent); + addEventHandler(eventHandlers, "tcp", this::handleTcpEvent); + addEventHandler(eventHandlers, "tls", this::handleTlsEvent); this.eventHandlers = eventHandlers; } private void addEventHandler( - LabelReader labels, Int2ObjectHashMap eventHandlers, String type, MessageConsumer consumer) { - int labelId = labels.lookupLabelId(type); + int labelId = lookupLabelId.apply(type); if (labelId != 0) { eventHandlers.put(labelId, consumer); @@ -101,6 +105,42 @@ private boolean handleEvent( return true; } + private void handleHttpEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + // TODO: Ati + } + + private void handleKafkaEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + // TODO: Ati + } + + private void handleMqttEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + // TODO: Ati + } + + private void handleSchemaRegistryEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + // TODO: Ati + } + private void handleTcpEvent( int msgTypeId, DirectBuffer buffer, @@ -119,7 +159,7 @@ private void handleTcpEvent( } } - private void handleHttpEvent( + private void handleTlsEvent( int msgTypeId, DirectBuffer buffer, int index, diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 96f64bd4e0..1d6fb46dd3 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -48,6 +48,9 @@ public interface EngineContext int supplyTypeId( String name); + int lookupLabelId( + String name); + long supplyInitialId( long bindingId); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/LabelManager.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/LabelManager.java index c29ecb95ee..2855d6485b 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/LabelManager.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/LabelManager.java @@ -61,6 +61,13 @@ public synchronized int supplyLabelId( return labelIds.computeIfAbsent(label, this::nextLabelId); } + public synchronized int lookupLabelId( + String label) + { + checkSnapshot(); + return labelIds.getOrDefault(label, 0); + } + public synchronized String lookupLabel( int labelId) { diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index c03be3e5ad..d294230a63 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -456,6 +456,13 @@ public int supplyTypeId( return labels.supplyLabelId(name); } + @Override + public int lookupLabelId( + String name) + { + return labels.lookupLabelId(name); + } + @Override public long supplyInitialId( long bindingId) From 2c0ea9f1b68957417e5b7971a89ae3d9ed6fb8c8 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 15:43:40 +0100 Subject: [PATCH 058/167] fix --- .../stdout/internal/stream/StdoutEventsStream.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 406074d405..cb938f2fe2 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -15,8 +15,8 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; -import java.util.function.Function; import java.util.function.LongFunction; +import java.util.function.ToIntFunction; import org.agrona.DirectBuffer; import org.agrona.collections.Int2ObjectHashMap; @@ -47,7 +47,7 @@ public class StdoutEventsStream private final EventsLayoutReader layout; private final LongFunction supplyNamespace; private final LongFunction supplyLocalName; - private final Function lookupLabelId; + private final ToIntFunction lookupLabelId; private final PrintStream out; private final Int2ObjectHashMap eventHandlers; @@ -55,7 +55,7 @@ public StdoutEventsStream( EventsLayoutReader layout, LongFunction supplyNamespace, LongFunction supplyLocalName, - Function lookupLabelId, + ToIntFunction lookupLabelId, PrintStream out) { this.layout = layout; @@ -79,7 +79,7 @@ private void addEventHandler( String type, MessageConsumer consumer) { - int labelId = lookupLabelId.apply(type); + int labelId = lookupLabelId.applyAsInt(type); if (labelId != 0) { eventHandlers.put(labelId, consumer); From be4fa0655c4a37706f2b641fe2fc86255e40ebb0 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 15:52:32 +0100 Subject: [PATCH 059/167] WIP ref --- .../internal/StdoutExporterHandler.java | 4 ++-- .../internal/stream/StdoutEventsStream.java | 2 +- .../engine/reader}/EventsLayoutReader.java | 21 +++++++++---------- .../engine/reader}/OneToOneRingBufferSpy.java | 17 ++++++++------- .../runtime/engine/reader}/RingBufferSpy.java | 17 ++++++++------- 5 files changed, 31 insertions(+), 30 deletions(-) rename {incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts => runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader}/EventsLayoutReader.java (82%) rename {incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy => runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader}/OneToOneRingBufferSpy.java (89%) rename {incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy => runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader}/RingBufferSpy.java (54%) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 61a5bf6f61..8fb2803ed7 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -27,9 +27,9 @@ import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; +import io.aklivity.zilla.runtime.engine.reader.EventsLayoutReader; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; -import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayoutReader; -import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.exporter.stdout.internal.stream.StdoutEventsStream; public class StdoutExporterHandler implements ExporterHandler diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index cb938f2fe2..4e0a568c9d 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -22,7 +22,7 @@ import org.agrona.collections.Int2ObjectHashMap; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.layouts.EventsLayoutReader; +import io.aklivity.zilla.runtime.engine.reader.EventsLayoutReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayoutReader.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/EventsLayoutReader.java similarity index 82% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayoutReader.java rename to runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/EventsLayoutReader.java index 4c075b27fa..73a113acc0 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/layouts/EventsLayoutReader.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/EventsLayoutReader.java @@ -1,18 +1,19 @@ /* - * Copyright 2021-2023 Aklivity Inc + * Copyright 2021-2023 Aklivity Inc. * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at + * Aklivity licenses this file to you 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: * - * https://www.aklivity.io/aklivity-community-license/ + * 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 OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * 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.aklivity.zilla.runtime.exporter.stdout.internal.layouts; +package io.aklivity.zilla.runtime.engine.reader; import static org.agrona.IoUtil.mapExistingFile; import static org.agrona.IoUtil.unmap; @@ -30,9 +31,7 @@ import org.agrona.concurrent.AtomicBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.OneToOneRingBufferSpy; -import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy; -import io.aklivity.zilla.runtime.exporter.stdout.internal.spy.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; public final class EventsLayoutReader implements AutoCloseable { diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/OneToOneRingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/OneToOneRingBufferSpy.java similarity index 89% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/OneToOneRingBufferSpy.java rename to runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/OneToOneRingBufferSpy.java index c2db6c7280..988b264941 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/OneToOneRingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/OneToOneRingBufferSpy.java @@ -1,18 +1,19 @@ /* - * Copyright 2021-2023 Aklivity Inc + * Copyright 2021-2023 Aklivity Inc. * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at + * Aklivity licenses this file to you 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: * - * https://www.aklivity.io/aklivity-community-license/ + * 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 OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * 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.aklivity.zilla.runtime.exporter.stdout.internal.spy; +package io.aklivity.zilla.runtime.engine.reader; import static org.agrona.BitUtil.align; import static org.agrona.concurrent.ringbuffer.RecordDescriptor.ALIGNMENT; diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/RingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/RingBufferSpy.java similarity index 54% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/RingBufferSpy.java rename to runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/RingBufferSpy.java index 56ed048be8..1f98f98418 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/spy/RingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/RingBufferSpy.java @@ -1,18 +1,19 @@ /* - * Copyright 2021-2023 Aklivity Inc + * Copyright 2021-2023 Aklivity Inc. * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at + * Aklivity licenses this file to you 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: * - * https://www.aklivity.io/aklivity-community-license/ + * 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 OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * 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.aklivity.zilla.runtime.exporter.stdout.internal.spy; +package io.aklivity.zilla.runtime.engine.reader; import org.agrona.DirectBuffer; From 786d434ec0c1a6e79eb1fe3cbdab9b6b0e6c5960 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 17:13:49 +0100 Subject: [PATCH 060/167] WIP spies --- .../internal/StdoutExporterHandler.java | 52 +----- .../internal/stream/StdoutEventsStream.java | 10 +- .../aklivity/zilla/runtime/engine/Engine.java | 15 +- .../zilla/runtime/engine/EngineContext.java | 5 + .../engine/internal/layouts/EventsLayout.java | 37 +++++ .../internal/registry/EngineWorker.java | 18 +++ .../engine/reader/EventsLayoutReader.java | 149 ------------------ 7 files changed, 86 insertions(+), 200 deletions(-) delete mode 100644 runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/EventsLayoutReader.java diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 8fb2803ed7..210b392011 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -14,30 +14,20 @@ */ package io.aklivity.zilla.runtime.exporter.stdout.internal; -import java.io.IOException; import java.io.PrintStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Stream; - -import org.agrona.LangUtil; +import java.util.Arrays; import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; -import io.aklivity.zilla.runtime.engine.reader.EventsLayoutReader; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; import io.aklivity.zilla.runtime.exporter.stdout.internal.stream.StdoutEventsStream; public class StdoutExporterHandler implements ExporterHandler { - private static final Pattern EVENTS_PATTERN = Pattern.compile("events(\\d+)"); - private final EngineContext context; - private final Path directory; private final PrintStream out; private StdoutEventsStream[] stdoutEventStreams; @@ -49,25 +39,15 @@ public StdoutExporterHandler( PrintStream out) { this.context = context; - this.directory = config.directory(); this.out = out; } @Override public void start() { - try (Stream files = Files.walk(directory, 3)) - { - this.stdoutEventStreams = files.filter(this::isEventsFile) - .sorted() - .map(this::newStdoutEventsStream) - .toArray(StdoutEventsStream[]::new); - } - catch (IOException ex) - { - LangUtil.rethrowUnchecked(ex); - } - + this.stdoutEventStreams = Arrays.stream(context.supplyEventSpies(SpyPosition.ZERO)) + .map(this::newStdoutEventsStream) + .toArray(StdoutEventsStream[]::new); } @Override @@ -89,27 +69,9 @@ public void stop() { } - private boolean isEventsFile( - Path path) - { - final int depth = path.getNameCount() - directory.getNameCount(); - if (depth != 1 || !Files.isRegularFile(path)) - { - return false; - } - - final Matcher matcher = EVENTS_PATTERN.matcher(path.getName(path.getNameCount() - 1).toString()); - return matcher.matches(); - } - private StdoutEventsStream newStdoutEventsStream( - Path path) + RingBufferSpy eventSpy) { - EventsLayoutReader layout = new EventsLayoutReader.Builder() - .path(path) - .readonly(true) - .spyAt(SpyPosition.ZERO) - .build(); - return new StdoutEventsStream(layout, context::supplyNamespace, context::supplyLocalName, context::lookupLabelId, out); + return new StdoutEventsStream(eventSpy, context::supplyNamespace, context::supplyLocalName, context::lookupLabelId, out); } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 4e0a568c9d..501204d14f 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -22,7 +22,7 @@ import org.agrona.collections.Int2ObjectHashMap; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.engine.reader.EventsLayoutReader; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; @@ -44,7 +44,7 @@ public class StdoutEventsStream private final TcpEventFW tcpEventRO = new TcpEventFW(); private final TlsEventFW tlsEventRO = new TlsEventFW(); - private final EventsLayoutReader layout; + private final RingBufferSpy eventSpy; private final LongFunction supplyNamespace; private final LongFunction supplyLocalName; private final ToIntFunction lookupLabelId; @@ -52,13 +52,13 @@ public class StdoutEventsStream private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( - EventsLayoutReader layout, + RingBufferSpy eventSpy, LongFunction supplyNamespace, LongFunction supplyLocalName, ToIntFunction lookupLabelId, PrintStream out) { - this.layout = layout; + this.eventSpy = eventSpy; this.supplyNamespace = supplyNamespace; this.supplyLocalName = supplyLocalName; this.lookupLabelId = lookupLabelId; @@ -88,7 +88,7 @@ private void addEventHandler( public int process() { - return layout.eventsBuffer().spy(this::handleEvent, 1); + return eventSpy.spy(this::handleEvent, 1); } private boolean handleEvent( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index 364bed3bc6..063a83bf45 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -75,6 +75,8 @@ import io.aklivity.zilla.runtime.engine.metrics.Collector; import io.aklivity.zilla.runtime.engine.metrics.MetricGroup; import io.aklivity.zilla.runtime.engine.model.Model; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.engine.vault.Vault; public final class Engine implements Collector, AutoCloseable @@ -160,7 +162,7 @@ public final class Engine implements Collector, AutoCloseable EngineWorker worker = new EngineWorker(config, tasks, labels, errorHandler, tuning::affinity, bindings, exporters, guards, vaults, catalogs, models, metricGroups, - this, coreIndex, readonly); + this, this::supplyEventSpies, coreIndex, readonly); workers.add(worker); } this.workers = workers; @@ -481,6 +483,17 @@ public long[][] histogramIds() return worker.histogramIds(); } + public RingBufferSpy[] supplyEventSpies( + SpyPosition position) + { + RingBufferSpy[] spies = new RingBufferSpy[workers.size()]; + for (int i = 0; i < workers.size(); i++) + { + spies[i] = workers.get(i).supplyEventSpy(position); + } + return spies; + } + public String supplyLocalName( long namespacedId) { diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 1d6fb46dd3..b8b08828c1 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -37,6 +37,8 @@ import io.aklivity.zilla.runtime.engine.model.ConverterHandler; import io.aklivity.zilla.runtime.engine.model.ValidatorHandler; import io.aklivity.zilla.runtime.engine.poller.PollerKey; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.engine.vault.VaultHandler; public interface EngineContext @@ -66,6 +68,9 @@ long supplyPromiseId( long supplyTraceId(); + RingBufferSpy[] supplyEventSpies( + SpyPosition position); + MessageConsumer supplySender( long streamId); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index 6fe93fee75..d6a358cbe7 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -38,12 +38,18 @@ import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.engine.reader.OneToOneRingBufferSpy; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; public final class EventsLayout implements AutoCloseable { private final Path path; private final long capacity; + private RingBuffer buffer; + private RingBufferSpy bufferSpy; + private SpyPosition position; private EventsLayout( Path path, @@ -60,6 +66,18 @@ public MessageConsumer supplyWriter() return this::writeEvent; } + public void spyAt( + SpyPosition position) + { + this.position = position; + bufferSpy = createRingBufferSpy(path, position); + } + + public RingBufferSpy bufferSpy() + { + return bufferSpy; + } + @Override public void close() { @@ -95,6 +113,10 @@ private void rotateFile() rethrowUnchecked(ex); } buffer = createRingBuffer(path, capacity, false); + if (position != null) + { + bufferSpy = createRingBufferSpy(path, position); + } } private static RingBuffer createRingBuffer( @@ -112,6 +134,21 @@ private static RingBuffer createRingBuffer( return new OneToOneRingBuffer(atomicBuffer); } + private static RingBufferSpy createRingBufferSpy( + Path path, + SpyPosition position) + { + final File layoutFile = path.toFile(); + final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); + final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); + final OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); + if (position != null) + { + spy.spyAt(position); + } + return spy; + } + public static final class Builder { private long capacity; diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index d294230a63..a7a187dad8 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -135,6 +135,8 @@ import io.aklivity.zilla.runtime.engine.model.ModelContext; import io.aklivity.zilla.runtime.engine.model.ValidatorHandler; import io.aklivity.zilla.runtime.engine.poller.PollerKey; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.engine.util.function.LongLongFunction; import io.aklivity.zilla.runtime.engine.vault.Vault; import io.aklivity.zilla.runtime.engine.vault.VaultContext; @@ -212,6 +214,7 @@ public class EngineWorker implements EngineContext, Agent private final ScalarsLayout gaugesLayout; private final HistogramsLayout histogramsLayout; private final EventsLayout eventsLayout; + private final Function supplyEventSpies; private long initialId; private long promiseId; private long traceId; @@ -234,6 +237,7 @@ public EngineWorker( Collection models, Collection metricGroups, Collector collector, + Function supplyEventSpies, int index, boolean readonly) { @@ -415,6 +419,7 @@ public EngineWorker( this.idleStrategy = idleStrategy; this.errorHandler = errorHandler; this.exportersById = new Long2ObjectHashMap<>(); + this.supplyEventSpies = supplyEventSpies; } public static int indexOfId( @@ -1584,6 +1589,19 @@ public MessageConsumer supplyReceiver( return writersByIndex.computeIfAbsent(remoteIndex, supplyWriter); } + public RingBufferSpy supplyEventSpy( + SpyPosition position) + { + eventsLayout.spyAt(position); + return eventsLayout.bufferSpy(); + } + + public RingBufferSpy[] supplyEventSpies( + SpyPosition position) + { + return supplyEventSpies.apply(position); + } + private MessageConsumer supplyWriter( int index) { diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/EventsLayoutReader.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/EventsLayoutReader.java deleted file mode 100644 index 73a113acc0..0000000000 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/EventsLayoutReader.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc. - * - * Aklivity licenses this file to you 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.aklivity.zilla.runtime.engine.reader; - -import static org.agrona.IoUtil.mapExistingFile; -import static org.agrona.IoUtil.unmap; -import static org.agrona.LangUtil.rethrowUnchecked; - -import java.io.File; -import java.nio.MappedByteBuffer; -import java.nio.file.FileSystems; -import java.nio.file.Path; -import java.nio.file.StandardWatchEventKinds; -import java.nio.file.WatchEvent; -import java.nio.file.WatchKey; -import java.nio.file.WatchService; - -import org.agrona.concurrent.AtomicBuffer; -import org.agrona.concurrent.UnsafeBuffer; - -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; - -public final class EventsLayoutReader implements AutoCloseable -{ - private final Path path; - private final SpyPosition position; - private RingBufferSpy buffer; - - private EventsLayoutReader( - Path path, - SpyPosition position, - RingBufferSpy buffer) - { - this.path = path; - this.position = position; - this.buffer = buffer; - Thread watcher = new Thread(this::watch); - watcher.start(); - } - - public RingBufferSpy eventsBuffer() - { - return buffer; - } - - @Override - public void close() - { - unmap(buffer.buffer().byteBuffer()); - } - - private void watch() - { - try - { - WatchService watchService = FileSystems.getDefault().newWatchService(); - path.getParent().register(watchService, StandardWatchEventKinds.ENTRY_MODIFY); - while (true) - { - WatchKey key = watchService.take(); - for (WatchEvent event : key.pollEvents()) - { - Path changedPath = (Path) event.context(); - if (path.getFileName().equals(changedPath.getFileName())) - { - close(); - buffer = createRingBufferSpy(path, position); - } - } - key.reset(); - } - } - catch (Exception ex) - { - ex.printStackTrace(); - rethrowUnchecked(ex); - } - } - - private static RingBufferSpy createRingBufferSpy( - Path path, - SpyPosition position) - { - final File layoutFile = path.toFile(); - final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); - final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); - final OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); - if (position != null) - { - spy.spyAt(position); - } - return spy; - } - - public static final class Builder - { - private long capacity; - private Path path; - private boolean readonly; - private SpyPosition position; - - public Builder capacity( - long capacity) - { - this.capacity = capacity; - return this; - } - - public Builder path( - Path path) - { - this.path = path; - return this; - } - - public Builder spyAt( - SpyPosition position) - { - this.position = position; - return this; - } - - public Builder readonly( - boolean readonly) - { - this.readonly = readonly; - return this; - } - - public EventsLayoutReader build() - { - RingBufferSpy spy = createRingBufferSpy(path, position); - return new EventsLayoutReader(path, position, spy); - } - } -} From d0f8585b04adfcd47d438c6651fd97fa4ca19170 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 9 Feb 2024 17:34:34 +0100 Subject: [PATCH 061/167] WIP spies --- .../stdout/internal/StdoutExporterHandler.java | 6 ++++-- .../stdout/internal/stream/StdoutEventsStream.java | 9 +++++---- .../java/io/aklivity/zilla/runtime/engine/Engine.java | 6 ++++-- .../aklivity/zilla/runtime/engine/EngineContext.java | 3 ++- .../engine/internal/registry/EngineWorker.java | 11 ++++++----- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 210b392011..3bbe9df2fd 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -16,6 +16,7 @@ import java.io.PrintStream; import java.util.Arrays; +import java.util.function.Supplier; import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; @@ -70,8 +71,9 @@ public void stop() } private StdoutEventsStream newStdoutEventsStream( - RingBufferSpy eventSpy) + Supplier supplyEventSpy) { - return new StdoutEventsStream(eventSpy, context::supplyNamespace, context::supplyLocalName, context::lookupLabelId, out); + return new StdoutEventsStream(supplyEventSpy, context::supplyNamespace, context::supplyLocalName, + context::lookupLabelId, out); } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 501204d14f..0531f20b6d 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -16,6 +16,7 @@ import java.io.PrintStream; import java.util.function.LongFunction; +import java.util.function.Supplier; import java.util.function.ToIntFunction; import org.agrona.DirectBuffer; @@ -44,7 +45,7 @@ public class StdoutEventsStream private final TcpEventFW tcpEventRO = new TcpEventFW(); private final TlsEventFW tlsEventRO = new TlsEventFW(); - private final RingBufferSpy eventSpy; + private final Supplier supplyEventSpy; private final LongFunction supplyNamespace; private final LongFunction supplyLocalName; private final ToIntFunction lookupLabelId; @@ -52,13 +53,13 @@ public class StdoutEventsStream private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( - RingBufferSpy eventSpy, + Supplier supplyEventSpy, LongFunction supplyNamespace, LongFunction supplyLocalName, ToIntFunction lookupLabelId, PrintStream out) { - this.eventSpy = eventSpy; + this.supplyEventSpy = supplyEventSpy; this.supplyNamespace = supplyNamespace; this.supplyLocalName = supplyLocalName; this.lookupLabelId = lookupLabelId; @@ -88,7 +89,7 @@ private void addEventHandler( public int process() { - return eventSpy.spy(this::handleEvent, 1); + return supplyEventSpy.get().spy(this::handleEvent, 1); } private boolean handleEvent( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index 063a83bf45..e256cce120 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -48,6 +48,7 @@ import java.util.function.IntFunction; import java.util.function.LongConsumer; import java.util.function.LongSupplier; +import java.util.function.Supplier; import java.util.function.ToIntFunction; import java.util.stream.Collectors; @@ -483,10 +484,11 @@ public long[][] histogramIds() return worker.histogramIds(); } - public RingBufferSpy[] supplyEventSpies( + public Supplier[] supplyEventSpies( SpyPosition position) { - RingBufferSpy[] spies = new RingBufferSpy[workers.size()]; + @SuppressWarnings("unchecked") + Supplier[] spies = new Supplier[workers.size()]; for (int i = 0; i < workers.size(); i++) { spies[i] = workers.get(i).supplyEventSpy(position); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index b8b08828c1..79cd5b2a0d 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -19,6 +19,7 @@ import java.net.URL; import java.nio.channels.SelectableChannel; import java.util.function.LongSupplier; +import java.util.function.Supplier; import org.agrona.MutableDirectBuffer; @@ -68,7 +69,7 @@ long supplyPromiseId( long supplyTraceId(); - RingBufferSpy[] supplyEventSpies( + Supplier[] supplyEventSpies( SpyPosition position); MessageConsumer supplySender( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index a7a187dad8..533ec475bc 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -60,6 +60,7 @@ import java.util.function.LongFunction; import java.util.function.LongSupplier; import java.util.function.LongUnaryOperator; +import java.util.function.Supplier; import org.agrona.DeadlineTimerWheel; import org.agrona.DeadlineTimerWheel.TimerHandler; @@ -214,7 +215,7 @@ public class EngineWorker implements EngineContext, Agent private final ScalarsLayout gaugesLayout; private final HistogramsLayout histogramsLayout; private final EventsLayout eventsLayout; - private final Function supplyEventSpies; + private final Function[]> supplyEventSpies; private long initialId; private long promiseId; private long traceId; @@ -237,7 +238,7 @@ public EngineWorker( Collection models, Collection metricGroups, Collector collector, - Function supplyEventSpies, + Function[]> supplyEventSpies, int index, boolean readonly) { @@ -1589,14 +1590,14 @@ public MessageConsumer supplyReceiver( return writersByIndex.computeIfAbsent(remoteIndex, supplyWriter); } - public RingBufferSpy supplyEventSpy( + public Supplier supplyEventSpy( SpyPosition position) { eventsLayout.spyAt(position); - return eventsLayout.bufferSpy(); + return eventsLayout::bufferSpy; } - public RingBufferSpy[] supplyEventSpies( + public Supplier[] supplyEventSpies( SpyPosition position) { return supplyEventSpies.apply(position); From c5a482c85f171a4b80716af1cc8a57f18ae5616a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 12 Feb 2024 11:23:28 +0100 Subject: [PATCH 062/167] WIP spies --- .../exporter/stdout/internal/StdoutExporterHandler.java | 4 ++-- .../exporter/stdout/internal/stream/StdoutEventsStream.java | 2 +- .../main/java/io/aklivity/zilla/runtime/engine/Engine.java | 4 ++-- .../io/aklivity/zilla/runtime/engine/EngineContext.java | 4 ++-- .../zilla/runtime/engine/internal/layouts/EventsLayout.java | 6 +++--- .../runtime/engine/internal/registry/EngineWorker.java | 4 ++-- .../engine/{reader => spy}/OneToOneRingBufferSpy.java | 2 +- .../zilla/runtime/engine/{reader => spy}/RingBufferSpy.java | 2 +- runtime/engine/src/main/moditect/module-info.java | 1 + 9 files changed, 15 insertions(+), 14 deletions(-) rename runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/{reader => spy}/OneToOneRingBufferSpy.java (98%) rename runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/{reader => spy}/RingBufferSpy.java (95%) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 3bbe9df2fd..667cf32fbb 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -21,8 +21,8 @@ import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; import io.aklivity.zilla.runtime.exporter.stdout.internal.stream.StdoutEventsStream; diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 0531f20b6d..f4347c110e 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -23,7 +23,7 @@ import org.agrona.collections.Int2ObjectHashMap; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index e256cce120..e02019d9de 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -76,8 +76,8 @@ import io.aklivity.zilla.runtime.engine.metrics.Collector; import io.aklivity.zilla.runtime.engine.metrics.MetricGroup; import io.aklivity.zilla.runtime.engine.model.Model; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.engine.vault.Vault; public final class Engine implements Collector, AutoCloseable diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 79cd5b2a0d..fb80a99189 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -38,8 +38,8 @@ import io.aklivity.zilla.runtime.engine.model.ConverterHandler; import io.aklivity.zilla.runtime.engine.model.ValidatorHandler; import io.aklivity.zilla.runtime.engine.poller.PollerKey; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.engine.vault.VaultHandler; public interface EngineContext diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index d6a358cbe7..61b8b32b3b 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -38,9 +38,9 @@ import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.engine.reader.OneToOneRingBufferSpy; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.spy.OneToOneRingBufferSpy; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; public final class EventsLayout implements AutoCloseable { diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 533ec475bc..b901fc50ed 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -136,8 +136,8 @@ import io.aklivity.zilla.runtime.engine.model.ModelContext; import io.aklivity.zilla.runtime.engine.model.ValidatorHandler; import io.aklivity.zilla.runtime.engine.poller.PollerKey; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.reader.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; import io.aklivity.zilla.runtime.engine.util.function.LongLongFunction; import io.aklivity.zilla.runtime.engine.vault.Vault; import io.aklivity.zilla.runtime.engine.vault.VaultContext; diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/OneToOneRingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/OneToOneRingBufferSpy.java similarity index 98% rename from runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/OneToOneRingBufferSpy.java rename to runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/OneToOneRingBufferSpy.java index 988b264941..0016cdd473 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/OneToOneRingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/OneToOneRingBufferSpy.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package io.aklivity.zilla.runtime.engine.reader; +package io.aklivity.zilla.runtime.engine.spy; import static org.agrona.BitUtil.align; import static org.agrona.concurrent.ringbuffer.RecordDescriptor.ALIGNMENT; diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/RingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/RingBufferSpy.java similarity index 95% rename from runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/RingBufferSpy.java rename to runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/RingBufferSpy.java index 1f98f98418..8271a04ec6 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/reader/RingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/RingBufferSpy.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package io.aklivity.zilla.runtime.engine.reader; +package io.aklivity.zilla.runtime.engine.spy; import org.agrona.DirectBuffer; diff --git a/runtime/engine/src/main/moditect/module-info.java b/runtime/engine/src/main/moditect/module-info.java index f6ba54367c..4d02851058 100644 --- a/runtime/engine/src/main/moditect/module-info.java +++ b/runtime/engine/src/main/moditect/module-info.java @@ -30,6 +30,7 @@ exports io.aklivity.zilla.runtime.engine.metrics.reader; exports io.aklivity.zilla.runtime.engine.reader; exports io.aklivity.zilla.runtime.engine.resolver; + exports io.aklivity.zilla.runtime.engine.spy; exports io.aklivity.zilla.runtime.engine.util.function; exports io.aklivity.zilla.runtime.engine.vault; From 1c311527aea82d46387339b129d3d56e55ea2613 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 12 Feb 2024 12:11:31 +0100 Subject: [PATCH 063/167] WIP spies --- .../engine/internal/layouts/EventsLayout.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index 61b8b32b3b..46fc2281d6 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -119,7 +119,7 @@ private void rotateFile() } } - private static RingBuffer createRingBuffer( + private static AtomicBuffer createAtomicBuffer( Path path, long capacity, boolean readonly) @@ -130,7 +130,15 @@ private static RingBuffer createRingBuffer( CloseHelper.close(createEmptyFile(layoutFile, capacity + RingBufferDescriptor.TRAILER_LENGTH)); } final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); - final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); + return new UnsafeBuffer(mappedBuffer); + } + + private static RingBuffer createRingBuffer( + Path path, + long capacity, + boolean readonly) + { + AtomicBuffer atomicBuffer = createAtomicBuffer(path, capacity, readonly); return new OneToOneRingBuffer(atomicBuffer); } @@ -138,9 +146,7 @@ private static RingBufferSpy createRingBufferSpy( Path path, SpyPosition position) { - final File layoutFile = path.toFile(); - final MappedByteBuffer mappedBuffer = mapExistingFile(layoutFile, "events"); - final AtomicBuffer atomicBuffer = new UnsafeBuffer(mappedBuffer); + AtomicBuffer atomicBuffer = createAtomicBuffer(path, 0, true); final OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); if (position != null) { From b934025f360dc61f239bb0c866da9c40de93f048 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 12 Feb 2024 15:50:07 +0100 Subject: [PATCH 064/167] WIP StdoutEventsStream --- .../internal/stream/StdoutEventsStream.java | 108 +++++++++++++++++- 1 file changed, 102 insertions(+), 6 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index f4347c110e..16a9f63e25 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -25,18 +25,40 @@ import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaAuthorizationEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.Result; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryRemoteAccessRejectedEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpRemoteAccessFailedEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsFailedEventFW; public class StdoutEventsStream { + private static final String HTTP_AUTHORIZATION_FORMAT = + "%s: HTTP Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + private static final String HTTP_ACCESS_DENIED = + "WARNING: HTTP Access Denied [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String KAFKA_AUTHORIZATION_FORMAT = + "%s: Kafka Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String KAFKA_API_VERSION_REJECTED = + "ERROR: Kafka API Version Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String MQTT_AUTHORIZATION_FORMAT = + "%s: MQTT Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + private static final String SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED = + "ERROR: Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s]" + + "[method = %s] [status = %d]%n"; private static final String TCP_REMOTE_ACCESS_FAILED_FORMAT = - "ERROR: Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; + "ERROR: TCP Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; + private static final String TLS_FAILED_FORMAT = + "ERROR: TLS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [error = %s]%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); @@ -112,7 +134,29 @@ private void handleHttpEvent( int index, int length) { - // TODO: Ati + final HttpEventFW event = httpEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case AUTHORIZATION: + { + HttpAuthorizationEventFW e = event.authorization(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + String level = e.result().get() == Result.SUCCESS ? "INFO" : "WARNING"; + String result = e.result().get() == Result.SUCCESS ? "Succeeded" : "Failed"; + out.printf(HTTP_AUTHORIZATION_FORMAT, level, result, e.timestamp(), e.traceId(), namespace, binding, + asString(e.identity())); + break; + } + case ACCESS_DENIED: + { + EventFW e = event.accessDenied(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(HTTP_ACCESS_DENIED, e.timestamp(), e.traceId(), namespace, binding); + break; + } + } } private void handleKafkaEvent( @@ -121,7 +165,28 @@ private void handleKafkaEvent( int index, int length) { - // TODO: Ati + final KafkaEventFW event = kafkaEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case AUTHORIZATION: + { + KafkaAuthorizationEventFW e = event.authorization(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + String level = e.result().get() == Result.SUCCESS ? "INFO" : "WARNING"; + String result = e.result().get() == Result.SUCCESS ? "Succeeded" : "Failed"; + out.printf(KAFKA_AUTHORIZATION_FORMAT, level, result, e.timestamp(), e.traceId(), namespace, binding); + break; + } + case API_VERSION_REJECTED: + { + EventFW e = event.apiVersionRejected(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(KAFKA_API_VERSION_REJECTED, e.timestamp(), e.traceId(), namespace, binding); + break; + } + } } private void handleMqttEvent( @@ -130,7 +195,19 @@ private void handleMqttEvent( int index, int length) { - // TODO: Ati + MqttEventFW event = mqttEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case AUTHORIZATION: + MqttAuthorizationEventFW e = event.authorization(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + String level = e.result().get() == Result.SUCCESS ? "INFO" : "WARNING"; + String result = e.result().get() == Result.SUCCESS ? "Succeeded" : "Failed"; + out.printf(MQTT_AUTHORIZATION_FORMAT, level, result, e.timestamp(), e.traceId(), namespace, binding, + asString(e.identity())); + break; + } } private void handleSchemaRegistryEvent( @@ -139,7 +216,17 @@ private void handleSchemaRegistryEvent( int index, int length) { - // TODO: Ati + SchemaRegistryEventFW event = schemaRegistryEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case REMOTE_ACCESS_REJECTED: + SchemaRegistryRemoteAccessRejectedEventFW e = event.remoteAccessRejected(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED, e.timestamp(), e.traceId(), namespace, binding, asString(e.url()), + asString(e.method()), e.status()); + break; + } } private void handleTcpEvent( @@ -166,7 +253,16 @@ private void handleTlsEvent( int index, int length) { - // TODO: Ati + TlsEventFW event = tlsEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case TLS_FAILED: + TlsFailedEventFW e = event.tlsFailed(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(TLS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, e.error().get().name()); + break; + } } private static String asString( From be6486b6312d1afec83ad453185f444328d1f706 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 12 Feb 2024 17:15:43 +0100 Subject: [PATCH 065/167] add EventsLayoutTest --- .../internal/layouts/EventsLayoutTest.java | 72 +++++++++++++++++++ .../metrics/HistogramsLayoutTest.java | 4 +- .../metrics/ScalarsLayoutTest.java | 4 +- 3 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java rename runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/{layout => layouts}/metrics/HistogramsLayoutTest.java (98%) rename runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/{layout => layouts}/metrics/ScalarsLayoutTest.java (96%) diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java new file mode 100644 index 0000000000..2e2ed2ea91 --- /dev/null +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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.aklivity.zilla.runtime.engine.internal.layouts; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.agrona.DirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; +import org.junit.Test; + +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; + +public class EventsLayoutTest +{ + private static final Path EVENTS0_PATH = Paths.get("target/zilla-itests/events0"); + + private int msgTypeId; + + @Test + public void shouldWorkInGenericCase() throws Exception + { + // GIVEN + EventsLayout eventsWriter = new EventsLayout.Builder() + .path(EVENTS0_PATH) + .capacity(1024) + .readonly(false) + .build(); + MessageConsumer eventWriter = eventsWriter.supplyWriter(); + eventWriter.accept(42, new UnsafeBuffer(), 0, 0); + EventsLayout eventReader = new EventsLayout.Builder() + .path(EVENTS0_PATH) + .readonly(true) + .build(); + eventReader.spyAt(RingBufferSpy.SpyPosition.ZERO); + RingBufferSpy spy = eventReader.bufferSpy(); + msgTypeId = 0; + + // WHEN + spy.spy(this::readEvent); + + // THEN + assertThat(msgTypeId, equalTo(42)); + } + + private boolean readEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + this.msgTypeId = msgTypeId; + return true; + } +} diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layout/metrics/HistogramsLayoutTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/metrics/HistogramsLayoutTest.java similarity index 98% rename from runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layout/metrics/HistogramsLayoutTest.java rename to runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/metrics/HistogramsLayoutTest.java index 9109ab83c2..9d5d5070ae 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layout/metrics/HistogramsLayoutTest.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/metrics/HistogramsLayoutTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package io.aklivity.zilla.runtime.engine.internal.layout.metrics; +package io.aklivity.zilla.runtime.engine.internal.layouts.metrics; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -28,8 +28,6 @@ import org.junit.Test; -import io.aklivity.zilla.runtime.engine.internal.layouts.metrics.HistogramsLayout; - public class HistogramsLayoutTest { @Test diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layout/metrics/ScalarsLayoutTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/metrics/ScalarsLayoutTest.java similarity index 96% rename from runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layout/metrics/ScalarsLayoutTest.java rename to runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/metrics/ScalarsLayoutTest.java index bbfdefa615..0a31ac6eb1 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layout/metrics/ScalarsLayoutTest.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/metrics/ScalarsLayoutTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package io.aklivity.zilla.runtime.engine.internal.layout.metrics; +package io.aklivity.zilla.runtime.engine.internal.layouts.metrics; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -28,8 +28,6 @@ import org.junit.Test; -import io.aklivity.zilla.runtime.engine.internal.layouts.metrics.ScalarsLayout; - public class ScalarsLayoutTest { @Test From 882434365ae9786e052c25a37521f48689bdb46d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 12 Feb 2024 17:21:33 +0100 Subject: [PATCH 066/167] fix pom --- incubator/exporter-stdout.spec/pom.xml | 2 +- incubator/exporter-stdout/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/incubator/exporter-stdout.spec/pom.xml b/incubator/exporter-stdout.spec/pom.xml index 4ed5662b0f..b786f0b919 100644 --- a/incubator/exporter-stdout.spec/pom.xml +++ b/incubator/exporter-stdout.spec/pom.xml @@ -13,7 +13,7 @@ exporter-stdout.spec - zilla::specs::exporter-stdout.spec + zilla::incubator::exporter-stdout.spec diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 83a00b73b5..35a017f41e 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -13,7 +13,7 @@ exporter-stdout - zilla::runtime::exporter-stdout + zilla::incubator::exporter-stdout From bfa4acaa5ea9e7be3446d36d50f0cd0837619c3c Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 12 Feb 2024 17:39:18 +0100 Subject: [PATCH 067/167] add StdoutExporterHandlerTest --- incubator/exporter-stdout/pom.xml | 4 +- .../internal/StdoutExporterHandlerTest.java | 96 +++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 35a017f41e..f084cce8af 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,8 +26,8 @@ 11 11 - 0.01 - 99 + 0.35 + 0 diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java new file mode 100644 index 0000000000..92d026cc10 --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -0,0 +1,96 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.function.Supplier; + +import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; +import org.junit.Test; + +import io.aklivity.zilla.runtime.engine.EngineConfiguration; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.engine.config.ExporterConfig; +import io.aklivity.zilla.runtime.engine.internal.layouts.EventsLayout; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; + +public class StdoutExporterHandlerTest +{ + private static final Path ENGINE_PATH = Paths.get("target/zilla-itests"); + private static final Path EVENTS_PATH = ENGINE_PATH.resolve("events"); + private static final int TCP_TYPE_ID = 1; + private static final String EXPECTED_OUTPUT = "ERROR: TCP Remote Access Failed [timestamp = 77] " + + "[traceId = 0x0000000000000042] [binding = ns.binding] [address = address]\n"; + + @Test + @SuppressWarnings("unchecked") + public void shouldStart() + { + // GIVEN + EventsLayout eventsWriter = new EventsLayout.Builder() + .path(EVENTS_PATH) + .capacity(1024) + .readonly(false) + .build(); + MessageConsumer eventWriter = eventsWriter.supplyWriter(); + MutableDirectBuffer eventBuffer = new UnsafeBuffer(new byte[64]); + TcpEventFW event = new TcpEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .remoteAccessFailed(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + .address("address") + ).build(); + eventWriter.accept(TCP_TYPE_ID, event.buffer(), 0, event.sizeof()); + EventsLayout eventReader = new EventsLayout.Builder() + .path(EVENTS_PATH) + .readonly(true) + .build(); + eventReader.spyAt(RingBufferSpy.SpyPosition.ZERO); + + EngineConfiguration config = mock(EngineConfiguration.class); + EngineContext context = mock(EngineContext.class); + StdoutExporterConfig exporter = new StdoutExporterConfig(mock(ExporterConfig.class)); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(os); + when(context.lookupLabelId("tcp")).thenReturn(TCP_TYPE_ID); + when(context.supplyNamespace(0x0000000200000007L)).thenReturn("ns"); + when(context.supplyLocalName(0x0000000200000007L)).thenReturn("binding"); + when(context.supplyEventSpies(RingBufferSpy.SpyPosition.ZERO)).thenReturn( + new Supplier[] {eventReader::bufferSpy} + ); + StdoutExporterHandler handler = new StdoutExporterHandler(config, context, exporter, ps); + + // WHEN + handler.start(); + handler.export(); + + // THEN + assertThat(os.toString(), equalTo(EXPECTED_OUTPUT)); + handler.stop(); + } +} From 62f976e73ef3325c0af4e765e22c4a04a81818aa Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 12 Feb 2024 18:06:21 +0100 Subject: [PATCH 068/167] fix --- .../zilla/runtime/engine/internal/layouts/EventsLayoutTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java index 2e2ed2ea91..b4061d2dd1 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java @@ -35,7 +35,7 @@ public class EventsLayoutTest private int msgTypeId; @Test - public void shouldWorkInGenericCase() throws Exception + public void shouldSpy() { // GIVEN EventsLayout eventsWriter = new EventsLayout.Builder() From 624e7ef7ead7b24a40a6605cdfc8e67c5ef1b614 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 12:22:55 +0100 Subject: [PATCH 069/167] fix --- cloud/docker-image/src/main/docker/zpm.json.template | 2 +- .../registry/internal/SchemaRegistryCatalogHandler.java | 5 ++--- .../registry/internal/SchemaRegistryEventContext.java | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cloud/docker-image/src/main/docker/zpm.json.template b/cloud/docker-image/src/main/docker/zpm.json.template index 0f5dc078a4..b0df49d630 100644 --- a/cloud/docker-image/src/main/docker/zpm.json.template +++ b/cloud/docker-image/src/main/docker/zpm.json.template @@ -43,9 +43,9 @@ "io.aklivity.zilla:command-stop", "io.aklivity.zilla:command-tune", "io.aklivity.zilla:engine", + "io.aklivity.zilla:exporter-otlp", "io.aklivity.zilla:exporter-prometheus", "io.aklivity.zilla:exporter-stdout", - "io.aklivity.zilla:exporter-otlp", "io.aklivity.zilla:guard-jwt", "io.aklivity.zilla:metrics-stream", "io.aklivity.zilla:metrics-http", diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java index 288acfbebf..b6adaa334e 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java @@ -224,14 +224,13 @@ private String sendHttpRequest( } else { - event.remoteAccessRejected(catalogId, httpRequest.uri().toString(), httpRequest.method(), response.statusCode()); + event.remoteAccessRejected(catalogId, httpRequest, response.statusCode()); } return responseBody; } catch (Exception ex) { - event.remoteAccessRejected(catalogId, httpRequest.uri().toString(), httpRequest.method(), -1); - ex.printStackTrace(System.out); + event.remoteAccessRejected(catalogId, httpRequest, 0); } return null; } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 96ad0fd185..8b2726effc 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -14,6 +14,7 @@ */ package io.aklivity.zilla.runtime.catalog.schema.registry.internal; +import java.net.http.HttpRequest; import java.nio.ByteBuffer; import java.util.function.LongSupplier; @@ -44,8 +45,7 @@ public SchemaRegistryEventContext( public void remoteAccessRejected( long catalogId, - String url, - String method, + HttpRequest httpRequest, int status) { SchemaRegistryEventFW event = schemaRegistryEventRW @@ -53,8 +53,8 @@ public void remoteAccessRejected( .remoteAccessRejected(e -> e .timestamp(timestamp.getAsLong()) .namespacedId(catalogId) - .url(url) - .method(method) + .url(httpRequest.uri().toString()) + .method(httpRequest.method()) .status((short) status) ) .build(); From 3f9b66c2347f0be84bcb09c84a408381661c4604 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 12:28:23 +0100 Subject: [PATCH 070/167] fix --- .../internal/SchemaRegistryCatalogHandler.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java index b6adaa334e..88f47fd777 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java @@ -216,15 +216,12 @@ private String sendHttpRequest( try { - HttpResponse response = client.send(httpRequest, HttpResponse.BodyHandlers.ofString()); - String responseBody = null; - if (response.statusCode() == 200) - { - responseBody = response.body(); - } - else + HttpResponse httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString()); + boolean success = httpResponse.statusCode() == 200; + String responseBody = success ? httpResponse.body() : null; + if (!success) { - event.remoteAccessRejected(catalogId, httpRequest, response.statusCode()); + event.remoteAccessRejected(catalogId, httpRequest, httpResponse.statusCode()); } return responseBody; } From 8f39a7768e26dea182e5ba4bd0a2a943a7f353ed Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 12:31:21 +0100 Subject: [PATCH 071/167] fix onDecodeResponseErrorCode --- .../stream/KafkaClientDescribeFactory.java | 2 +- .../internal/stream/KafkaClientFetchFactory.java | 4 ++-- .../internal/stream/KafkaClientGroupFactory.java | 14 +++++++------- .../internal/stream/KafkaClientMetaFactory.java | 4 ++-- .../stream/KafkaClientOffsetCommitFactory.java | 2 +- .../stream/KafkaClientOffsetFetchFactory.java | 2 +- .../internal/stream/KafkaClientProduceFactory.java | 2 +- .../internal/stream/KafkaClientSaslHandshaker.java | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java index 3ba84ac540..c255364d8f 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java @@ -531,7 +531,7 @@ private int decodeDescribeResponse( final String resourceName = resource.name().asString(); final int resourceError = resource.errorCode(); - checkUnsupportedVersionError(resourceError, traceId); + onDecodeResponseErrorCode(resourceError, traceId); client.onDecodeResource(traceId, client.authorization, resourceError, resourceName); // TODO: use different decoder for configs diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java index bb25d04e4c..035ff88551 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java @@ -762,7 +762,7 @@ private int decodeOffsetsPartition( final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); final long partitionOffset = partition.offset$(); progress = partition.limit(); @@ -908,7 +908,7 @@ else if (length != 0) { final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); client.stableOffset = partition.lastStableOffset() - 1; client.latestOffset = partition.highWatermark() - 1; diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java index 328d02e20a..0bfbb7f98f 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java @@ -778,7 +778,7 @@ private int decodeDescribeResponse( final String resourceName = resource.name().asString(); final short errorCode = resource.errorCode(); - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); if (errorCode != ERROR_NONE || !client.delegate.nodeId.equals(resourceName)) { @@ -879,7 +879,7 @@ private int decodeFindCoordinatorResponse( findCoordinatorResponse.host(), findCoordinatorResponse.port()); break; default: - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeClusterReject; break; @@ -970,7 +970,7 @@ private int decodeJoinGroupResponse( joinGroupResponseRO.tryWrap(buffer, progress, limit); final short errorCode = joinGroupResponse != null ? joinGroupResponse.errorCode() : ERROR_EXISTS; - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); if (joinGroupResponse == null) { @@ -1057,7 +1057,7 @@ private int decodeSyncGroupResponse( syncGroupResponseRO.tryWrap(buffer, progress, limit); final short errorCode = syncGroupResponse != null ? syncGroupResponse.errorCode() : ERROR_EXISTS; - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); if (syncGroupResponse == null) { @@ -1124,7 +1124,7 @@ private int decodeHeartbeatResponse( progress = heartbeatResponse.limit(); final short errorCode = heartbeatResponse.errorCode(); - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); switch (errorCode) { @@ -1202,7 +1202,7 @@ private int decodeLeaveGroupResponse( } else { - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } @@ -1217,7 +1217,7 @@ private int decodeLeaveGroupResponse( } else { - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java index b961202857..97991e6127 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java @@ -698,7 +698,7 @@ private int decodeMetaTopic( final String topic = topicMetadata.topic().asString(); final int topicError = topicMetadata.errorCode(); - checkUnsupportedVersionError(topicError, traceId); + onDecodeResponseErrorCode(topicError, traceId); client.onDecodeTopic(traceId, authorization, topicError, topic); @@ -763,7 +763,7 @@ private int decodeMetaPartition( } final int partitionError = partition.errorCode(); - checkUnsupportedVersionError(partitionError, traceId); + onDecodeResponseErrorCode(partitionError, traceId); final int partitionId = partition.partitionId(); final int leaderId = partition.leader(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java index 0a78b5f98b..90bf3766ce 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java @@ -589,7 +589,7 @@ private int decodeOffsetCommitPartition( } else { - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeReject; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java index 269da7c085..921011b472 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java @@ -661,7 +661,7 @@ private int decodeOffsetFetchPartition( client.decoder = decodeOffsetFetchPartitions; break; default: - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); client.errorCode = errorCode; client.decoder = decodeReject; break; diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index e6144c47a5..5863b40c96 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -816,7 +816,7 @@ private int decodeProducePartition( final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); - checkUnsupportedVersionError(errorCode, traceId); + onDecodeResponseErrorCode(errorCode, traceId); progress = partition.limit(); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index c8d8e0bca3..aaf75fcb10 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -834,7 +834,7 @@ private String16FW createClientId( return clientId != null ? new String16FW(clientId) : KAFKA_CLIENT_ID_DEFAULT_VALUE; } - protected void checkUnsupportedVersionError( + protected void onDecodeResponseErrorCode( int errorCode, long traceId) { From 0f57f30f5649ea5804be113ed11a0108df733a32 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 13:15:10 +0100 Subject: [PATCH 072/167] rm accessDeinied --- .../internal/stream/StdoutEventsStream.java | 10 ---------- .../binding/http/internal/HttpEventContext.java | 16 ---------------- .../http/internal/stream/HttpServerFactory.java | 2 -- .../src/main/resources/META-INF/zilla/http.idl | 4 +--- 4 files changed, 1 insertion(+), 31 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 16a9f63e25..b20713dd46 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -138,7 +138,6 @@ private void handleHttpEvent( switch (event.kind()) { case AUTHORIZATION: - { HttpAuthorizationEventFW e = event.authorization(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); @@ -148,15 +147,6 @@ private void handleHttpEvent( asString(e.identity())); break; } - case ACCESS_DENIED: - { - EventFW e = event.accessDenied(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HTTP_ACCESS_DENIED, e.timestamp(), e.traceId(), namespace, binding); - break; - } - } } private void handleKafkaEvent( diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 31852591ce..347cb03b0f 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -44,22 +44,6 @@ public HttpEventContext( this.timestamp = context.timestamp(); } - public void accessDenied( - long traceId, - long routedId) - { - HttpEventFW event = httpEventRW - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .accessDenied(e -> e - .timestamp(timestamp.getAsLong()) - .traceId(traceId) - .namespacedId(routedId) - ) - .build(); - System.out.println(event); // TODO: Ati - logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); - } - public void authorization( long sessionId, long traceId, diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 9a219e9a52..b56d449fbe 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1031,7 +1031,6 @@ else if (limit > endOfMethodLimit) } else if (!isCorsRequestAllowed(server.binding, headers)) { - event.accessDenied(traceId, server.routedId); server.onDecodeHeadersError(traceId, authorization, response403); server.decoder = decodeIgnore; } @@ -4942,7 +4941,6 @@ else if (headersDecoder.httpError()) } else if (!isCorsRequestAllowed(binding, headers)) { - event.accessDenied(traceId, routedId); doEncodeHeaders(traceId, authorization, streamId, headers403, true); } else diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 5bd3f39086..cdbe5e859a 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -54,8 +54,7 @@ scope http { enum HttpEventType (uint8) { - AUTHORIZATION (1), - ACCESS_DENIED (2) + AUTHORIZATION (1) } enum Result (uint8) @@ -73,7 +72,6 @@ scope http union HttpEvent switch (HttpEventType) { case AUTHORIZATION: HttpAuthorizationEvent authorization; - case ACCESS_DENIED: core::event::Event accessDenied; } } } From 393b00b28485ccb29020739b4a2de36b1126b76b Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 13:27:52 +0100 Subject: [PATCH 073/167] fix internal --- .../zilla/runtime/engine/internal/layouts/EventsLayout.java | 2 +- .../engine/{ => internal}/spy/OneToOneRingBufferSpy.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) rename runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/{ => internal}/spy/OneToOneRingBufferSpy.java (97%) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index 46fc2281d6..06745fb73b 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -38,7 +38,7 @@ import org.agrona.concurrent.ringbuffer.RingBufferDescriptor; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.engine.spy.OneToOneRingBufferSpy; +import io.aklivity.zilla.runtime.engine.internal.spy.OneToOneRingBufferSpy; import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/OneToOneRingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java similarity index 97% rename from runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/OneToOneRingBufferSpy.java rename to runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java index 0016cdd473..c47b99a52c 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/OneToOneRingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package io.aklivity.zilla.runtime.engine.spy; +package io.aklivity.zilla.runtime.engine.internal.spy; import static org.agrona.BitUtil.align; import static org.agrona.concurrent.ringbuffer.RecordDescriptor.ALIGNMENT; @@ -32,6 +32,7 @@ import org.agrona.concurrent.AtomicBuffer; import io.aklivity.zilla.runtime.engine.binding.function.MessagePredicate; +import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; public class OneToOneRingBufferSpy implements RingBufferSpy { From 705ad99fa89f0c911c28c568ff8cd0945640fb15 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 13:39:05 +0100 Subject: [PATCH 074/167] cleanup --- .../schema/registry/internal/SchemaRegistryEventContext.java | 1 - .../zilla/runtime/binding/http/internal/HttpEventContext.java | 1 - .../zilla/runtime/binding/kafka/internal/KafkaEventContext.java | 2 -- .../zilla/runtime/binding/mqtt/internal/MqttEventContext.java | 1 - .../zilla/runtime/binding/tls/internal/TlsEventContext.java | 1 - 5 files changed, 6 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 8b2726effc..b3cccaf7d6 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -58,7 +58,6 @@ public void remoteAccessRejected( .status((short) status) ) .build(); - System.out.println(event); // TODO: Ati logger.accept(schemaRegistryTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 347cb03b0f..d78a03d4c9 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -61,7 +61,6 @@ public void authorization( .identity(identity) ) .build(); - System.out.println(event); // TODO: Ati logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 47fc7d60fd..f13a7ef889 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -60,7 +60,6 @@ public void authorization( .result(r -> r.set(result)) ) .build(); - System.out.println(event); // TODO: Ati logger.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } @@ -74,7 +73,6 @@ public void apiVersionRejected( .traceId(traceId) ) .build(); - System.out.println(event); // TODO: Ati logger.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 12382396bf..b81fc0d67e 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -61,7 +61,6 @@ public void authorization( .identity(identity) ) .build(); - System.out.println(event); // TODO: Ati logger.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index ae8080dd35..00a67d03a1 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -61,7 +61,6 @@ public void tlsFailed( .error(r -> r.set(error)) ) .build(); - System.out.println(event); // TODO: Ati logger.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); } From 8d63a5d9b2323c0d9d6ea9f114870dbd43c6b090 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 15:54:13 +0100 Subject: [PATCH 075/167] fix EventReader --- incubator/exporter-stdout/pom.xml | 2 +- .../internal/StdoutExporterHandler.java | 10 +-- .../internal/stream/StdoutEventsStream.java | 14 ++-- .../internal/StdoutExporterHandlerTest.java | 22 ++--- .../aklivity/zilla/runtime/engine/Engine.java | 16 ++-- .../zilla/runtime/engine/EngineContext.java | 10 ++- .../engine/internal/layouts/EventsLayout.java | 80 +++++++------------ .../internal/registry/EngineWorker.java | 25 +++--- .../internal/spy/OneToOneRingBufferSpy.java | 13 +-- .../{ => internal}/spy/RingBufferSpy.java | 8 +- .../engine/util/function/EventReader.java | 25 ++++++ .../engine/src/main/moditect/module-info.java | 1 - .../internal/layouts/EventsLayoutTest.java | 26 ++---- 13 files changed, 109 insertions(+), 143 deletions(-) rename runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/{ => internal}/spy/RingBufferSpy.java (85%) create mode 100644 runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index f084cce8af..45a7da2d73 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,7 +26,7 @@ 11 11 - 0.35 + 0.40 0 diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 667cf32fbb..d8f511afcc 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -16,13 +16,11 @@ import java.io.PrintStream; import java.util.Arrays; -import java.util.function.Supplier; import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; import io.aklivity.zilla.runtime.exporter.stdout.internal.stream.StdoutEventsStream; @@ -46,7 +44,7 @@ public StdoutExporterHandler( @Override public void start() { - this.stdoutEventStreams = Arrays.stream(context.supplyEventSpies(SpyPosition.ZERO)) + this.stdoutEventStreams = Arrays.stream(context.supplyEventReaders().get()) .map(this::newStdoutEventsStream) .toArray(StdoutEventsStream[]::new); } @@ -71,9 +69,9 @@ public void stop() } private StdoutEventsStream newStdoutEventsStream( - Supplier supplyEventSpy) + EventReader eventReader) { - return new StdoutEventsStream(supplyEventSpy, context::supplyNamespace, context::supplyLocalName, + return new StdoutEventsStream(eventReader, context::supplyNamespace, context::supplyLocalName, context::lookupLabelId, out); } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index b20713dd46..dde59ede8d 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -16,14 +16,13 @@ import java.io.PrintStream; import java.util.function.LongFunction; -import java.util.function.Supplier; import java.util.function.ToIntFunction; import org.agrona.DirectBuffer; import org.agrona.collections.Int2ObjectHashMap; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationEventFW; @@ -67,7 +66,7 @@ public class StdoutEventsStream private final TcpEventFW tcpEventRO = new TcpEventFW(); private final TlsEventFW tlsEventRO = new TlsEventFW(); - private final Supplier supplyEventSpy; + private final EventReader readEvent; private final LongFunction supplyNamespace; private final LongFunction supplyLocalName; private final ToIntFunction lookupLabelId; @@ -75,13 +74,13 @@ public class StdoutEventsStream private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( - Supplier supplyEventSpy, + EventReader readEvent, LongFunction supplyNamespace, LongFunction supplyLocalName, ToIntFunction lookupLabelId, PrintStream out) { - this.supplyEventSpy = supplyEventSpy; + this.readEvent = readEvent; this.supplyNamespace = supplyNamespace; this.supplyLocalName = supplyLocalName; this.lookupLabelId = lookupLabelId; @@ -111,10 +110,10 @@ private void addEventHandler( public int process() { - return supplyEventSpy.get().spy(this::handleEvent, 1); + return readEvent.applyAsInt(this::handleEvent, 1); } - private boolean handleEvent( + private void handleEvent( int msgTypeId, DirectBuffer buffer, int index, @@ -125,7 +124,6 @@ private boolean handleEvent( { handler.accept(msgTypeId, buffer, index, length); } - return true; } private void handleHttpEvent( diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index 92d026cc10..812eb85bb3 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -23,7 +23,6 @@ import java.io.PrintStream; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.function.Supplier; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -31,10 +30,9 @@ import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; -import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; import io.aklivity.zilla.runtime.engine.config.ExporterConfig; import io.aklivity.zilla.runtime.engine.internal.layouts.EventsLayout; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; @@ -42,6 +40,7 @@ public class StdoutExporterHandlerTest { private static final Path ENGINE_PATH = Paths.get("target/zilla-itests"); private static final Path EVENTS_PATH = ENGINE_PATH.resolve("events"); + private static final int CAPACITY = 1024; private static final int TCP_TYPE_ID = 1; private static final String EXPECTED_OUTPUT = "ERROR: TCP Remote Access Failed [timestamp = 77] " + "[traceId = 0x0000000000000042] [binding = ns.binding] [address = address]\n"; @@ -51,12 +50,10 @@ public class StdoutExporterHandlerTest public void shouldStart() { // GIVEN - EventsLayout eventsWriter = new EventsLayout.Builder() + EventsLayout layout = new EventsLayout.Builder() .path(EVENTS_PATH) - .capacity(1024) - .readonly(false) + .capacity(CAPACITY) .build(); - MessageConsumer eventWriter = eventsWriter.supplyWriter(); MutableDirectBuffer eventBuffer = new UnsafeBuffer(new byte[64]); TcpEventFW event = new TcpEventFW.Builder() .wrap(eventBuffer, 0, eventBuffer.capacity()) @@ -65,12 +62,7 @@ public void shouldStart() .namespacedId(0x0000000200000007L) .address("address") ).build(); - eventWriter.accept(TCP_TYPE_ID, event.buffer(), 0, event.sizeof()); - EventsLayout eventReader = new EventsLayout.Builder() - .path(EVENTS_PATH) - .readonly(true) - .build(); - eventReader.spyAt(RingBufferSpy.SpyPosition.ZERO); + layout.writeEvent(TCP_TYPE_ID, event.buffer(), 0, event.sizeof()); EngineConfiguration config = mock(EngineConfiguration.class); EngineContext context = mock(EngineContext.class); @@ -80,9 +72,7 @@ public void shouldStart() when(context.lookupLabelId("tcp")).thenReturn(TCP_TYPE_ID); when(context.supplyNamespace(0x0000000200000007L)).thenReturn("ns"); when(context.supplyLocalName(0x0000000200000007L)).thenReturn("binding"); - when(context.supplyEventSpies(RingBufferSpy.SpyPosition.ZERO)).thenReturn( - new Supplier[] {eventReader::bufferSpy} - ); + when(context.supplyEventReaders()).thenReturn(() -> new EventReader[]{layout::readEvent}); StdoutExporterHandler handler = new StdoutExporterHandler(config, context, exporter, ps); // WHEN diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index 08f2aba33a..119bd0e568 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -48,7 +48,6 @@ import java.util.function.IntFunction; import java.util.function.LongConsumer; import java.util.function.LongSupplier; -import java.util.function.Supplier; import java.util.function.ToIntFunction; import java.util.stream.Collectors; @@ -76,8 +75,7 @@ import io.aklivity.zilla.runtime.engine.metrics.MetricGroup; import io.aklivity.zilla.runtime.engine.model.Model; import io.aklivity.zilla.runtime.engine.namespace.NamespacedId; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.engine.vault.Vault; public final class Engine implements Collector, AutoCloseable @@ -163,7 +161,7 @@ public final class Engine implements Collector, AutoCloseable EngineWorker worker = new EngineWorker(config, tasks, labels, errorHandler, tuning::affinity, bindings, exporters, guards, vaults, catalogs, models, metricGroups, - this, this::supplyEventSpies, coreIndex, readonly); + this, this::supplyEventReaders, coreIndex, readonly); workers.add(worker); } this.workers = workers; @@ -484,16 +482,14 @@ public long[][] histogramIds() return worker.histogramIds(); } - public Supplier[] supplyEventSpies( - SpyPosition position) + public EventReader[] supplyEventReaders() { - @SuppressWarnings("unchecked") - Supplier[] spies = new Supplier[workers.size()]; + EventReader[] readers = new EventReader[workers.size()]; for (int i = 0; i < workers.size(); i++) { - spies[i] = workers.get(i).supplyEventSpy(position); + readers[i] = workers.get(i)::readEvent; } - return spies; + return readers; } public String supplyLocalName( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index fb80a99189..f9b4045135 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -38,8 +38,7 @@ import io.aklivity.zilla.runtime.engine.model.ConverterHandler; import io.aklivity.zilla.runtime.engine.model.ValidatorHandler; import io.aklivity.zilla.runtime.engine.poller.PollerKey; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.engine.vault.VaultHandler; public interface EngineContext @@ -69,8 +68,11 @@ long supplyPromiseId( long supplyTraceId(); - Supplier[] supplyEventSpies( - SpyPosition position); + int readEvent( + MessageConsumer handler, + int messageCountLimit); + + Supplier supplyEventReaders(); MessageConsumer supplySender( long streamId); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index 06745fb73b..4e49a815e4 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -15,6 +15,7 @@ */ package io.aklivity.zilla.runtime.engine.internal.layouts; +import static io.aklivity.zilla.runtime.engine.internal.spy.RingBufferSpy.SpyPosition.ZERO; import static org.agrona.IoUtil.createEmptyFile; import static org.agrona.IoUtil.mapExistingFile; import static org.agrona.IoUtil.unmap; @@ -39,8 +40,7 @@ import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; import io.aklivity.zilla.runtime.engine.internal.spy.OneToOneRingBufferSpy; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.internal.spy.RingBufferSpy; public final class EventsLayout implements AutoCloseable { @@ -49,33 +49,17 @@ public final class EventsLayout implements AutoCloseable private RingBuffer buffer; private RingBufferSpy bufferSpy; - private SpyPosition position; private EventsLayout( Path path, long capacity, - RingBuffer buffer) + RingBuffer buffer, + RingBufferSpy bufferSpy) { - this.buffer = buffer; - this.capacity = capacity; this.path = path; - } - - public MessageConsumer supplyWriter() - { - return this::writeEvent; - } - - public void spyAt( - SpyPosition position) - { - this.position = position; - bufferSpy = createRingBufferSpy(path, position); - } - - public RingBufferSpy bufferSpy() - { - return bufferSpy; + this.capacity = capacity; + this.buffer = buffer; + this.bufferSpy = bufferSpy; } @Override @@ -84,7 +68,7 @@ public void close() unmap(buffer.buffer().byteBuffer()); } - private void writeEvent( + public void writeEvent( int msgTypeId, DirectBuffer recordBuffer, int index, @@ -98,6 +82,13 @@ private void writeEvent( } } + public int readEvent( + MessageConsumer handler, + int messageCountLimit) + { + return bufferSpy.spy(handler, messageCountLimit); + } + private void rotateFile() { close(); @@ -112,20 +103,17 @@ private void rotateFile() ex.printStackTrace(); rethrowUnchecked(ex); } - buffer = createRingBuffer(path, capacity, false); - if (position != null) - { - bufferSpy = createRingBufferSpy(path, position); - } + buffer = createRingBuffer(path, capacity); + bufferSpy = createRingBufferSpy(path); } private static AtomicBuffer createAtomicBuffer( Path path, long capacity, - boolean readonly) + boolean createFile) { final File layoutFile = path.toFile(); - if (!readonly) + if (createFile) { CloseHelper.close(createEmptyFile(layoutFile, capacity + RingBufferDescriptor.TRAILER_LENGTH)); } @@ -135,23 +123,18 @@ private static AtomicBuffer createAtomicBuffer( private static RingBuffer createRingBuffer( Path path, - long capacity, - boolean readonly) + long capacity) { - AtomicBuffer atomicBuffer = createAtomicBuffer(path, capacity, readonly); + AtomicBuffer atomicBuffer = createAtomicBuffer(path, capacity, true); return new OneToOneRingBuffer(atomicBuffer); } private static RingBufferSpy createRingBufferSpy( - Path path, - SpyPosition position) + Path path) { - AtomicBuffer atomicBuffer = createAtomicBuffer(path, 0, true); - final OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); - if (position != null) - { - spy.spyAt(position); - } + AtomicBuffer atomicBuffer = createAtomicBuffer(path, 0, false); + OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); + spy.spyAt(ZERO); return spy; } @@ -159,7 +142,6 @@ public static final class Builder { private long capacity; private Path path; - private boolean readonly; public Builder capacity( long capacity) @@ -175,17 +157,11 @@ public Builder path( return this; } - public Builder readonly( - boolean readonly) - { - this.readonly = readonly; - return this; - } - public EventsLayout build() { - RingBuffer ringBuffer = createRingBuffer(path, capacity, readonly); - return new EventsLayout(path, capacity, ringBuffer); + RingBuffer ringBuffer = createRingBuffer(path, capacity); + RingBufferSpy ringBufferSpy = createRingBufferSpy(path); + return new EventsLayout(path, capacity, ringBuffer, ringBufferSpy); } } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index e2609b1579..c5fe1e2bc4 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -136,8 +136,7 @@ import io.aklivity.zilla.runtime.engine.model.ValidatorHandler; import io.aklivity.zilla.runtime.engine.namespace.NamespacedId; import io.aklivity.zilla.runtime.engine.poller.PollerKey; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy.SpyPosition; +import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.engine.util.function.LongLongFunction; import io.aklivity.zilla.runtime.engine.vault.Vault; import io.aklivity.zilla.runtime.engine.vault.VaultContext; @@ -215,7 +214,7 @@ public class EngineWorker implements EngineContext, Agent private final ScalarsLayout gaugesLayout; private final HistogramsLayout histogramsLayout; private final EventsLayout eventsLayout; - private final Function[]> supplyEventSpies; + private final Supplier supplyEventReaders; private long initialId; private long promiseId; private long traceId; @@ -238,7 +237,7 @@ public EngineWorker( Collection models, Collection metricGroups, Collector collector, - Function[]> supplyEventSpies, + Supplier supplyEventReaders, int index, boolean readonly) { @@ -295,7 +294,6 @@ public EngineWorker( this.eventsLayout = new EventsLayout.Builder() .path(config.directory().resolve(String.format("events%d", index))) .capacity(config.eventsBufferCapacity()) - .readonly(readonly) .build(); this.agentName = String.format("engine/data#%d", index); @@ -420,7 +418,7 @@ public EngineWorker( this.idleStrategy = idleStrategy; this.errorHandler = errorHandler; this.exportersById = new Long2ObjectHashMap<>(); - this.supplyEventSpies = supplyEventSpies; + this.supplyEventReaders = supplyEventReaders; } public static int indexOfId( @@ -919,7 +917,7 @@ public LongConsumer supplyHistogramWriter( @Override public MessageConsumer logger() { - return this.eventsLayout.supplyWriter(); + return this.eventsLayout::writeEvent; } @Override @@ -1590,17 +1588,16 @@ public MessageConsumer supplyReceiver( return writersByIndex.computeIfAbsent(remoteIndex, supplyWriter); } - public Supplier supplyEventSpy( - SpyPosition position) + public int readEvent( + MessageConsumer handler, + int messageCountLimit) { - eventsLayout.spyAt(position); - return eventsLayout::bufferSpy; + return eventsLayout.readEvent(handler, messageCountLimit); } - public Supplier[] supplyEventSpies( - SpyPosition position) + public Supplier supplyEventReaders() { - return supplyEventSpies.apply(position); + return supplyEventReaders; } private MessageConsumer supplyWriter( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java index c47b99a52c..91f7156f93 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java @@ -31,8 +31,7 @@ import org.agrona.DirectBuffer; import org.agrona.concurrent.AtomicBuffer; -import io.aklivity.zilla.runtime.engine.binding.function.MessagePredicate; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; public class OneToOneRingBufferSpy implements RingBufferSpy { @@ -90,14 +89,14 @@ public long consumerPosition() @Override public int spy( - final MessagePredicate handler) + final MessageConsumer handler) { return spy(handler, Integer.MAX_VALUE); } @Override public int spy( - final MessagePredicate handler, + final MessageConsumer handler, final int messageCountLimit) { int messagesRead = 0; @@ -131,11 +130,7 @@ public int spy( } ++messagesRead; - if (!handler.test(messageTypeId, buffer, recordIndex + HEADER_LENGTH, recordLength - HEADER_LENGTH)) - { - bytesRead -= align(recordLength, ALIGNMENT); - break; - } + handler.accept(messageTypeId, buffer, recordIndex + HEADER_LENGTH, recordLength - HEADER_LENGTH); } } finally diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/RingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java similarity index 85% rename from runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/RingBufferSpy.java rename to runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java index 8271a04ec6..5d8f2630d1 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/spy/RingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java @@ -13,11 +13,11 @@ * License for the specific language governing permissions and limitations * under the License. */ -package io.aklivity.zilla.runtime.engine.spy; +package io.aklivity.zilla.runtime.engine.internal.spy; import org.agrona.DirectBuffer; -import io.aklivity.zilla.runtime.engine.binding.function.MessagePredicate; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; public interface RingBufferSpy { @@ -30,8 +30,8 @@ enum SpyPosition void spyAt(SpyPosition position); - int spy(MessagePredicate handler); - int spy(MessagePredicate handler, int messageCountLimit); + int spy(MessageConsumer handler); + int spy(MessageConsumer handler, int messageCountLimit); long producerPosition(); long consumerPosition(); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java new file mode 100644 index 0000000000..025fcfe7ce --- /dev/null +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java @@ -0,0 +1,25 @@ +/* + * Copyright 2021-2023 Aklivity Inc. + * + * Aklivity licenses this file to you 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.aklivity.zilla.runtime.engine.util.function; + +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; + +public interface EventReader +{ + int applyAsInt( + MessageConsumer handler, + int messageCountLimit); +} diff --git a/runtime/engine/src/main/moditect/module-info.java b/runtime/engine/src/main/moditect/module-info.java index 96bfdedb2f..4c15cb57b3 100644 --- a/runtime/engine/src/main/moditect/module-info.java +++ b/runtime/engine/src/main/moditect/module-info.java @@ -31,7 +31,6 @@ exports io.aklivity.zilla.runtime.engine.metrics.reader; exports io.aklivity.zilla.runtime.engine.reader; exports io.aklivity.zilla.runtime.engine.resolver; - exports io.aklivity.zilla.runtime.engine.spy; exports io.aklivity.zilla.runtime.engine.util.function; exports io.aklivity.zilla.runtime.engine.vault; diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java index b4061d2dd1..55014aaa91 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java @@ -25,48 +25,38 @@ import org.agrona.concurrent.UnsafeBuffer; import org.junit.Test; -import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.engine.spy.RingBufferSpy; - public class EventsLayoutTest { private static final Path EVENTS0_PATH = Paths.get("target/zilla-itests/events0"); + private static final int CAPACITY = 1024; private int msgTypeId; @Test - public void shouldSpy() + public void shouldWriteAndReadEvents() { // GIVEN - EventsLayout eventsWriter = new EventsLayout.Builder() - .path(EVENTS0_PATH) - .capacity(1024) - .readonly(false) - .build(); - MessageConsumer eventWriter = eventsWriter.supplyWriter(); - eventWriter.accept(42, new UnsafeBuffer(), 0, 0); - EventsLayout eventReader = new EventsLayout.Builder() + EventsLayout layout = new EventsLayout.Builder() .path(EVENTS0_PATH) - .readonly(true) + .capacity(CAPACITY) .build(); - eventReader.spyAt(RingBufferSpy.SpyPosition.ZERO); - RingBufferSpy spy = eventReader.bufferSpy(); + layout.writeEvent(42, new UnsafeBuffer(), 0, 0); msgTypeId = 0; // WHEN - spy.spy(this::readEvent); + int count = layout.readEvent(this::readEvent, 1); // THEN + assertThat(count, equalTo(1)); assertThat(msgTypeId, equalTo(42)); } - private boolean readEvent( + private void readEvent( int msgTypeId, DirectBuffer buffer, int index, int length) { this.msgTypeId = msgTypeId; - return true; } } From b7dfcd9a137396b0d426bb1daa6ef8114609b197 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 16:46:09 +0100 Subject: [PATCH 076/167] cleanup --- .../exporter/stdout/internal/stream/StdoutEventsStream.java | 2 -- .../exporter/stdout/internal/StdoutExporterHandlerTest.java | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index dde59ede8d..0889d0cbfe 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -43,8 +43,6 @@ public class StdoutEventsStream { private static final String HTTP_AUTHORIZATION_FORMAT = "%s: HTTP Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; - private static final String HTTP_ACCESS_DENIED = - "WARNING: HTTP Access Denied [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; private static final String KAFKA_AUTHORIZATION_FORMAT = "%s: Kafka Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; private static final String KAFKA_API_VERSION_REJECTED = diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index 812eb85bb3..0fb9a85156 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -46,7 +46,6 @@ public class StdoutExporterHandlerTest "[traceId = 0x0000000000000042] [binding = ns.binding] [address = address]\n"; @Test - @SuppressWarnings("unchecked") public void shouldStart() { // GIVEN @@ -78,9 +77,9 @@ public void shouldStart() // WHEN handler.start(); handler.export(); + handler.stop(); // THEN assertThat(os.toString(), equalTo(EXPECTED_OUTPUT)); - handler.stop(); } } From 7ef306dc2c13fea002010a140f20bbbd49d64ec0 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 17:48:28 +0100 Subject: [PATCH 077/167] fix EventHandler --- .../stdout/internal/stream/EventHandler.java | 66 ++++++ .../internal/stream/HttpEventHandler.java | 58 +++++ .../internal/stream/KafkaEventHandler.java | 71 ++++++ .../internal/stream/MqttEventHandler.java | 58 +++++ .../stream/SchemaRegistryEventHandler.java | 59 +++++ .../internal/stream/StdoutEventsStream.java | 207 ++---------------- .../internal/stream/TcpEventHandler.java | 57 +++++ .../internal/stream/TlsEventHandler.java | 57 +++++ 8 files changed, 444 insertions(+), 189 deletions(-) create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java new file mode 100644 index 0000000000..3613d733a5 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java @@ -0,0 +1,66 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; + +import java.io.PrintStream; +import java.util.function.LongFunction; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.Result; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.ResultFW; + +public abstract class EventHandler +{ + protected final LongFunction supplyNamespace; + protected final LongFunction supplyLocalName; + protected final PrintStream out; + + public EventHandler( + LongFunction supplyNamespace, + LongFunction supplyLocalName, + PrintStream out) + { + this.supplyNamespace = supplyNamespace; + this.supplyLocalName = supplyLocalName; + this.out = out; + } + + public abstract void handleEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length); + + protected static String asString( + StringFW stringFW) + { + String s = stringFW.asString(); + return s == null ? "" : s; + } + + protected static String level( + ResultFW result) + { + return result.get() == Result.SUCCESS ? "INFO" : "WARNING"; + } + + protected static String result( + ResultFW result) + { + return result.get() == Result.SUCCESS ? "Succeeded" : "Failed"; + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java new file mode 100644 index 0000000000..51b372af78 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; + +import java.io.PrintStream; +import java.util.function.LongFunction; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; + +public class HttpEventHandler extends EventHandler +{ + private static final String HTTP_AUTHORIZATION_FORMAT = + "%s: HTTP Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + + private final HttpEventFW httpEventRO = new HttpEventFW(); + + public HttpEventHandler( + LongFunction supplyNamespace, + LongFunction supplyLocalName, + PrintStream out) + { + super(supplyNamespace, supplyLocalName, out); + } + + public void handleEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + final HttpEventFW event = httpEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case AUTHORIZATION: + HttpAuthorizationEventFW e = event.authorization(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(HTTP_AUTHORIZATION_FORMAT, level(e.result()), result(e.result()), e.timestamp(), e.traceId(), namespace, + binding, asString(e.identity())); + break; + } + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java new file mode 100644 index 0000000000..7fbb7ff581 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -0,0 +1,71 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; + +import java.io.PrintStream; +import java.util.function.LongFunction; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaAuthorizationEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; + +public class KafkaEventHandler extends EventHandler +{ + private static final String KAFKA_AUTHORIZATION_FORMAT = + "%s: Kafka Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String KAFKA_API_VERSION_REJECTED = + "ERROR: Kafka API Version Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + + private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); + + public KafkaEventHandler( + LongFunction supplyNamespace, + LongFunction supplyLocalName, + PrintStream out) + { + super(supplyNamespace, supplyLocalName, out); + } + + public void handleEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + final KafkaEventFW event = kafkaEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case AUTHORIZATION: + { + KafkaAuthorizationEventFW e = event.authorization(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(KAFKA_AUTHORIZATION_FORMAT, level(e.result()), result(e.result()), e.timestamp(), e.traceId(), namespace, + binding); + break; + } + case API_VERSION_REJECTED: + { + EventFW e = event.apiVersionRejected(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(KAFKA_API_VERSION_REJECTED, e.timestamp(), e.traceId(), namespace, binding); + break; + } + } + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java new file mode 100644 index 0000000000..7c0433e7cf --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; + +import java.io.PrintStream; +import java.util.function.LongFunction; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; + +public class MqttEventHandler extends EventHandler +{ + private static final String MQTT_AUTHORIZATION_FORMAT = + "%s: MQTT Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + + private final MqttEventFW mqttEventRO = new MqttEventFW(); + + public MqttEventHandler( + LongFunction supplyNamespace, + LongFunction supplyLocalName, + PrintStream out) + { + super(supplyNamespace, supplyLocalName, out); + } + + public void handleEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + MqttEventFW event = mqttEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case AUTHORIZATION: + MqttAuthorizationEventFW e = event.authorization(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(MQTT_AUTHORIZATION_FORMAT, level(e.result()), result(e.result()), e.timestamp(), e.traceId(), namespace, + binding, asString(e.identity())); + break; + } + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java new file mode 100644 index 0000000000..21566c8497 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -0,0 +1,59 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; + +import java.io.PrintStream; +import java.util.function.LongFunction; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryRemoteAccessRejectedEventFW; + +public class SchemaRegistryEventHandler extends EventHandler +{ + private static final String SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED = + "ERROR: Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s]" + + "[method = %s] [status = %d]%n"; + + private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); + + public SchemaRegistryEventHandler( + LongFunction supplyNamespace, + LongFunction supplyLocalName, + PrintStream out) + { + super(supplyNamespace, supplyLocalName, out); + } + + public void handleEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + SchemaRegistryEventFW event = schemaRegistryEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case REMOTE_ACCESS_REJECTED: + SchemaRegistryRemoteAccessRejectedEventFW e = event.remoteAccessRejected(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED, e.timestamp(), e.traceId(), namespace, binding, asString(e.url()), + asString(e.method()), e.status()); + break; + } + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 0889d0cbfe..b965897ee6 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -23,52 +23,11 @@ import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; import io.aklivity.zilla.runtime.engine.util.function.EventReader; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaAuthorizationEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.Result; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryRemoteAccessRejectedEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpRemoteAccessFailedEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsFailedEventFW; public class StdoutEventsStream { - private static final String HTTP_AUTHORIZATION_FORMAT = - "%s: HTTP Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; - private static final String KAFKA_AUTHORIZATION_FORMAT = - "%s: Kafka Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; - private static final String KAFKA_API_VERSION_REJECTED = - "ERROR: Kafka API Version Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; - private static final String MQTT_AUTHORIZATION_FORMAT = - "%s: MQTT Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; - private static final String SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED = - "ERROR: Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s]" + - "[method = %s] [status = %d]%n"; - private static final String TCP_REMOTE_ACCESS_FAILED_FORMAT = - "ERROR: TCP Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; - private static final String TLS_FAILED_FORMAT = - "ERROR: TLS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [error = %s]%n"; - - private final HttpEventFW httpEventRO = new HttpEventFW(); - private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); - private final MqttEventFW mqttEventRO = new MqttEventFW(); - private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); - private final TcpEventFW tcpEventRO = new TcpEventFW(); - private final TlsEventFW tlsEventRO = new TlsEventFW(); - private final EventReader readEvent; - private final LongFunction supplyNamespace; - private final LongFunction supplyLocalName; private final ToIntFunction lookupLabelId; - private final PrintStream out; private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( @@ -79,21 +38,30 @@ public StdoutEventsStream( PrintStream out) { this.readEvent = readEvent; - this.supplyNamespace = supplyNamespace; - this.supplyLocalName = supplyLocalName; this.lookupLabelId = lookupLabelId; - this.out = out; + final HttpEventHandler httpEventHandler = new HttpEventHandler(supplyNamespace, supplyLocalName, out); + final KafkaEventHandler kafkaEventHandler = new KafkaEventHandler(supplyNamespace, supplyLocalName, out); + final MqttEventHandler mqttEventHandler = new MqttEventHandler(supplyNamespace, supplyLocalName, out); + final SchemaRegistryEventHandler schemaRegistryEventHandler = + new SchemaRegistryEventHandler(supplyNamespace, supplyLocalName, out); + final TcpEventHandler tcpEventHandler = new TcpEventHandler(supplyNamespace, supplyLocalName, out); + final TlsEventHandler tlsEventHandler = new TlsEventHandler(supplyNamespace, supplyLocalName, out); final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); - addEventHandler(eventHandlers, "http", this::handleHttpEvent); - addEventHandler(eventHandlers, "kafka", this::handleKafkaEvent); - addEventHandler(eventHandlers, "mqtt", this::handleMqttEvent); - addEventHandler(eventHandlers, "schema-registry", this::handleSchemaRegistryEvent); - addEventHandler(eventHandlers, "tcp", this::handleTcpEvent); - addEventHandler(eventHandlers, "tls", this::handleTlsEvent); + addEventHandler(eventHandlers, "http", httpEventHandler::handleEvent); + addEventHandler(eventHandlers, "kafka", kafkaEventHandler::handleEvent); + addEventHandler(eventHandlers, "mqtt", mqttEventHandler::handleEvent); + addEventHandler(eventHandlers, "schema-registry", schemaRegistryEventHandler::handleEvent); + addEventHandler(eventHandlers, "tcp", tcpEventHandler::handleEvent); + addEventHandler(eventHandlers, "tls", tlsEventHandler::handleEvent); this.eventHandlers = eventHandlers; } + public int process() + { + return readEvent.applyAsInt(this::handleEvent, 1); + } + private void addEventHandler( Int2ObjectHashMap eventHandlers, String type, @@ -106,11 +74,6 @@ private void addEventHandler( } } - public int process() - { - return readEvent.applyAsInt(this::handleEvent, 1); - } - private void handleEvent( int msgTypeId, DirectBuffer buffer, @@ -123,138 +86,4 @@ private void handleEvent( handler.accept(msgTypeId, buffer, index, length); } } - - private void handleHttpEvent( - int msgTypeId, - DirectBuffer buffer, - int index, - int length) - { - final HttpEventFW event = httpEventRO.wrap(buffer, index, index + length); - switch (event.kind()) - { - case AUTHORIZATION: - HttpAuthorizationEventFW e = event.authorization(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - String level = e.result().get() == Result.SUCCESS ? "INFO" : "WARNING"; - String result = e.result().get() == Result.SUCCESS ? "Succeeded" : "Failed"; - out.printf(HTTP_AUTHORIZATION_FORMAT, level, result, e.timestamp(), e.traceId(), namespace, binding, - asString(e.identity())); - break; - } - } - - private void handleKafkaEvent( - int msgTypeId, - DirectBuffer buffer, - int index, - int length) - { - final KafkaEventFW event = kafkaEventRO.wrap(buffer, index, index + length); - switch (event.kind()) - { - case AUTHORIZATION: - { - KafkaAuthorizationEventFW e = event.authorization(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - String level = e.result().get() == Result.SUCCESS ? "INFO" : "WARNING"; - String result = e.result().get() == Result.SUCCESS ? "Succeeded" : "Failed"; - out.printf(KAFKA_AUTHORIZATION_FORMAT, level, result, e.timestamp(), e.traceId(), namespace, binding); - break; - } - case API_VERSION_REJECTED: - { - EventFW e = event.apiVersionRejected(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_API_VERSION_REJECTED, e.timestamp(), e.traceId(), namespace, binding); - break; - } - } - } - - private void handleMqttEvent( - int msgTypeId, - DirectBuffer buffer, - int index, - int length) - { - MqttEventFW event = mqttEventRO.wrap(buffer, index, index + length); - switch (event.kind()) - { - case AUTHORIZATION: - MqttAuthorizationEventFW e = event.authorization(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - String level = e.result().get() == Result.SUCCESS ? "INFO" : "WARNING"; - String result = e.result().get() == Result.SUCCESS ? "Succeeded" : "Failed"; - out.printf(MQTT_AUTHORIZATION_FORMAT, level, result, e.timestamp(), e.traceId(), namespace, binding, - asString(e.identity())); - break; - } - } - - private void handleSchemaRegistryEvent( - int msgTypeId, - DirectBuffer buffer, - int index, - int length) - { - SchemaRegistryEventFW event = schemaRegistryEventRO.wrap(buffer, index, index + length); - switch (event.kind()) - { - case REMOTE_ACCESS_REJECTED: - SchemaRegistryRemoteAccessRejectedEventFW e = event.remoteAccessRejected(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED, e.timestamp(), e.traceId(), namespace, binding, asString(e.url()), - asString(e.method()), e.status()); - break; - } - } - - private void handleTcpEvent( - int msgTypeId, - DirectBuffer buffer, - int index, - int length) - { - final TcpEventFW event = tcpEventRO.wrap(buffer, index, index + length); - switch (event.kind()) - { - case REMOTE_ACCESS_FAILED: - TcpRemoteAccessFailedEventFW e = event.remoteAccessFailed(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.address())); - break; - } - } - - private void handleTlsEvent( - int msgTypeId, - DirectBuffer buffer, - int index, - int length) - { - TlsEventFW event = tlsEventRO.wrap(buffer, index, index + length); - switch (event.kind()) - { - case TLS_FAILED: - TlsFailedEventFW e = event.tlsFailed(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, e.error().get().name()); - break; - } - } - - private static String asString( - StringFW stringFW) - { - String s = stringFW.asString(); - return s == null ? "" : s; - } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java new file mode 100644 index 0000000000..ae05e4e110 --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -0,0 +1,57 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; + +import java.io.PrintStream; +import java.util.function.LongFunction; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpRemoteAccessFailedEventFW; + +public class TcpEventHandler extends EventHandler +{ + private static final String TCP_REMOTE_ACCESS_FAILED_FORMAT = + "ERROR: TCP Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; + + private final TcpEventFW tcpEventRO = new TcpEventFW(); + + public TcpEventHandler( + LongFunction supplyNamespace, + LongFunction supplyLocalName, + PrintStream out) + { + super(supplyNamespace, supplyLocalName, out); + } + + public void handleEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + final TcpEventFW event = tcpEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case REMOTE_ACCESS_FAILED: + TcpRemoteAccessFailedEventFW e = event.remoteAccessFailed(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.address())); + break; + } + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java new file mode 100644 index 0000000000..4a7f3f72ed --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -0,0 +1,57 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; + +import java.io.PrintStream; +import java.util.function.LongFunction; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsFailedEventFW; + +public class TlsEventHandler extends EventHandler +{ + private static final String TLS_FAILED_FORMAT = + "ERROR: TLS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [error = %s]%n"; + + private final TlsEventFW tlsEventRO = new TlsEventFW(); + + public TlsEventHandler( + LongFunction supplyNamespace, + LongFunction supplyLocalName, + PrintStream out) + { + super(supplyNamespace, supplyLocalName, out); + } + + public void handleEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + TlsEventFW event = tlsEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case TLS_FAILED: + TlsFailedEventFW e = event.tlsFailed(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(TLS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, e.error().get().name()); + break; + } + } +} From 4a5a7f6b75cf117e12355afa291df285eff04ffa Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 17:51:25 +0100 Subject: [PATCH 078/167] fix --- .../exporter/stdout/internal/stream/StdoutEventsStream.java | 2 +- .../zilla/runtime/engine/util/function/EventReader.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index b965897ee6..ff9c04196b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -59,7 +59,7 @@ public StdoutEventsStream( public int process() { - return readEvent.applyAsInt(this::handleEvent, 1); + return readEvent.read(this::handleEvent, 1); } private void addEventHandler( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java index 025fcfe7ce..79e03bb4fa 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java @@ -19,7 +19,7 @@ public interface EventReader { - int applyAsInt( + int read( MessageConsumer handler, int messageCountLimit); } From 633ed142080e096f116e3560ac683709d5905478 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 20:11:07 +0100 Subject: [PATCH 079/167] fix tcp --- .../internal/stream/TcpEventHandler.java | 12 ++++----- .../internal/StdoutExporterHandlerTest.java | 4 +-- .../binding/tcp/internal/TcpEventContext.java | 4 +-- .../tcp/internal/stream/TcpClientFactory.java | 25 +++++++++++++------ .../src/main/resources/META-INF/zilla/tcp.idl | 6 ++--- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index ae05e4e110..e9c886719b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -19,13 +19,13 @@ import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpDnsResolutionFailedEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpRemoteAccessFailedEventFW; public class TcpEventHandler extends EventHandler { - private static final String TCP_REMOTE_ACCESS_FAILED_FORMAT = - "ERROR: TCP Remote Access Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; + private static final String TCP_DNS_RESOLUTION_FAILED_FORMAT = + "ERROR: TCP DNS Resolution Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); @@ -46,11 +46,11 @@ public void handleEvent( final TcpEventFW event = tcpEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case REMOTE_ACCESS_FAILED: - TcpRemoteAccessFailedEventFW e = event.remoteAccessFailed(); + case DNS_RESOLUTION_FAILED: + TcpDnsResolutionFailedEventFW e = event.dnsResolutionFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TCP_REMOTE_ACCESS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.address())); + out.printf(TCP_DNS_RESOLUTION_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.address())); break; } } diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index 0fb9a85156..a16379dc19 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -42,7 +42,7 @@ public class StdoutExporterHandlerTest private static final Path EVENTS_PATH = ENGINE_PATH.resolve("events"); private static final int CAPACITY = 1024; private static final int TCP_TYPE_ID = 1; - private static final String EXPECTED_OUTPUT = "ERROR: TCP Remote Access Failed [timestamp = 77] " + + private static final String EXPECTED_OUTPUT = "ERROR: TCP DNS Resolution Failed [timestamp = 77] " + "[traceId = 0x0000000000000042] [binding = ns.binding] [address = address]\n"; @Test @@ -56,7 +56,7 @@ public void shouldStart() MutableDirectBuffer eventBuffer = new UnsafeBuffer(new byte[64]); TcpEventFW event = new TcpEventFW.Builder() .wrap(eventBuffer, 0, eventBuffer.capacity()) - .remoteAccessFailed(e -> e.timestamp(77) + .dnsResolutionFailed(e -> e.timestamp(77) .traceId(0x0000000000000042L) .namespacedId(0x0000000200000007L) .address("address") diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 792e0cb498..84d1b009c8 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -43,14 +43,14 @@ public TcpEventContext( this.timestamp = context.timestamp(); } - public void remoteAccessFailed( + public void dnsResolutionFailed( long traceId, long routedId, String address) { TcpEventFW event = tcpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .remoteAccessFailed(e -> e + .dnsResolutionFailed(e -> e .timestamp(timestamp.getAsLong()) .traceId(traceId) .namespacedId(routedId) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index c8d5b2b2ed..1641074084 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -271,9 +271,15 @@ private void doNetConnect( networkKey.register(OP_CONNECT); } } - catch (UnresolvedAddressException | IOException ex) + catch (UnresolvedAddressException ex) { - onNetRejected(remoteAddress); + String address = remoteAddress == null ? "" : remoteAddress.toString(); + event.dnsResolutionFailed(supplyTraceId.getAsLong(), routedId, address); + onNetRejected(); + } + catch (IOException ex) + { + onNetRejected(); } } @@ -286,9 +292,14 @@ private int onNetConnect( net.finishConnect(); onNetConnected(); } - catch (UnresolvedAddressException | IOException ex) + catch (UnresolvedAddressException ex) { - onNetRejected(null); + event.dnsResolutionFailed(supplyTraceId.getAsLong(), routedId, ""); + onNetRejected(); + } + catch (IOException ex) + { + onNetRejected(); } return 1; @@ -314,12 +325,10 @@ private void onNetConnected() } } - private void onNetRejected( - InetSocketAddress remoteAddress) + private void onNetRejected() { final long traceId = supplyTraceId.getAsLong(); - String address = remoteAddress == null ? null : remoteAddress.toString(); - event.remoteAccessFailed(traceId, routedId, address); + cleanup(traceId); } diff --git a/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl b/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl index e0eaa1efc4..1ed0fa2549 100644 --- a/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl +++ b/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl @@ -19,17 +19,17 @@ scope tcp { enum TcpEventType (uint8) { - REMOTE_ACCESS_FAILED (1) + DNS_RESOLUTION_FAILED (1) } - struct TcpRemoteAccessFailedEvent extends core::event::Event + struct TcpDnsResolutionFailedEvent extends core::event::Event { string16 address; } union TcpEvent switch (TcpEventType) { - case REMOTE_ACCESS_FAILED: TcpRemoteAccessFailedEvent remoteAccessFailed; + case DNS_RESOLUTION_FAILED: TcpDnsResolutionFailedEvent dnsResolutionFailed; } } } From 1289396c88cbc9fb934b3b788d74811a46b0c472 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 13 Feb 2024 21:16:19 +0100 Subject: [PATCH 080/167] fix --- runtime/binding-tcp/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/binding-tcp/pom.xml b/runtime/binding-tcp/pom.xml index 6753ca7a65..513e5eae6b 100644 --- a/runtime/binding-tcp/pom.xml +++ b/runtime/binding-tcp/pom.xml @@ -26,7 +26,7 @@ 11 11 - 0.89 + 0.88 0 From c47719fd21d7d6a6a1fc04d894dbdff39a25d7b2 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 14 Feb 2024 17:37:59 +0100 Subject: [PATCH 081/167] fix --- .../exporter/stdout/internal/StdoutExporterHandler.java | 1 + .../runtime/engine/internal/layouts/EventsLayoutTest.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index d8f511afcc..16eb46c816 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -66,6 +66,7 @@ public int export() @Override public void stop() { + this.stdoutEventStreams = null; } private StdoutEventsStream newStdoutEventsStream( diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java index 55014aaa91..a0aeda974b 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayoutTest.java @@ -27,7 +27,7 @@ public class EventsLayoutTest { - private static final Path EVENTS0_PATH = Paths.get("target/zilla-itests/events0"); + private static final Path PATH = Paths.get("target/zilla-itests/events0"); private static final int CAPACITY = 1024; private int msgTypeId; @@ -37,7 +37,7 @@ public void shouldWriteAndReadEvents() { // GIVEN EventsLayout layout = new EventsLayout.Builder() - .path(EVENTS0_PATH) + .path(PATH) .capacity(CAPACITY) .build(); layout.writeEvent(42, new UnsafeBuffer(), 0, 0); From ed04985e8bd318f89aa0164479cb7fcca979b1d4 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 15 Feb 2024 12:32:02 +0100 Subject: [PATCH 082/167] WIP RingBufferSpy --- .../engine/internal/layouts/EventsLayout.java | 5 +- .../internal/spy/OneToOneRingBufferSpy.java | 56 ++----------------- .../engine/internal/spy/RingBufferSpy.java | 16 ------ 3 files changed, 6 insertions(+), 71 deletions(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index 4e49a815e4..f31ff2f95a 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -15,7 +15,6 @@ */ package io.aklivity.zilla.runtime.engine.internal.layouts; -import static io.aklivity.zilla.runtime.engine.internal.spy.RingBufferSpy.SpyPosition.ZERO; import static org.agrona.IoUtil.createEmptyFile; import static org.agrona.IoUtil.mapExistingFile; import static org.agrona.IoUtil.unmap; @@ -133,9 +132,7 @@ private static RingBufferSpy createRingBufferSpy( Path path) { AtomicBuffer atomicBuffer = createAtomicBuffer(path, 0, false); - OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); - spy.spyAt(ZERO); - return spy; + return new OneToOneRingBufferSpy(atomicBuffer); } public static final class Builder diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java index 91f7156f93..0ac34ffc09 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java @@ -21,14 +21,9 @@ import static org.agrona.concurrent.ringbuffer.RecordDescriptor.lengthOffset; import static org.agrona.concurrent.ringbuffer.RecordDescriptor.typeOffset; import static org.agrona.concurrent.ringbuffer.RingBuffer.PADDING_MSG_TYPE_ID; -import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.HEAD_POSITION_OFFSET; -import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.TAIL_POSITION_OFFSET; import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.TRAILER_LENGTH; import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.checkCapacity; -import java.util.concurrent.atomic.AtomicLong; - -import org.agrona.DirectBuffer; import org.agrona.concurrent.AtomicBuffer; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -36,55 +31,18 @@ public class OneToOneRingBufferSpy implements RingBufferSpy { private final int capacity; - private final AtomicLong spyPosition; private final AtomicBuffer buffer; + private int spyPosition; + public OneToOneRingBufferSpy( final AtomicBuffer buffer) { this.buffer = buffer; checkCapacity(buffer.capacity()); capacity = buffer.capacity() - TRAILER_LENGTH; - buffer.verifyAlignment(); - - spyPosition = new AtomicLong(); - } - - @Override - public void spyAt( - SpyPosition position) - { - switch (position) - { - case ZERO: - spyPosition.lazySet(0); - break; - case HEAD: - spyPosition.lazySet(buffer.getLong(capacity + HEAD_POSITION_OFFSET)); - break; - case TAIL: - spyPosition.lazySet(buffer.getLong(capacity + TAIL_POSITION_OFFSET)); - break; - } - } - - @Override - public DirectBuffer buffer() - { - return buffer; - } - - @Override - public long producerPosition() - { - return buffer.getLong(buffer.capacity() - TRAILER_LENGTH + TAIL_POSITION_OFFSET); - } - - @Override - public long consumerPosition() - { - return buffer.getLong(buffer.capacity() - TRAILER_LENGTH + HEAD_POSITION_OFFSET); + spyPosition = 0; } @Override @@ -100,14 +58,10 @@ public int spy( final int messageCountLimit) { int messagesRead = 0; - - final AtomicBuffer buffer = this.buffer; - final long head = spyPosition.get(); - int bytesRead = 0; final int capacity = this.capacity; - final int headIndex = (int)head & (capacity - 1); + final int headIndex = spyPosition & (capacity - 1); final int contiguousBlockLength = capacity - headIndex; try @@ -137,7 +91,7 @@ public int spy( { if (bytesRead != 0) { - spyPosition.lazySet(head + bytesRead); + spyPosition += bytesRead; } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java index 5d8f2630d1..420273b511 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java @@ -15,26 +15,10 @@ */ package io.aklivity.zilla.runtime.engine.internal.spy; -import org.agrona.DirectBuffer; - import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; public interface RingBufferSpy { - enum SpyPosition - { - ZERO, - HEAD, - TAIL - } - - void spyAt(SpyPosition position); - int spy(MessageConsumer handler); int spy(MessageConsumer handler, int messageCountLimit); - - long producerPosition(); - long consumerPosition(); - - DirectBuffer buffer(); } From db2cf892c7d423ea9152c733bef646e2bf98d197 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 16 Feb 2024 14:56:33 +0100 Subject: [PATCH 083/167] Revert "WIP RingBufferSpy" This reverts commit ed04985e8bd318f89aa0164479cb7fcca979b1d4. --- .../engine/internal/layouts/EventsLayout.java | 5 +- .../internal/spy/OneToOneRingBufferSpy.java | 56 +++++++++++++++++-- .../engine/internal/spy/RingBufferSpy.java | 16 ++++++ 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index f31ff2f95a..4e49a815e4 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -15,6 +15,7 @@ */ package io.aklivity.zilla.runtime.engine.internal.layouts; +import static io.aklivity.zilla.runtime.engine.internal.spy.RingBufferSpy.SpyPosition.ZERO; import static org.agrona.IoUtil.createEmptyFile; import static org.agrona.IoUtil.mapExistingFile; import static org.agrona.IoUtil.unmap; @@ -132,7 +133,9 @@ private static RingBufferSpy createRingBufferSpy( Path path) { AtomicBuffer atomicBuffer = createAtomicBuffer(path, 0, false); - return new OneToOneRingBufferSpy(atomicBuffer); + OneToOneRingBufferSpy spy = new OneToOneRingBufferSpy(atomicBuffer); + spy.spyAt(ZERO); + return spy; } public static final class Builder diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java index 0ac34ffc09..91f7156f93 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java @@ -21,9 +21,14 @@ import static org.agrona.concurrent.ringbuffer.RecordDescriptor.lengthOffset; import static org.agrona.concurrent.ringbuffer.RecordDescriptor.typeOffset; import static org.agrona.concurrent.ringbuffer.RingBuffer.PADDING_MSG_TYPE_ID; +import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.HEAD_POSITION_OFFSET; +import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.TAIL_POSITION_OFFSET; import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.TRAILER_LENGTH; import static org.agrona.concurrent.ringbuffer.RingBufferDescriptor.checkCapacity; +import java.util.concurrent.atomic.AtomicLong; + +import org.agrona.DirectBuffer; import org.agrona.concurrent.AtomicBuffer; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -31,18 +36,55 @@ public class OneToOneRingBufferSpy implements RingBufferSpy { private final int capacity; + private final AtomicLong spyPosition; private final AtomicBuffer buffer; - private int spyPosition; - public OneToOneRingBufferSpy( final AtomicBuffer buffer) { this.buffer = buffer; checkCapacity(buffer.capacity()); capacity = buffer.capacity() - TRAILER_LENGTH; + buffer.verifyAlignment(); - spyPosition = 0; + + spyPosition = new AtomicLong(); + } + + @Override + public void spyAt( + SpyPosition position) + { + switch (position) + { + case ZERO: + spyPosition.lazySet(0); + break; + case HEAD: + spyPosition.lazySet(buffer.getLong(capacity + HEAD_POSITION_OFFSET)); + break; + case TAIL: + spyPosition.lazySet(buffer.getLong(capacity + TAIL_POSITION_OFFSET)); + break; + } + } + + @Override + public DirectBuffer buffer() + { + return buffer; + } + + @Override + public long producerPosition() + { + return buffer.getLong(buffer.capacity() - TRAILER_LENGTH + TAIL_POSITION_OFFSET); + } + + @Override + public long consumerPosition() + { + return buffer.getLong(buffer.capacity() - TRAILER_LENGTH + HEAD_POSITION_OFFSET); } @Override @@ -58,10 +100,14 @@ public int spy( final int messageCountLimit) { int messagesRead = 0; + + final AtomicBuffer buffer = this.buffer; + final long head = spyPosition.get(); + int bytesRead = 0; final int capacity = this.capacity; - final int headIndex = spyPosition & (capacity - 1); + final int headIndex = (int)head & (capacity - 1); final int contiguousBlockLength = capacity - headIndex; try @@ -91,7 +137,7 @@ public int spy( { if (bytesRead != 0) { - spyPosition += bytesRead; + spyPosition.lazySet(head + bytesRead); } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java index 420273b511..5d8f2630d1 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java @@ -15,10 +15,26 @@ */ package io.aklivity.zilla.runtime.engine.internal.spy; +import org.agrona.DirectBuffer; + import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; public interface RingBufferSpy { + enum SpyPosition + { + ZERO, + HEAD, + TAIL + } + + void spyAt(SpyPosition position); + int spy(MessageConsumer handler); int spy(MessageConsumer handler, int messageCountLimit); + + long producerPosition(); + long consumerPosition(); + + DirectBuffer buffer(); } From 6b74346ab1b18811fb611a10aa3d4d800d040ebc Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 15 Feb 2024 16:45:13 +0100 Subject: [PATCH 084/167] WIP eventReadingQueue --- .../internal/StdoutExporterHandler.java | 28 ++------ .../internal/StdoutExporterHandlerTest.java | 3 +- .../aklivity/zilla/runtime/engine/Engine.java | 66 +++++++++++++++++-- .../zilla/runtime/engine/EngineContext.java | 2 +- .../internal/registry/EngineWorker.java | 10 +-- 5 files changed, 72 insertions(+), 37 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 16eb46c816..66e86b54b6 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -15,12 +15,10 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal; import java.io.PrintStream; -import java.util.Arrays; import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; -import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; import io.aklivity.zilla.runtime.exporter.stdout.internal.stream.StdoutEventsStream; @@ -29,7 +27,7 @@ public class StdoutExporterHandler implements ExporterHandler private final EngineContext context; private final PrintStream out; - private StdoutEventsStream[] stdoutEventStreams; + private StdoutEventsStream stdoutEventsStream; public StdoutExporterHandler( EngineConfiguration config, @@ -44,35 +42,19 @@ public StdoutExporterHandler( @Override public void start() { - this.stdoutEventStreams = Arrays.stream(context.supplyEventReaders().get()) - .map(this::newStdoutEventsStream) - .toArray(StdoutEventsStream[]::new); + stdoutEventsStream = new StdoutEventsStream(context.supplyEventReader().get(), context::supplyNamespace, + context::supplyLocalName, context::lookupLabelId, out); } @Override public int export() { - int workCount = 0; - if (stdoutEventStreams != null) - { - for (int i = 0; i < stdoutEventStreams.length; i++) - { - workCount += stdoutEventStreams[i].process(); - } - } - return workCount; + return stdoutEventsStream.process(); } @Override public void stop() { - this.stdoutEventStreams = null; - } - - private StdoutEventsStream newStdoutEventsStream( - EventReader eventReader) - { - return new StdoutEventsStream(eventReader, context::supplyNamespace, context::supplyLocalName, - context::lookupLabelId, out); + this.stdoutEventsStream = null; } } diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index a16379dc19..5156f24ab0 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -32,7 +32,6 @@ import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.config.ExporterConfig; import io.aklivity.zilla.runtime.engine.internal.layouts.EventsLayout; -import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; @@ -71,7 +70,7 @@ public void shouldStart() when(context.lookupLabelId("tcp")).thenReturn(TCP_TYPE_ID); when(context.supplyNamespace(0x0000000200000007L)).thenReturn("ns"); when(context.supplyLocalName(0x0000000200000007L)).thenReturn("binding"); - when(context.supplyEventReaders()).thenReturn(() -> new EventReader[]{layout::readEvent}); + when(context.supplyEventReader()).thenReturn(() -> layout::readEvent); StdoutExporterHandler handler = new StdoutExporterHandler(config, context, exporter, ps); // WHEN diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index 119bd0e568..ce059c00ca 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -33,9 +33,11 @@ import java.net.http.HttpResponse; import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.PriorityQueue; import java.util.ServiceLoader; import java.util.ServiceLoader.Provider; import java.util.concurrent.ExecutorService; @@ -53,10 +55,13 @@ import org.agrona.CloseHelper; import org.agrona.ErrorHandler; +import org.agrona.MutableDirectBuffer; import org.agrona.collections.Int2ObjectHashMap; import org.agrona.concurrent.AgentRunner; +import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.engine.binding.Binding; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; import io.aklivity.zilla.runtime.engine.catalog.Catalog; import io.aklivity.zilla.runtime.engine.config.KindConfig; import io.aklivity.zilla.runtime.engine.exporter.Exporter; @@ -71,6 +76,7 @@ import io.aklivity.zilla.runtime.engine.internal.registry.FileWatcherTask; import io.aklivity.zilla.runtime.engine.internal.registry.HttpWatcherTask; import io.aklivity.zilla.runtime.engine.internal.registry.WatcherTask; +import io.aklivity.zilla.runtime.engine.internal.types.event.EventFW; import io.aklivity.zilla.runtime.engine.metrics.Collector; import io.aklivity.zilla.runtime.engine.metrics.MetricGroup; import io.aklivity.zilla.runtime.engine.model.Model; @@ -97,6 +103,9 @@ public final class Engine implements Collector, AutoCloseable private final EngineConfiguration config; private Future watcherTaskRef; + private final PriorityQueue eventReadingQueue; + private final EventFW eventRO = new EventFW(); + Engine( EngineConfiguration config, Collection bindings, @@ -161,7 +170,7 @@ public final class Engine implements Collector, AutoCloseable EngineWorker worker = new EngineWorker(config, tasks, labels, errorHandler, tuning::affinity, bindings, exporters, guards, vaults, catalogs, models, metricGroups, - this, this::supplyEventReaders, coreIndex, readonly); + this, this::supplyEventReader, coreIndex, readonly); workers.add(worker); } this.workers = workers; @@ -216,6 +225,7 @@ else if ("http".equals(protocol) || "https".equals(protocol)) this.context = context; this.runners = runners; this.readonly = readonly; + this.eventReadingQueue = new PriorityQueue<>(Comparator.comparing(EventRecord::timestamp)); } public T binding( @@ -482,14 +492,36 @@ public long[][] histogramIds() return worker.histogramIds(); } - public EventReader[] supplyEventReaders() + public int readEvent( + MessageConsumer handler, + int messageCountLimit) { - EventReader[] readers = new EventReader[workers.size()]; - for (int i = 0; i < workers.size(); i++) + int messagesRead = 0; + boolean queueEmpty = false; + while (!queueEmpty && messagesRead < messageCountLimit) { - readers[i] = workers.get(i)::readEvent; + for (EngineWorker worker : workers) + { + worker.readEvent((m, b, i, l) -> + { + eventRO.wrap(b, i, i + l); + eventReadingQueue.add(new EventRecord(m, eventRO.timestamp(), new UnsafeBuffer(b, i, i + l))); + }, 1); + } + queueEmpty = eventReadingQueue.isEmpty(); + if (!queueEmpty) + { + EventRecord event = eventReadingQueue.poll(); + handler.accept(event.msgTypeId, event.buffer, 0, event.buffer.capacity()); + messagesRead++; + } } - return readers; + return messagesRead; + } + + public EventReader supplyEventReader() + { + return this::readEvent; } public String supplyLocalName( @@ -506,6 +538,28 @@ public int supplyLabelId( return worker.supplyTypeId(label); } + private static final class EventRecord + { + public int msgTypeId; + public long timestamp; + public MutableDirectBuffer buffer; + + private EventRecord( + int msgTypeId, + long timestamp, + MutableDirectBuffer buffer) + { + this.msgTypeId = msgTypeId; + this.timestamp = timestamp; + this.buffer = buffer; + } + + public long timestamp() + { + return timestamp; + } + } + // visible for testing public final class ContextImpl implements EngineExtContext { diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index f9b4045135..51629193de 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -72,7 +72,7 @@ int readEvent( MessageConsumer handler, int messageCountLimit); - Supplier supplyEventReaders(); + Supplier supplyEventReader(); MessageConsumer supplySender( long streamId); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index c5fe1e2bc4..1c61f471d8 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -214,7 +214,7 @@ public class EngineWorker implements EngineContext, Agent private final ScalarsLayout gaugesLayout; private final HistogramsLayout histogramsLayout; private final EventsLayout eventsLayout; - private final Supplier supplyEventReaders; + private final Supplier supplyEventReader; private long initialId; private long promiseId; private long traceId; @@ -237,7 +237,7 @@ public EngineWorker( Collection models, Collection metricGroups, Collector collector, - Supplier supplyEventReaders, + Supplier supplyEventReader, int index, boolean readonly) { @@ -418,7 +418,7 @@ public EngineWorker( this.idleStrategy = idleStrategy; this.errorHandler = errorHandler; this.exportersById = new Long2ObjectHashMap<>(); - this.supplyEventReaders = supplyEventReaders; + this.supplyEventReader = supplyEventReader; } public static int indexOfId( @@ -1595,9 +1595,9 @@ public int readEvent( return eventsLayout.readEvent(handler, messageCountLimit); } - public Supplier supplyEventReaders() + public Supplier supplyEventReader() { - return supplyEventReaders; + return supplyEventReader; } private MessageConsumer supplyWriter( From 29d06f37b2c04d6f065b057062ffe7014fbf110a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 16 Feb 2024 16:09:55 +0100 Subject: [PATCH 085/167] WIP sortEventIndicesByTimestamps --- .../aklivity/zilla/runtime/engine/Engine.java | 59 ++++++++++++++----- .../engine/internal/layouts/EventsLayout.java | 6 ++ .../internal/registry/EngineWorker.java | 6 ++ .../internal/spy/OneToOneRingBufferSpy.java | 21 +++++++ .../engine/internal/spy/RingBufferSpy.java | 1 + .../runtime/engine/internal/EngineTest.java | 57 ++++++++++++++++++ 6 files changed, 134 insertions(+), 16 deletions(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index ce059c00ca..edec4ce157 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -33,11 +33,9 @@ import java.net.http.HttpResponse; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.PriorityQueue; import java.util.ServiceLoader; import java.util.ServiceLoader.Provider; import java.util.concurrent.ExecutorService; @@ -58,7 +56,6 @@ import org.agrona.MutableDirectBuffer; import org.agrona.collections.Int2ObjectHashMap; import org.agrona.concurrent.AgentRunner; -import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.engine.binding.Binding; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -103,8 +100,9 @@ public final class Engine implements Collector, AutoCloseable private final EngineConfiguration config; private Future watcherTaskRef; - private final PriorityQueue eventReadingQueue; private final EventFW eventRO = new EventFW(); + private final int[] eventIndices; + private final long[] eventTimestamps; Engine( EngineConfiguration config, @@ -225,7 +223,8 @@ else if ("http".equals(protocol) || "https".equals(protocol)) this.context = context; this.runners = runners; this.readonly = readonly; - this.eventReadingQueue = new PriorityQueue<>(Comparator.comparing(EventRecord::timestamp)); + this.eventIndices = new int[workerCount]; + this.eventTimestamps = new long[workerCount]; } public T binding( @@ -497,28 +496,56 @@ public int readEvent( int messageCountLimit) { int messagesRead = 0; - boolean queueEmpty = false; - while (!queueEmpty && messagesRead < messageCountLimit) + boolean empty = false; + while (!empty && messagesRead < messageCountLimit) { - for (EngineWorker worker : workers) + int eventCount = 0; + for (int j = 0; j < workers.size(); j++) { - worker.readEvent((m, b, i, l) -> + final int workerIndex = j; + final int eventIndex = eventCount; + int eventsPeeked = workers.get(workerIndex).peekEvent((m, b, i, l) -> { eventRO.wrap(b, i, i + l); - eventReadingQueue.add(new EventRecord(m, eventRO.timestamp(), new UnsafeBuffer(b, i, i + l))); - }, 1); + eventIndices[eventIndex] = workerIndex; + eventTimestamps[eventIndex] = eventRO.timestamp(); + }); + eventCount += eventsPeeked; } - queueEmpty = eventReadingQueue.isEmpty(); - if (!queueEmpty) + sortEventIndicesByTimestamps(eventIndices, eventTimestamps); + for (int i = 0; i < eventCount && messagesRead < messageCountLimit; i++) { - EventRecord event = eventReadingQueue.poll(); - handler.accept(event.msgTypeId, event.buffer, 0, event.buffer.capacity()); - messagesRead++; + EngineWorker worker = workers.get(eventIndices[i]); + messagesRead += worker.readEvent(handler, 1); } + empty = eventCount == 0; } return messagesRead; } + // visible for testing + public static void sortEventIndicesByTimestamps( + int[] indices, + long[] timestamps) + { + int i, j, index; + long timestamp; + for (i = 1; i < indices.length; i++) + { + index = indices[i]; + timestamp = timestamps[i]; + j = i - 1; + while (j >= 0 && timestamps[j] > timestamp) + { + indices[j + 1] = indices[j]; + timestamps[j + 1] = timestamps[j]; + j = j - 1; + } + indices[j + 1] = index; + timestamps[j + 1] = timestamp; + } + } + public EventReader supplyEventReader() { return this::readEvent; diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java index 4e49a815e4..ee3670f16b 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/layouts/EventsLayout.java @@ -89,6 +89,12 @@ public int readEvent( return bufferSpy.spy(handler, messageCountLimit); } + public int peekEvent( + MessageConsumer handler) + { + return bufferSpy.peek(handler); + } + private void rotateFile() { close(); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 1c61f471d8..9b8703d5cf 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -1595,6 +1595,12 @@ public int readEvent( return eventsLayout.readEvent(handler, messageCountLimit); } + public int peekEvent( + MessageConsumer handler) + { + return eventsLayout.peekEvent(handler); + } + public Supplier supplyEventReader() { return supplyEventReader; diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java index 91f7156f93..4104b505ff 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/OneToOneRingBufferSpy.java @@ -143,4 +143,25 @@ public int spy( return messagesRead; } + + public int peek( + final MessageConsumer handler) + { + final AtomicBuffer buffer = this.buffer; + final long head = spyPosition.get(); + final int capacity = this.capacity; + final int headIndex = (int)head & (capacity - 1); + final int recordLength = buffer.getIntVolatile(lengthOffset(headIndex)); + int messagesPeeked = 0; + if (recordLength > 0) + { + final int messageTypeId = buffer.getInt(typeOffset(headIndex)); + if (PADDING_MSG_TYPE_ID != messageTypeId) + { + handler.accept(messageTypeId, buffer, headIndex + HEADER_LENGTH, recordLength - HEADER_LENGTH); + messagesPeeked = 1; + } + } + return messagesPeeked; + } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java index 5d8f2630d1..a863b76d1e 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/spy/RingBufferSpy.java @@ -32,6 +32,7 @@ enum SpyPosition int spy(MessageConsumer handler); int spy(MessageConsumer handler, int messageCountLimit); + int peek(MessageConsumer handler); long producerPosition(); long consumerPosition(); diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java index 711dca56e2..de33ad9f31 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java @@ -20,6 +20,7 @@ import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_WORKERS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertTrue; @@ -250,6 +251,62 @@ public void shouldNotConfigureUnknownScheme() throws Exception } } + @Test + public void shouldSortEventIndicesByTimestampSimpleCase() + { + // GIVEN + int[] eventIndices = new int[]{1, 2, 3}; + long[] eventTimestamps = new long[]{1L, 2L, 3L}; + + // WHEN + Engine.sortEventIndicesByTimestamps(eventIndices, eventTimestamps); + + // THEN + assertThat(eventIndices, equalTo(new int[]{1, 2, 3})); + } + + @Test + public void shouldSortEventIndicesByTimestampGenericCase() + { + // GIVEN + int[] eventIndices = new int[]{1, 5, 2, 7, 9, 8}; + long[] eventTimestamps = new long[]{8L, 1L, 9L, 4L, 3L, 42L}; + + // WHEN + Engine.sortEventIndicesByTimestamps(eventIndices, eventTimestamps); + + // THEN + assertThat(eventIndices, equalTo(new int[]{5, 9, 7, 1, 2, 8})); + } + + @Test + public void shouldSortEventIndicesByTimestampOne() + { + // GIVEN + int[] eventIndices = new int[]{3}; + long[] eventTimestamps = new long[]{7777L}; + + // WHEN + Engine.sortEventIndicesByTimestamps(eventIndices, eventTimestamps); + + // THEN + assertThat(eventIndices, equalTo(new int[]{3})); + } + + @Test + public void shouldSortEventIndicesByTimestampEmpty() + { + // GIVEN + int[] eventIndices = new int[]{}; + long[] eventTimestamps = new long[]{}; + + // WHEN + Engine.sortEventIndicesByTimestamps(eventIndices, eventTimestamps); + + // THEN + assertThat(eventIndices, equalTo(new int[]{})); + } + public static final class TestEngineExt implements EngineExtSpi { public static volatile CountDownLatch registerLatch = new CountDownLatch(1); From 5740eadb84cca4a9b485d8ea13c6acd70f58b3c7 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Fri, 16 Feb 2024 17:04:16 +0100 Subject: [PATCH 086/167] test stdout --- incubator/exporter-stdout/pom.xml | 2 +- .../stream/SchemaRegistryEventHandler.java | 2 +- .../internal/StdoutExporterHandlerTest.java | 94 +++++++++++++++++-- 3 files changed, 90 insertions(+), 8 deletions(-) diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 45a7da2d73..4194b774b3 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,7 +26,7 @@ 11 11 - 0.40 + 0.90 0 diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index 21566c8497..011f3296a4 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -25,7 +25,7 @@ public class SchemaRegistryEventHandler extends EventHandler { private static final String SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED = - "ERROR: Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s]" + + "ERROR: Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s] " + "[method = %s] [status = %d]%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index 5156f24ab0..3c7ec8cb39 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -33,16 +33,38 @@ import io.aklivity.zilla.runtime.engine.config.ExporterConfig; import io.aklivity.zilla.runtime.engine.internal.layouts.EventsLayout; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.Result; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsError; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; public class StdoutExporterHandlerTest { private static final Path ENGINE_PATH = Paths.get("target/zilla-itests"); private static final Path EVENTS_PATH = ENGINE_PATH.resolve("events"); private static final int CAPACITY = 1024; - private static final int TCP_TYPE_ID = 1; - private static final String EXPECTED_OUTPUT = "ERROR: TCP DNS Resolution Failed [timestamp = 77] " + - "[traceId = 0x0000000000000042] [binding = ns.binding] [address = address]\n"; + private static final int HTTP_TYPE_ID = 1; + private static final int KAFKA_TYPE_ID = 2; + private static final int MQTT_TYPE_ID = 3; + private static final int SCHEMA_REGISTRY_TYPE_ID = 4; + private static final int TCP_TYPE_ID = 5; + private static final int TLS_TYPE_ID = 6; + private static final String EXPECTED_OUTPUT = + "WARNING: HTTP Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "[identity = identity]\n" + + "WARNING: Kafka Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + + "ERROR: Kafka API Version Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + + "WARNING: MQTT Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "[identity = identity]\n" + + "ERROR: Schema Registry Remote Access Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "[url = url] [method = method] [status = 42]\n" + + "ERROR: TCP DNS Resolution Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "[address = address]\n" + + "ERROR: TLS Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] [error = HANDSHAKE_ERROR]\n"; @Test public void shouldStart() @@ -53,21 +75,78 @@ public void shouldStart() .capacity(CAPACITY) .build(); MutableDirectBuffer eventBuffer = new UnsafeBuffer(new byte[64]); - TcpEventFW event = new TcpEventFW.Builder() + HttpEventFW httpAuthorizationEvent = new HttpEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorization(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + .result(r -> r.set(Result.FAILURE)) + .identity("identity") + ).build(); + layout.writeEvent(HTTP_TYPE_ID, httpAuthorizationEvent.buffer(), 0, httpAuthorizationEvent.sizeof()); + KafkaEventFW kafkaAuthorizationEvent = new KafkaEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorization(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + .result(r -> r.set(Result.FAILURE)) + ).build(); + layout.writeEvent(KAFKA_TYPE_ID, kafkaAuthorizationEvent.buffer(), 0, kafkaAuthorizationEvent.sizeof()); + KafkaEventFW kafkaApiVersionRejectedEvent = new KafkaEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .apiVersionRejected(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + ).build(); + layout.writeEvent(KAFKA_TYPE_ID, kafkaApiVersionRejectedEvent.buffer(), 0, kafkaApiVersionRejectedEvent.sizeof()); + MqttEventFW mqttAuthorizationEvent = new MqttEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorization(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + .result(r -> r.set(Result.FAILURE)) + .identity("identity") + ).build(); + layout.writeEvent(MQTT_TYPE_ID, mqttAuthorizationEvent.buffer(), 0, mqttAuthorizationEvent.sizeof()); + SchemaRegistryEventFW schemaRegistryAuthorizationEvent = new SchemaRegistryEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .remoteAccessRejected(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + .url("url") + .method("method") + .status((short) 42) + ).build(); + layout.writeEvent(SCHEMA_REGISTRY_TYPE_ID, schemaRegistryAuthorizationEvent.buffer(), 0, + schemaRegistryAuthorizationEvent.sizeof()); + TcpEventFW tcpDnsResolutionFailedEvent = new TcpEventFW.Builder() .wrap(eventBuffer, 0, eventBuffer.capacity()) .dnsResolutionFailed(e -> e.timestamp(77) .traceId(0x0000000000000042L) .namespacedId(0x0000000200000007L) .address("address") ).build(); - layout.writeEvent(TCP_TYPE_ID, event.buffer(), 0, event.sizeof()); + layout.writeEvent(TCP_TYPE_ID, tcpDnsResolutionFailedEvent.buffer(), 0, tcpDnsResolutionFailedEvent.sizeof()); + TlsEventFW tlsFailedEvent = new TlsEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .tlsFailed(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + .error(t -> t.set(TlsError.HANDSHAKE_ERROR)) + ).build(); + layout.writeEvent(TLS_TYPE_ID, tlsFailedEvent.buffer(), 0, tlsFailedEvent.sizeof()); EngineConfiguration config = mock(EngineConfiguration.class); EngineContext context = mock(EngineContext.class); StdoutExporterConfig exporter = new StdoutExporterConfig(mock(ExporterConfig.class)); ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); + when(context.lookupLabelId("http")).thenReturn(HTTP_TYPE_ID); + when(context.lookupLabelId("kafka")).thenReturn(KAFKA_TYPE_ID); + when(context.lookupLabelId("mqtt")).thenReturn(MQTT_TYPE_ID); + when(context.lookupLabelId("schema-registry")).thenReturn(SCHEMA_REGISTRY_TYPE_ID); when(context.lookupLabelId("tcp")).thenReturn(TCP_TYPE_ID); + when(context.lookupLabelId("tls")).thenReturn(TLS_TYPE_ID); when(context.supplyNamespace(0x0000000200000007L)).thenReturn("ns"); when(context.supplyLocalName(0x0000000200000007L)).thenReturn("binding"); when(context.supplyEventReader()).thenReturn(() -> layout::readEvent); @@ -75,7 +154,10 @@ public void shouldStart() // WHEN handler.start(); - handler.export(); + for (int i = 0; i < 42; i++) + { + handler.export(); + } handler.stop(); // THEN From 0acc7f4e087035ea80155d8e442ff76d723c69d7 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 19 Feb 2024 16:12:04 +0100 Subject: [PATCH 087/167] fix Engine readEvent --- .../aklivity/zilla/runtime/engine/Engine.java | 74 ++++--------------- .../runtime/engine/internal/EngineTest.java | 57 -------------- 2 files changed, 14 insertions(+), 117 deletions(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index edec4ce157..b08dd92a1f 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -53,7 +53,6 @@ import org.agrona.CloseHelper; import org.agrona.ErrorHandler; -import org.agrona.MutableDirectBuffer; import org.agrona.collections.Int2ObjectHashMap; import org.agrona.concurrent.AgentRunner; @@ -101,8 +100,8 @@ public final class Engine implements Collector, AutoCloseable private Future watcherTaskRef; private final EventFW eventRO = new EventFW(); - private final int[] eventIndices; - private final long[] eventTimestamps; + private int minWorkerIndex; + private long minTimeStamp; Engine( EngineConfiguration config, @@ -223,8 +222,6 @@ else if ("http".equals(protocol) || "https".equals(protocol)) this.context = context; this.runners = runners; this.readonly = readonly; - this.eventIndices = new int[workerCount]; - this.eventTimestamps = new long[workerCount]; } public T binding( @@ -500,50 +497,29 @@ public int readEvent( while (!empty && messagesRead < messageCountLimit) { int eventCount = 0; + minWorkerIndex = 0; + minTimeStamp = Long.MAX_VALUE; for (int j = 0; j < workers.size(); j++) { final int workerIndex = j; - final int eventIndex = eventCount; - int eventsPeeked = workers.get(workerIndex).peekEvent((m, b, i, l) -> + int eventPeeked = workers.get(workerIndex).peekEvent((m, b, i, l) -> { eventRO.wrap(b, i, i + l); - eventIndices[eventIndex] = workerIndex; - eventTimestamps[eventIndex] = eventRO.timestamp(); + if (eventRO.timestamp() < minTimeStamp) + { + minTimeStamp = eventRO.timestamp(); + minWorkerIndex = workerIndex; + } }); - eventCount += eventsPeeked; - } - sortEventIndicesByTimestamps(eventIndices, eventTimestamps); - for (int i = 0; i < eventCount && messagesRead < messageCountLimit; i++) - { - EngineWorker worker = workers.get(eventIndices[i]); - messagesRead += worker.readEvent(handler, 1); + eventCount += eventPeeked; } empty = eventCount == 0; - } - return messagesRead; - } - - // visible for testing - public static void sortEventIndicesByTimestamps( - int[] indices, - long[] timestamps) - { - int i, j, index; - long timestamp; - for (i = 1; i < indices.length; i++) - { - index = indices[i]; - timestamp = timestamps[i]; - j = i - 1; - while (j >= 0 && timestamps[j] > timestamp) + if (!empty) { - indices[j + 1] = indices[j]; - timestamps[j + 1] = timestamps[j]; - j = j - 1; + messagesRead += workers.get(minWorkerIndex).readEvent(handler, 1); } - indices[j + 1] = index; - timestamps[j + 1] = timestamp; } + return messagesRead; } public EventReader supplyEventReader() @@ -565,28 +541,6 @@ public int supplyLabelId( return worker.supplyTypeId(label); } - private static final class EventRecord - { - public int msgTypeId; - public long timestamp; - public MutableDirectBuffer buffer; - - private EventRecord( - int msgTypeId, - long timestamp, - MutableDirectBuffer buffer) - { - this.msgTypeId = msgTypeId; - this.timestamp = timestamp; - this.buffer = buffer; - } - - public long timestamp() - { - return timestamp; - } - } - // visible for testing public final class ContextImpl implements EngineExtContext { diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java index de33ad9f31..711dca56e2 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java @@ -20,7 +20,6 @@ import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_WORKERS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertTrue; @@ -251,62 +250,6 @@ public void shouldNotConfigureUnknownScheme() throws Exception } } - @Test - public void shouldSortEventIndicesByTimestampSimpleCase() - { - // GIVEN - int[] eventIndices = new int[]{1, 2, 3}; - long[] eventTimestamps = new long[]{1L, 2L, 3L}; - - // WHEN - Engine.sortEventIndicesByTimestamps(eventIndices, eventTimestamps); - - // THEN - assertThat(eventIndices, equalTo(new int[]{1, 2, 3})); - } - - @Test - public void shouldSortEventIndicesByTimestampGenericCase() - { - // GIVEN - int[] eventIndices = new int[]{1, 5, 2, 7, 9, 8}; - long[] eventTimestamps = new long[]{8L, 1L, 9L, 4L, 3L, 42L}; - - // WHEN - Engine.sortEventIndicesByTimestamps(eventIndices, eventTimestamps); - - // THEN - assertThat(eventIndices, equalTo(new int[]{5, 9, 7, 1, 2, 8})); - } - - @Test - public void shouldSortEventIndicesByTimestampOne() - { - // GIVEN - int[] eventIndices = new int[]{3}; - long[] eventTimestamps = new long[]{7777L}; - - // WHEN - Engine.sortEventIndicesByTimestamps(eventIndices, eventTimestamps); - - // THEN - assertThat(eventIndices, equalTo(new int[]{3})); - } - - @Test - public void shouldSortEventIndicesByTimestampEmpty() - { - // GIVEN - int[] eventIndices = new int[]{}; - long[] eventTimestamps = new long[]{}; - - // WHEN - Engine.sortEventIndicesByTimestamps(eventIndices, eventTimestamps); - - // THEN - assertThat(eventIndices, equalTo(new int[]{})); - } - public static final class TestEngineExt implements EngineExtSpi { public static volatile CountDownLatch registerLatch = new CountDownLatch(1); From baf1c1953042f0e06a043d39704d09cd2b2fbd75 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 19 Feb 2024 19:49:30 +0100 Subject: [PATCH 088/167] WIP http server log --- .../internal/stream/HttpEventHandler.java | 41 ++++++++++++++ .../internal/StdoutExporterHandlerTest.java | 22 ++++++++ .../http/internal/HttpEventContext.java | 53 +++++++++++++++++-- .../internal/stream/HttpServerFactory.java | 5 +- .../main/resources/META-INF/zilla/http.idl | 16 +++++- 5 files changed, 132 insertions(+), 5 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index 51b372af78..f8f740e4f4 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -19,13 +19,21 @@ import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.Array32FW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.HttpHeaderFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpResponseEventFW; public class HttpEventHandler extends EventHandler { private static final String HTTP_AUTHORIZATION_FORMAT = "%s: HTTP Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + private static final String HTTP_REQUEST_FORMAT = + "INFO: HTTP Request [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; + private static final String HTTP_RESPONSE_FORMAT = + "INFO: HTTP Response [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -47,6 +55,7 @@ public void handleEvent( switch (event.kind()) { case AUTHORIZATION: + { HttpAuthorizationEventFW e = event.authorization(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); @@ -54,5 +63,37 @@ public void handleEvent( binding, asString(e.identity())); break; } + case REQUEST: + { + HttpRequestEventFW e = event.request(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.format(HTTP_REQUEST_FORMAT, e.timestamp(), e.traceId(), namespace, binding, headersAsString(e.headers())); + break; + } + case RESPONSE: + { + HttpResponseEventFW e = event.response(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.format(HTTP_RESPONSE_FORMAT, e.timestamp(), e.traceId(), namespace, binding, headersAsString(e.headers())); + break; + } + } + } + + private static String headersAsString( + Array32FW headers) + { + StringBuilder sb = new StringBuilder(); + headers.forEach(h -> + { + sb.append("["); + sb.append(h.name().asString()); + sb.append(" = "); + sb.append(h.value().asString()); + sb.append("] "); + }); + return sb.toString(); } } diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index 3c7ec8cb39..000ebf8afe 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -56,6 +56,10 @@ public class StdoutExporterHandlerTest private static final String EXPECTED_OUTPUT = "WARNING: HTTP Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + "[identity = identity]\n" + + "INFO: HTTP Request [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "[name1 = value1] [name2 = value2] \n" + + "INFO: HTTP Response [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "[name1 = value1] [name2 = value2] \n" + "WARNING: Kafka Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + "ERROR: Kafka API Version Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + "WARNING: MQTT Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + @@ -84,6 +88,24 @@ public void shouldStart() .identity("identity") ).build(); layout.writeEvent(HTTP_TYPE_ID, httpAuthorizationEvent.buffer(), 0, httpAuthorizationEvent.sizeof()); + HttpEventFW httpRequestEvent = new HttpEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .request(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + .headersItem(h -> h.name("name1").value("value1")) + .headersItem(h -> h.name("name2").value("value2")) + ).build(); + layout.writeEvent(HTTP_TYPE_ID, httpRequestEvent.buffer(), 0, httpRequestEvent.sizeof()); + HttpEventFW httpResponseEvent = new HttpEventFW.Builder() + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .response(e -> e.timestamp(77) + .traceId(0x0000000000000042L) + .namespacedId(0x0000000200000007L) + .headersItem(h -> h.name("name1").value("value1")) + .headersItem(h -> h.name("name2").value("value2")) + ).build(); + layout.writeEvent(HTTP_TYPE_ID, httpResponseEvent.buffer(), 0, httpResponseEvent.sizeof()); KafkaEventFW kafkaAuthorizationEvent = new KafkaEventFW.Builder() .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e.timestamp(77) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index d78a03d4c9..848ac9738a 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -16,11 +16,14 @@ package io.aklivity.zilla.runtime.binding.http.internal; import java.nio.ByteBuffer; +import java.util.Map; import java.util.function.LongSupplier; -import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.AtomicBuffer; import org.agrona.concurrent.UnsafeBuffer; +import io.aklivity.zilla.runtime.binding.http.internal.types.Array32FW; +import io.aklivity.zilla.runtime.binding.http.internal.types.HttpHeaderFW; import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; @@ -28,10 +31,14 @@ public class HttpEventContext { - private static final int EVENT_BUFFER_CAPACITY = 1024; + private static final int EVENT_BUFFER_CAPACITY = 2048; + private static final int HEADER_BUFFER_CAPACITY = 1024; + private final AtomicBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final HttpEventFW.Builder httpEventRW = new HttpEventFW.Builder(); - private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + private final AtomicBuffer headerBuffer = new UnsafeBuffer(new byte[HEADER_BUFFER_CAPACITY]); + private final Array32FW.Builder headersRW = + new Array32FW.Builder<>(new HttpHeaderFW.Builder(), new HttpHeaderFW()); private final int httpTypeId; private final MessageConsumer logger; private final LongSupplier timestamp; @@ -63,4 +70,44 @@ public void authorization( .build(); logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } + + public void request( + long traceId, + long routedId, + Array32FW headers) + { + HttpEventFW event = httpEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .request(e -> e + .traceId(traceId) + .namespacedId(routedId) + .headers(headers)) + .build(); + logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + } + + public void request( + long traceId, + long routedId, + Map headers) + { + headersRW.wrap(headerBuffer, 0, headerBuffer.capacity()); + headers.forEach((n, v) -> headersRW.item(i -> i.name(n).value(v))); + request(traceId, routedId, headersRW.build()); + } + + public void response( + long traceId, + long routedId, + Array32FW headers) + { + HttpEventFW event = httpEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .response(e -> e + .traceId(traceId) + .namespacedId(routedId) + .headers(headers)) + .build(); + logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index b56d449fbe..7fd42b5084 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -2272,6 +2272,7 @@ private boolean onDecodeHeaders( final HttpHeaderFW connection = beginEx.headers().matchFirst(h -> HEADER_CONNECTION.equals(h.name())); exchange.responseClosing = connection != null && connectionClose.reset(connection.value().asString()).matches(); + event.request(traceId, routedId, beginEx.headers()); this.exchange = exchange; } return headersValid; @@ -2999,6 +3000,7 @@ private void onResponseBegin( final HttpBeginExFW beginEx = begin.extension().get(beginExRO::tryWrap); final Array32FW headers = beginEx != null ? beginEx.headers() : DEFAULT_HEADERS; + event.response(traceId, routedId, headers); responseState = HttpExchangeState.OPEN; doEncodeHeaders(this, traceId, sessionId, 0L, headers); } @@ -4927,7 +4929,7 @@ else if (headersDecoder.httpError()) else { final Map headers = headersDecoder.headers; - + event.request(traceId, routedId, headers); if (isCorsPreflightRequest(headers)) { if (!endRequest) @@ -6020,6 +6022,7 @@ private void onResponseBegin( header.name().equals(HEADER_CONTENT_LENGTH)); responseContentLength = contentLengthHeader != null ? parseInt(contentLengthHeader.value().asString()) : -1; + event.response(traceId, routedId, headers); doEncodeHeaders(traceId, authorization, streamId, policy, origin, headers, responseContentLength == 0); } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index cdbe5e859a..f630ef05be 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -54,7 +54,9 @@ scope http { enum HttpEventType (uint8) { - AUTHORIZATION (1) + AUTHORIZATION (1), + REQUEST (2), + RESPONSE (3) } enum Result (uint8) @@ -69,9 +71,21 @@ scope http string8 identity; } + struct HttpRequestEvent extends core::event::Event + { + HttpHeader[] headers; + } + + struct HttpResponseEvent extends core::event::Event + { + HttpHeader[] headers; + } + union HttpEvent switch (HttpEventType) { case AUTHORIZATION: HttpAuthorizationEvent authorization; + case REQUEST: HttpRequestEvent request; + case RESPONSE: HttpResponseEvent response; } } } From 39e737d78b3e67983db2a771ee61997e19ccb0ce Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 09:41:19 +0100 Subject: [PATCH 089/167] rm level --- .../stdout/internal/stream/EventHandler.java | 6 ------ .../internal/stream/HttpEventHandler.java | 8 ++++---- .../internal/stream/KafkaEventHandler.java | 6 +++--- .../internal/stream/MqttEventHandler.java | 4 ++-- .../stream/SchemaRegistryEventHandler.java | 2 +- .../internal/stream/TcpEventHandler.java | 2 +- .../internal/stream/TlsEventHandler.java | 2 +- .../internal/StdoutExporterHandlerTest.java | 18 +++++++++--------- 8 files changed, 21 insertions(+), 27 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java index 3613d733a5..4397f7103a 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java @@ -52,12 +52,6 @@ protected static String asString( return s == null ? "" : s; } - protected static String level( - ResultFW result) - { - return result.get() == Result.SUCCESS ? "INFO" : "WARNING"; - } - protected static String result( ResultFW result) { diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index f8f740e4f4..90ede8ad9e 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -29,11 +29,11 @@ public class HttpEventHandler extends EventHandler { private static final String HTTP_AUTHORIZATION_FORMAT = - "%s: HTTP Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + "HTTP Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; private static final String HTTP_REQUEST_FORMAT = - "INFO: HTTP Request [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; + "HTTP Request [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; private static final String HTTP_RESPONSE_FORMAT = - "INFO: HTTP Response [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; + "HTTP Response [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -59,7 +59,7 @@ public void handleEvent( HttpAuthorizationEventFW e = event.authorization(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HTTP_AUTHORIZATION_FORMAT, level(e.result()), result(e.result()), e.timestamp(), e.traceId(), namespace, + out.printf(HTTP_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, binding, asString(e.identity())); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index 7fbb7ff581..612ed27cf5 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -26,9 +26,9 @@ public class KafkaEventHandler extends EventHandler { private static final String KAFKA_AUTHORIZATION_FORMAT = - "%s: Kafka Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + "Kafka Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; private static final String KAFKA_API_VERSION_REJECTED = - "ERROR: Kafka API Version Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + "Kafka API Version Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); @@ -54,7 +54,7 @@ public void handleEvent( KafkaAuthorizationEventFW e = event.authorization(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_AUTHORIZATION_FORMAT, level(e.result()), result(e.result()), e.timestamp(), e.traceId(), namespace, + out.printf(KAFKA_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, binding); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index 7c0433e7cf..0b97e9f576 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -25,7 +25,7 @@ public class MqttEventHandler extends EventHandler { private static final String MQTT_AUTHORIZATION_FORMAT = - "%s: MQTT Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + "MQTT Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); @@ -50,7 +50,7 @@ public void handleEvent( MqttAuthorizationEventFW e = event.authorization(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(MQTT_AUTHORIZATION_FORMAT, level(e.result()), result(e.result()), e.timestamp(), e.traceId(), namespace, + out.printf(MQTT_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, binding, asString(e.identity())); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index 011f3296a4..8ed3d4d19d 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -25,7 +25,7 @@ public class SchemaRegistryEventHandler extends EventHandler { private static final String SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED = - "ERROR: Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s] " + + "Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s] " + "[method = %s] [status = %d]%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index e9c886719b..1255bebebb 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -25,7 +25,7 @@ public class TcpEventHandler extends EventHandler { private static final String TCP_DNS_RESOLUTION_FAILED_FORMAT = - "ERROR: TCP DNS Resolution Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; + "TCP DNS Resolution Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index 4a7f3f72ed..5e949c304b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -25,7 +25,7 @@ public class TlsEventHandler extends EventHandler { private static final String TLS_FAILED_FORMAT = - "ERROR: TLS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [error = %s]%n"; + "TLS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [error = %s]%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index 000ebf8afe..f4cb82a834 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -54,21 +54,21 @@ public class StdoutExporterHandlerTest private static final int TCP_TYPE_ID = 5; private static final int TLS_TYPE_ID = 6; private static final String EXPECTED_OUTPUT = - "WARNING: HTTP Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "HTTP Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + "[identity = identity]\n" + - "INFO: HTTP Request [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "HTTP Request [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + "[name1 = value1] [name2 = value2] \n" + - "INFO: HTTP Response [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "HTTP Response [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + "[name1 = value1] [name2 = value2] \n" + - "WARNING: Kafka Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + - "ERROR: Kafka API Version Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + - "WARNING: MQTT Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "Kafka Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + + "Kafka API Version Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + + "MQTT Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + "[identity = identity]\n" + - "ERROR: Schema Registry Remote Access Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "Schema Registry Remote Access Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + "[url = url] [method = method] [status = 42]\n" + - "ERROR: TCP DNS Resolution Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + + "TCP DNS Resolution Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + "[address = address]\n" + - "ERROR: TLS Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] [error = HANDSHAKE_ERROR]\n"; + "TLS Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] [error = HANDSHAKE_ERROR]\n"; @Test public void shouldStart() From da6cb7bdd5fb23bec513b387f0dbf5fc0b8182ae Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 09:53:42 +0100 Subject: [PATCH 090/167] fix onDecodeResponseErrorCode --- .../stream/KafkaClientDescribeFactory.java | 2 +- .../internal/stream/KafkaClientFetchFactory.java | 7 +++++-- .../internal/stream/KafkaClientGroupFactory.java | 14 +++++++------- .../internal/stream/KafkaClientMetaFactory.java | 7 +++++-- .../stream/KafkaClientOffsetCommitFactory.java | 2 +- .../stream/KafkaClientOffsetFetchFactory.java | 2 +- .../internal/stream/KafkaClientProduceFactory.java | 2 +- .../internal/stream/KafkaClientSaslHandshaker.java | 4 ++-- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java index c255364d8f..1430b779d6 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java @@ -531,7 +531,6 @@ private int decodeDescribeResponse( final String resourceName = resource.name().asString(); final int resourceError = resource.errorCode(); - onDecodeResponseErrorCode(resourceError, traceId); client.onDecodeResource(traceId, client.authorization, resourceError, resourceName); // TODO: use different decoder for configs @@ -966,6 +965,7 @@ public void onDecodeResource( assert resource.equals(this.topic); break; default: + onDecodeResponseErrorCode(traceId, errorCode); final KafkaResetExFW resetEx = kafkaResetExRW.wrap(extBuffer, 0, extBuffer.capacity()) .typeId(kafkaTypeId) .error(errorCode) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java index 035ff88551..8da1d13607 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java @@ -762,7 +762,6 @@ private int decodeOffsetsPartition( final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); - onDecodeResponseErrorCode(errorCode, traceId); final long partitionOffset = partition.offset$(); progress = partition.limit(); @@ -908,7 +907,6 @@ else if (length != 0) { final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); - onDecodeResponseErrorCode(errorCode, traceId); client.stableOffset = partition.lastStableOffset() - 1; client.latestOffset = partition.highWatermark() - 1; @@ -2951,6 +2949,7 @@ private void onDecodeOffsetsPartition( this.nextOffset = partitionOffset; break; default: + onDecodeResponseErrorCode(traceId, errorCode); cleanupApplication(traceId, errorCode); doNetworkEnd(traceId, authorization); break; @@ -2990,6 +2989,10 @@ private void onDecodeFetchPartition( traceId, authorization, 0, EMPTY_OCTETS); } } + else + { + onDecodeResponseErrorCode(traceId, errorCode); + } cleanupApplication(traceId, errorCode); doNetworkEnd(traceId, authorization); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java index 0bfbb7f98f..4ac2bbbfd8 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java @@ -778,7 +778,6 @@ private int decodeDescribeResponse( final String resourceName = resource.name().asString(); final short errorCode = resource.errorCode(); - onDecodeResponseErrorCode(errorCode, traceId); if (errorCode != ERROR_NONE || !client.delegate.nodeId.equals(resourceName)) { @@ -879,7 +878,7 @@ private int decodeFindCoordinatorResponse( findCoordinatorResponse.host(), findCoordinatorResponse.port()); break; default: - onDecodeResponseErrorCode(errorCode, traceId); + onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeClusterReject; break; @@ -970,7 +969,6 @@ private int decodeJoinGroupResponse( joinGroupResponseRO.tryWrap(buffer, progress, limit); final short errorCode = joinGroupResponse != null ? joinGroupResponse.errorCode() : ERROR_EXISTS; - onDecodeResponseErrorCode(errorCode, traceId); if (joinGroupResponse == null) { @@ -1015,6 +1013,7 @@ private int decodeJoinGroupResponse( joinGroupResponse.memberId().asString()); break; default: + onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1057,7 +1056,6 @@ private int decodeSyncGroupResponse( syncGroupResponseRO.tryWrap(buffer, progress, limit); final short errorCode = syncGroupResponse != null ? syncGroupResponse.errorCode() : ERROR_EXISTS; - onDecodeResponseErrorCode(errorCode, traceId); if (syncGroupResponse == null) { @@ -1075,6 +1073,7 @@ private int decodeSyncGroupResponse( client.onSyncGroupResponse(traceId, authorization, syncGroupResponse.assignment()); break; default: + onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1124,7 +1123,6 @@ private int decodeHeartbeatResponse( progress = heartbeatResponse.limit(); final short errorCode = heartbeatResponse.errorCode(); - onDecodeResponseErrorCode(errorCode, traceId); switch (errorCode) { @@ -1138,6 +1136,7 @@ private int decodeHeartbeatResponse( client.onHeartbeatResponse(traceId, authorization); break; default: + onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1202,7 +1201,7 @@ private int decodeLeaveGroupResponse( } else { - onDecodeResponseErrorCode(errorCode, traceId); + onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } @@ -1217,7 +1216,7 @@ private int decodeLeaveGroupResponse( } else { - onDecodeResponseErrorCode(errorCode, traceId); + onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } @@ -2572,6 +2571,7 @@ public void onDecodeResource( assert resource.equals(delegate.nodeId); break; default: + onDecodeResponseErrorCode(traceId, errorCode); onNetworkError(traceId, errorCode); break; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java index 97991e6127..83624dd4a4 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java @@ -698,7 +698,6 @@ private int decodeMetaTopic( final String topic = topicMetadata.topic().asString(); final int topicError = topicMetadata.errorCode(); - onDecodeResponseErrorCode(topicError, traceId); client.onDecodeTopic(traceId, authorization, topicError, topic); @@ -763,7 +762,6 @@ private int decodeMetaPartition( } final int partitionError = partition.errorCode(); - onDecodeResponseErrorCode(partitionError, traceId); final int partitionId = partition.partitionId(); final int leaderId = partition.leader(); @@ -1812,6 +1810,7 @@ private void onDecodeTopic( newPartitions.clear(); break; default: + onDecodeResponseErrorCode(traceId, errorCode); final KafkaResetExFW resetEx = kafkaResetExRW.wrap(extBuffer, 0, extBuffer.capacity()) .typeId(kafkaTypeId) .error(errorCode) @@ -1832,6 +1831,10 @@ private void onDecodePartition( { newPartitions.put(partitionId, leaderId); } + else + { + onDecodeResponseErrorCode(traceId, partitionError); + } } @Override diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java index 90bf3766ce..ff4c276882 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java @@ -589,7 +589,7 @@ private int decodeOffsetCommitPartition( } else { - onDecodeResponseErrorCode(errorCode, traceId); + onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeReject; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java index 921011b472..f4966d55da 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java @@ -661,7 +661,7 @@ private int decodeOffsetFetchPartition( client.decoder = decodeOffsetFetchPartitions; break; default: - onDecodeResponseErrorCode(errorCode, traceId); + onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeReject; break; diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index 5863b40c96..2085423ade 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -816,7 +816,6 @@ private int decodeProducePartition( final int partitionId = partition.partitionId(); final int errorCode = partition.errorCode(); - onDecodeResponseErrorCode(errorCode, traceId); progress = partition.limit(); @@ -2272,6 +2271,7 @@ private void onDecodeProducePartition( assert partitionId == this.partitionId; break; default: + onDecodeResponseErrorCode(traceId, errorCode); final KafkaResetExFW resetEx = kafkaResetExRW.wrap(extBuffer, 0, extBuffer.capacity()) .typeId(kafkaTypeId) .error(errorCode) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index aaf75fcb10..f5fb387af7 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -835,8 +835,8 @@ private String16FW createClientId( } protected void onDecodeResponseErrorCode( - int errorCode, - long traceId) + long traceId, + int errorCode) { if (errorCode == ERROR_UNSUPPORTED_VERSION) { From 05db0f42846616290a7ce377b887702a8038ba83 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 11:06:15 +0100 Subject: [PATCH 091/167] fix tcp remoteAddress --- .../zilla/runtime/binding/tcp/internal/TcpEventContext.java | 4 +++- .../binding/tcp/internal/stream/TcpClientFactory.java | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 84d1b009c8..1150ec1b66 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -15,6 +15,7 @@ */ package io.aklivity.zilla.runtime.binding.tcp.internal; +import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.util.function.LongSupplier; @@ -46,8 +47,9 @@ public TcpEventContext( public void dnsResolutionFailed( long traceId, long routedId, - String address) + InetSocketAddress remoteAddress) { + String address = remoteAddress == null ? "" : remoteAddress.toString(); TcpEventFW event = tcpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .dnsResolutionFailed(e -> e diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 1641074084..200c8cf16c 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -273,8 +273,7 @@ private void doNetConnect( } catch (UnresolvedAddressException ex) { - String address = remoteAddress == null ? "" : remoteAddress.toString(); - event.dnsResolutionFailed(supplyTraceId.getAsLong(), routedId, address); + event.dnsResolutionFailed(supplyTraceId.getAsLong(), routedId, remoteAddress); onNetRejected(); } catch (IOException ex) @@ -294,7 +293,7 @@ private int onNetConnect( } catch (UnresolvedAddressException ex) { - event.dnsResolutionFailed(supplyTraceId.getAsLong(), routedId, ""); + event.dnsResolutionFailed(supplyTraceId.getAsLong(), routedId, null); onNetRejected(); } catch (IOException ex) From cf554b61b6d63aa6d1a7272b87b5fa91cc98ab63 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 11:11:10 +0100 Subject: [PATCH 092/167] fix tcp traceId doNetConnect --- .../binding/tcp/internal/stream/TcpClientFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 200c8cf16c..717a4b5724 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -141,6 +141,7 @@ public MessageConsumer newStream( MessageConsumer application) { final BeginFW begin = beginRO.wrap(buffer, index, index + length); + final long traceId = begin.traceId(); final long originId = begin.originId(); final long routedId = begin.routedId(); final long authorization = begin.authorization(); @@ -165,7 +166,7 @@ public MessageConsumer newStream( final SocketChannel channel = newSocketChannel(); final TcpClient client = new TcpClient(application, originId, routedId, initialId, channel); - client.doNetConnect(route, binding.options); + client.doNetConnect(traceId, route, binding.options); newStream = client::onAppMessage; } @@ -252,6 +253,7 @@ private TcpClient( } private void doNetConnect( + long traceId, InetSocketAddress remoteAddress, TcpOptionsConfig options) { @@ -273,7 +275,7 @@ private void doNetConnect( } catch (UnresolvedAddressException ex) { - event.dnsResolutionFailed(supplyTraceId.getAsLong(), routedId, remoteAddress); + event.dnsResolutionFailed(traceId, routedId, remoteAddress); onNetRejected(); } catch (IOException ex) From 776c2ec4da3aa4755aa62b5e06a1a2697439e6a2 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 11:24:42 +0100 Subject: [PATCH 093/167] fix tcp traceId 0 onNetConnect --- .../runtime/binding/tcp/internal/stream/TcpClientFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 717a4b5724..c0c4084725 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -295,7 +295,7 @@ private int onNetConnect( } catch (UnresolvedAddressException ex) { - event.dnsResolutionFailed(supplyTraceId.getAsLong(), routedId, null); + event.dnsResolutionFailed(0L, routedId, null); onNetRejected(); } catch (IOException ex) From 10cfdfc0f14ff2523f8d7fb7eb10e204fa0e0643 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 11:46:44 +0100 Subject: [PATCH 094/167] fix mv MessageReader --- .../stdout/internal/stream/StdoutEventsStream.java | 6 +++--- .../java/io/aklivity/zilla/runtime/engine/Engine.java | 4 ++-- .../io/aklivity/zilla/runtime/engine/EngineContext.java | 4 ++-- .../function/MessageReader.java} | 6 ++---- .../runtime/engine/internal/registry/EngineWorker.java | 8 ++++---- 5 files changed, 13 insertions(+), 15 deletions(-) rename runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/{util/function/EventReader.java => binding/function/MessageReader.java} (81%) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index ff9c04196b..31f297ddf4 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -22,16 +22,16 @@ import org.agrona.collections.Int2ObjectHashMap; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.engine.util.function.EventReader; +import io.aklivity.zilla.runtime.engine.binding.function.MessageReader; public class StdoutEventsStream { - private final EventReader readEvent; + private final MessageReader readEvent; private final ToIntFunction lookupLabelId; private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( - EventReader readEvent, + MessageReader readEvent, LongFunction supplyNamespace, LongFunction supplyLocalName, ToIntFunction lookupLabelId, diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index b08dd92a1f..e004ba07de 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -58,6 +58,7 @@ import io.aklivity.zilla.runtime.engine.binding.Binding; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.engine.binding.function.MessageReader; import io.aklivity.zilla.runtime.engine.catalog.Catalog; import io.aklivity.zilla.runtime.engine.config.KindConfig; import io.aklivity.zilla.runtime.engine.exporter.Exporter; @@ -77,7 +78,6 @@ import io.aklivity.zilla.runtime.engine.metrics.MetricGroup; import io.aklivity.zilla.runtime.engine.model.Model; import io.aklivity.zilla.runtime.engine.namespace.NamespacedId; -import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.engine.vault.Vault; public final class Engine implements Collector, AutoCloseable @@ -522,7 +522,7 @@ public int readEvent( return messagesRead; } - public EventReader supplyEventReader() + public MessageReader supplyEventReader() { return this::readEvent; } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 51629193de..8f5d273ec8 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -25,6 +25,7 @@ import io.aklivity.zilla.runtime.engine.binding.BindingHandler; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.engine.binding.function.MessageReader; import io.aklivity.zilla.runtime.engine.budget.BudgetCreditor; import io.aklivity.zilla.runtime.engine.budget.BudgetDebitor; import io.aklivity.zilla.runtime.engine.buffer.BufferPool; @@ -38,7 +39,6 @@ import io.aklivity.zilla.runtime.engine.model.ConverterHandler; import io.aklivity.zilla.runtime.engine.model.ValidatorHandler; import io.aklivity.zilla.runtime.engine.poller.PollerKey; -import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.engine.vault.VaultHandler; public interface EngineContext @@ -72,7 +72,7 @@ int readEvent( MessageConsumer handler, int messageCountLimit); - Supplier supplyEventReader(); + Supplier supplyEventReader(); MessageConsumer supplySender( long streamId); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/binding/function/MessageReader.java similarity index 81% rename from runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java rename to runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/binding/function/MessageReader.java index 79e03bb4fa..9759b940d5 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/util/function/EventReader.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/binding/function/MessageReader.java @@ -13,11 +13,9 @@ * License for the specific language governing permissions and limitations * under the License. */ -package io.aklivity.zilla.runtime.engine.util.function; +package io.aklivity.zilla.runtime.engine.binding.function; -import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; - -public interface EventReader +public interface MessageReader { int read( MessageConsumer handler, diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 9b8703d5cf..b38b56b1be 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -87,6 +87,7 @@ import io.aklivity.zilla.runtime.engine.binding.BindingContext; import io.aklivity.zilla.runtime.engine.binding.BindingHandler; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.engine.binding.function.MessageReader; import io.aklivity.zilla.runtime.engine.budget.BudgetCreditor; import io.aklivity.zilla.runtime.engine.budget.BudgetDebitor; import io.aklivity.zilla.runtime.engine.buffer.BufferPool; @@ -136,7 +137,6 @@ import io.aklivity.zilla.runtime.engine.model.ValidatorHandler; import io.aklivity.zilla.runtime.engine.namespace.NamespacedId; import io.aklivity.zilla.runtime.engine.poller.PollerKey; -import io.aklivity.zilla.runtime.engine.util.function.EventReader; import io.aklivity.zilla.runtime.engine.util.function.LongLongFunction; import io.aklivity.zilla.runtime.engine.vault.Vault; import io.aklivity.zilla.runtime.engine.vault.VaultContext; @@ -214,7 +214,7 @@ public class EngineWorker implements EngineContext, Agent private final ScalarsLayout gaugesLayout; private final HistogramsLayout histogramsLayout; private final EventsLayout eventsLayout; - private final Supplier supplyEventReader; + private final Supplier supplyEventReader; private long initialId; private long promiseId; private long traceId; @@ -237,7 +237,7 @@ public EngineWorker( Collection models, Collection metricGroups, Collector collector, - Supplier supplyEventReader, + Supplier supplyEventReader, int index, boolean readonly) { @@ -1601,7 +1601,7 @@ public int peekEvent( return eventsLayout.peekEvent(handler); } - public Supplier supplyEventReader() + public Supplier supplyEventReader() { return supplyEventReader; } From f302779ce164f8b89beb6d16578849253907089a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 12:00:22 +0100 Subject: [PATCH 095/167] fix Engine supplyEventReader --- .../exporter/stdout/internal/StdoutExporterHandler.java | 2 +- .../exporter/stdout/internal/StdoutExporterHandlerTest.java | 2 +- .../java/io/aklivity/zilla/runtime/engine/EngineContext.java | 3 +-- .../zilla/runtime/engine/internal/registry/EngineWorker.java | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 66e86b54b6..99ecffe339 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -42,7 +42,7 @@ public StdoutExporterHandler( @Override public void start() { - stdoutEventsStream = new StdoutEventsStream(context.supplyEventReader().get(), context::supplyNamespace, + stdoutEventsStream = new StdoutEventsStream(context.supplyEventReader(), context::supplyNamespace, context::supplyLocalName, context::lookupLabelId, out); } diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index f4cb82a834..50b140b827 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -171,7 +171,7 @@ public void shouldStart() when(context.lookupLabelId("tls")).thenReturn(TLS_TYPE_ID); when(context.supplyNamespace(0x0000000200000007L)).thenReturn("ns"); when(context.supplyLocalName(0x0000000200000007L)).thenReturn("binding"); - when(context.supplyEventReader()).thenReturn(() -> layout::readEvent); + when(context.supplyEventReader()).thenReturn(layout::readEvent); StdoutExporterHandler handler = new StdoutExporterHandler(config, context, exporter, ps); // WHEN diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 8f5d273ec8..8b021da2c5 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -19,7 +19,6 @@ import java.net.URL; import java.nio.channels.SelectableChannel; import java.util.function.LongSupplier; -import java.util.function.Supplier; import org.agrona.MutableDirectBuffer; @@ -72,7 +71,7 @@ int readEvent( MessageConsumer handler, int messageCountLimit); - Supplier supplyEventReader(); + MessageReader supplyEventReader(); MessageConsumer supplySender( long streamId); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index b38b56b1be..5d3ced7cb2 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -1601,9 +1601,9 @@ public int peekEvent( return eventsLayout.peekEvent(handler); } - public Supplier supplyEventReader() + public MessageReader supplyEventReader() { - return supplyEventReader; + return supplyEventReader.get(); } private MessageConsumer supplyWriter( From 035589e96ccfdcab5324ecda3d19498b96377b92 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 16:28:53 +0100 Subject: [PATCH 096/167] fix mv lookupTypeId --- .../stdout/internal/StdoutExporterHandler.java | 2 +- .../stdout/internal/stream/StdoutEventsStream.java | 8 ++++---- .../stdout/internal/StdoutExporterHandlerTest.java | 12 ++++++------ .../aklivity/zilla/runtime/engine/EngineContext.java | 2 +- .../engine/internal/registry/EngineWorker.java | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 99ecffe339..48b38f6230 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -43,7 +43,7 @@ public StdoutExporterHandler( public void start() { stdoutEventsStream = new StdoutEventsStream(context.supplyEventReader(), context::supplyNamespace, - context::supplyLocalName, context::lookupLabelId, out); + context::supplyLocalName, context::lookupTypeId, out); } @Override diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 31f297ddf4..23751492b3 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -27,18 +27,18 @@ public class StdoutEventsStream { private final MessageReader readEvent; - private final ToIntFunction lookupLabelId; + private final ToIntFunction lookupTypeId; private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( MessageReader readEvent, LongFunction supplyNamespace, LongFunction supplyLocalName, - ToIntFunction lookupLabelId, + ToIntFunction lookupTypeId, PrintStream out) { this.readEvent = readEvent; - this.lookupLabelId = lookupLabelId; + this.lookupTypeId = lookupTypeId; final HttpEventHandler httpEventHandler = new HttpEventHandler(supplyNamespace, supplyLocalName, out); final KafkaEventHandler kafkaEventHandler = new KafkaEventHandler(supplyNamespace, supplyLocalName, out); @@ -67,7 +67,7 @@ private void addEventHandler( String type, MessageConsumer consumer) { - int labelId = lookupLabelId.applyAsInt(type); + int labelId = lookupTypeId.applyAsInt(type); if (labelId != 0) { eventHandlers.put(labelId, consumer); diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index 50b140b827..aad044edc1 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -163,12 +163,12 @@ public void shouldStart() StdoutExporterConfig exporter = new StdoutExporterConfig(mock(ExporterConfig.class)); ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); - when(context.lookupLabelId("http")).thenReturn(HTTP_TYPE_ID); - when(context.lookupLabelId("kafka")).thenReturn(KAFKA_TYPE_ID); - when(context.lookupLabelId("mqtt")).thenReturn(MQTT_TYPE_ID); - when(context.lookupLabelId("schema-registry")).thenReturn(SCHEMA_REGISTRY_TYPE_ID); - when(context.lookupLabelId("tcp")).thenReturn(TCP_TYPE_ID); - when(context.lookupLabelId("tls")).thenReturn(TLS_TYPE_ID); + when(context.lookupTypeId("http")).thenReturn(HTTP_TYPE_ID); + when(context.lookupTypeId("kafka")).thenReturn(KAFKA_TYPE_ID); + when(context.lookupTypeId("mqtt")).thenReturn(MQTT_TYPE_ID); + when(context.lookupTypeId("schema-registry")).thenReturn(SCHEMA_REGISTRY_TYPE_ID); + when(context.lookupTypeId("tcp")).thenReturn(TCP_TYPE_ID); + when(context.lookupTypeId("tls")).thenReturn(TLS_TYPE_ID); when(context.supplyNamespace(0x0000000200000007L)).thenReturn("ns"); when(context.supplyLocalName(0x0000000200000007L)).thenReturn("binding"); when(context.supplyEventReader()).thenReturn(layout::readEvent); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 8b021da2c5..a95d772b02 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -49,7 +49,7 @@ public interface EngineContext int supplyTypeId( String name); - int lookupLabelId( + int lookupTypeId( String name); long supplyInitialId( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 5d3ced7cb2..f6ba010543 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -461,7 +461,7 @@ public int supplyTypeId( } @Override - public int lookupLabelId( + public int lookupTypeId( String name) { return labels.lookupLabelId(name); From ceb2efceaeaedc4ef2739db3eecd293297de6758 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 16:53:39 +0100 Subject: [PATCH 097/167] fix mv remoteaddressrejected --- .../stdout/internal/stream/SchemaRegistryEventHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index 8ed3d4d19d..fd8b5a21ef 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -24,7 +24,7 @@ public class SchemaRegistryEventHandler extends EventHandler { - private static final String SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED = + private static final String REMOTE_ACCESS_REJECTED = "Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s] " + "[method = %s] [status = %d]%n"; @@ -51,7 +51,7 @@ public void handleEvent( SchemaRegistryRemoteAccessRejectedEventFW e = event.remoteAccessRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED, e.timestamp(), e.traceId(), namespace, binding, asString(e.url()), + out.printf(REMOTE_ACCESS_REJECTED, e.timestamp(), e.traceId(), namespace, binding, asString(e.url()), asString(e.method()), e.status()); break; } From d2665ac17a667e2b672c7e2f8eba9c6305ef2a5b Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 17:03:52 +0100 Subject: [PATCH 098/167] fix mv supplyEventWriter --- .../registry/internal/SchemaRegistryEventContext.java | 6 +++--- .../binding/http/internal/HttpEventContext.java | 10 +++++----- .../binding/kafka/internal/KafkaEventContext.java | 8 ++++---- .../binding/mqtt/internal/MqttEventContext.java | 6 +++--- .../runtime/binding/tcp/internal/TcpEventContext.java | 6 +++--- .../runtime/binding/tls/internal/TlsEventContext.java | 6 +++--- .../aklivity/zilla/runtime/engine/EngineContext.java | 6 +++--- .../runtime/engine/internal/registry/EngineWorker.java | 2 +- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index b3cccaf7d6..c47db586ac 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -32,14 +32,14 @@ public class SchemaRegistryEventContext private final SchemaRegistryEventFW.Builder schemaRegistryEventRW = new SchemaRegistryEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int schemaRegistryTypeId; - private final MessageConsumer logger; + private final MessageConsumer eventWriter; private final LongSupplier timestamp; public SchemaRegistryEventContext( EngineContext context) { this.schemaRegistryTypeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); - this.logger = context.logger(); + this.eventWriter = context.supplyEventWriter(); this.timestamp = context.timestamp(); } @@ -58,6 +58,6 @@ public void remoteAccessRejected( .status((short) status) ) .build(); - logger.accept(schemaRegistryTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(schemaRegistryTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 848ac9738a..4ccabf6310 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -40,14 +40,14 @@ public class HttpEventContext private final Array32FW.Builder headersRW = new Array32FW.Builder<>(new HttpHeaderFW.Builder(), new HttpHeaderFW()); private final int httpTypeId; - private final MessageConsumer logger; + private final MessageConsumer eventWriter; private final LongSupplier timestamp; public HttpEventContext( EngineContext context) { this.httpTypeId = context.supplyTypeId(HttpBinding.NAME); - this.logger = context.logger(); + this.eventWriter = context.supplyEventWriter(); this.timestamp = context.timestamp(); } @@ -68,7 +68,7 @@ public void authorization( .identity(identity) ) .build(); - logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } public void request( @@ -83,7 +83,7 @@ public void request( .namespacedId(routedId) .headers(headers)) .build(); - logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } public void request( @@ -108,6 +108,6 @@ public void response( .namespacedId(routedId) .headers(headers)) .build(); - logger.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index f13a7ef889..ae1b7b271d 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -34,14 +34,14 @@ public class KafkaEventContext private final KafkaEventFW.Builder kafkaEventRW = new KafkaEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int kafkaTypeId; - private final MessageConsumer logger; + private final MessageConsumer eventWriter; private final LongSupplier timestamp; public KafkaEventContext( EngineContext context) { this.kafkaTypeId = context.supplyTypeId(KafkaBinding.NAME); - this.logger = context.logger(); + this.eventWriter = context.supplyEventWriter(); this.timestamp = context.timestamp(); } @@ -60,7 +60,7 @@ public void authorization( .result(r -> r.set(result)) ) .build(); - logger.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } public void apiVersionRejected( @@ -73,6 +73,6 @@ public void apiVersionRejected( .traceId(traceId) ) .build(); - logger.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index b81fc0d67e..85e70b51c0 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -33,14 +33,14 @@ public class MqttEventContext private final MqttEventFW.Builder mqttEventRW = new MqttEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int mqttTypeId; - private final MessageConsumer logger; + private final MessageConsumer eventWriter; private final LongSupplier timestamp; public MqttEventContext( EngineContext context) { this.mqttTypeId = context.supplyTypeId(MqttBinding.NAME); - this.logger = context.logger(); + this.eventWriter = context.supplyEventWriter(); this.timestamp = context.timestamp(); } @@ -61,6 +61,6 @@ public void authorization( .identity(identity) ) .build(); - logger.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 1150ec1b66..555ba6ef6b 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -33,14 +33,14 @@ public class TcpEventContext private final TcpEventFW.Builder tcpEventRW = new TcpEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int tcpTypeId; - private final MessageConsumer logger; + private final MessageConsumer eventWriter; private final LongSupplier timestamp; public TcpEventContext( EngineContext context) { this.tcpTypeId = context.supplyTypeId(TcpBinding.NAME); - this.logger = context.logger(); + this.eventWriter = context.supplyEventWriter(); this.timestamp = context.timestamp(); } @@ -59,6 +59,6 @@ public void dnsResolutionFailed( .address(address) ) .build(); - logger.accept(tcpTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(tcpTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 00a67d03a1..b5f8a4a8b8 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -38,14 +38,14 @@ public class TlsEventContext private final TlsEventFW.Builder tlsEventRW = new TlsEventFW.Builder(); private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int tlsTypeId; - private final MessageConsumer logger; + private final MessageConsumer eventWriter; private final LongSupplier timestamp; public TlsEventContext( EngineContext context) { this.tlsTypeId = context.supplyTypeId(TlsBinding.NAME); - this.logger = context.logger(); + this.eventWriter = context.supplyEventWriter(); this.timestamp = context.timestamp(); } @@ -61,7 +61,7 @@ public void tlsFailed( .error(r -> r.set(error)) ) .build(); - logger.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); + eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); } public void tlsFailed( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index a95d772b02..b068850418 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -71,8 +71,6 @@ int readEvent( MessageConsumer handler, int messageCountLimit); - MessageReader supplyEventReader(); - MessageConsumer supplySender( long streamId); @@ -159,7 +157,9 @@ void onExporterAttached( void onExporterDetached( long exporterId); - MessageConsumer logger(); + MessageConsumer supplyEventWriter(); + + MessageReader supplyEventReader(); LongSupplier timestamp(); } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index f6ba010543..04efcaa620 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -915,7 +915,7 @@ public LongConsumer supplyHistogramWriter( } @Override - public MessageConsumer logger() + public MessageConsumer supplyEventWriter() { return this.eventsLayout::writeEvent; } From 7415d67ca2c811fb1b4f5c2595460b2efcf0514f Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 17:20:59 +0100 Subject: [PATCH 099/167] fix mv tcp.idl --- .../stdout/internal/stream/TcpEventHandler.java | 12 ++++++------ .../stdout/internal/StdoutExporterHandlerTest.java | 5 ++--- .../binding/tcp/internal/TcpEventContext.java | 2 +- .../src/main/resources/META-INF/zilla/tcp.idl | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index 1255bebebb..de2f57c993 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -19,13 +19,13 @@ import org.agrona.DirectBuffer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpDnsResolutionFailedEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpDnsFailedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; public class TcpEventHandler extends EventHandler { - private static final String TCP_DNS_RESOLUTION_FAILED_FORMAT = - "TCP DNS Resolution Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; + private static final String TCP_DNS_FAILED_FORMAT = + "TCP DNS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); @@ -46,11 +46,11 @@ public void handleEvent( final TcpEventFW event = tcpEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case DNS_RESOLUTION_FAILED: - TcpDnsResolutionFailedEventFW e = event.dnsResolutionFailed(); + case DNS_FAILED: + TcpDnsFailedFW e = event.dnsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TCP_DNS_RESOLUTION_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.address())); + out.printf(TCP_DNS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.address())); break; } } diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java index aad044edc1..90452a581e 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java @@ -66,8 +66,7 @@ public class StdoutExporterHandlerTest "[identity = identity]\n" + "Schema Registry Remote Access Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + "[url = url] [method = method] [status = 42]\n" + - "TCP DNS Resolution Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + - "[address = address]\n" + + "TCP DNS Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] [address = address]\n" + "TLS Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] [error = HANDSHAKE_ERROR]\n"; @Test @@ -143,7 +142,7 @@ public void shouldStart() schemaRegistryAuthorizationEvent.sizeof()); TcpEventFW tcpDnsResolutionFailedEvent = new TcpEventFW.Builder() .wrap(eventBuffer, 0, eventBuffer.capacity()) - .dnsResolutionFailed(e -> e.timestamp(77) + .dnsFailed(e -> e.timestamp(77) .traceId(0x0000000000000042L) .namespacedId(0x0000000200000007L) .address("address") diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 555ba6ef6b..6bf7315960 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -52,7 +52,7 @@ public void dnsResolutionFailed( String address = remoteAddress == null ? "" : remoteAddress.toString(); TcpEventFW event = tcpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .dnsResolutionFailed(e -> e + .dnsFailed(e -> e .timestamp(timestamp.getAsLong()) .traceId(traceId) .namespacedId(routedId) diff --git a/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl b/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl index 1ed0fa2549..a796c117f5 100644 --- a/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl +++ b/specs/binding-tcp.spec/src/main/resources/META-INF/zilla/tcp.idl @@ -19,17 +19,17 @@ scope tcp { enum TcpEventType (uint8) { - DNS_RESOLUTION_FAILED (1) + DNS_FAILED (1) } - struct TcpDnsResolutionFailedEvent extends core::event::Event + struct TcpDnsFailed extends core::event::Event { string16 address; } union TcpEvent switch (TcpEventType) { - case DNS_RESOLUTION_FAILED: TcpDnsResolutionFailedEvent dnsResolutionFailed; + case DNS_FAILED: TcpDnsFailed dnsFailed; } } } From 68e1b0c38fe5d99a2a97e7b25f60cd8f596af898 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 17:24:58 +0100 Subject: [PATCH 100/167] fix mv http.idl --- .../stdout/internal/stream/HttpEventHandler.java | 12 ++++++------ .../src/main/resources/META-INF/zilla/http.idl | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index 90ede8ad9e..f6f03cbe9b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -21,10 +21,10 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.Array32FW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.HttpHeaderFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpResponseEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpResponseFW; public class HttpEventHandler extends EventHandler { @@ -56,7 +56,7 @@ public void handleEvent( { case AUTHORIZATION: { - HttpAuthorizationEventFW e = event.authorization(); + HttpAuthorizationFW e = event.authorization(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.printf(HTTP_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, @@ -65,7 +65,7 @@ public void handleEvent( } case REQUEST: { - HttpRequestEventFW e = event.request(); + HttpRequestFW e = event.request(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.format(HTTP_REQUEST_FORMAT, e.timestamp(), e.traceId(), namespace, binding, headersAsString(e.headers())); @@ -73,7 +73,7 @@ public void handleEvent( } case RESPONSE: { - HttpResponseEventFW e = event.response(); + HttpResponseFW e = event.response(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.format(HTTP_RESPONSE_FORMAT, e.timestamp(), e.traceId(), namespace, binding, headersAsString(e.headers())); diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index f630ef05be..37b291f378 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -65,27 +65,27 @@ scope http FAILURE (1) } - struct HttpAuthorizationEvent extends core::event::Event + struct HttpAuthorization extends core::event::Event { Result result; string8 identity; } - struct HttpRequestEvent extends core::event::Event + struct HttpRequest extends core::event::Event { HttpHeader[] headers; } - struct HttpResponseEvent extends core::event::Event + struct HttpResponse extends core::event::Event { HttpHeader[] headers; } union HttpEvent switch (HttpEventType) { - case AUTHORIZATION: HttpAuthorizationEvent authorization; - case REQUEST: HttpRequestEvent request; - case RESPONSE: HttpResponseEvent response; + case AUTHORIZATION: HttpAuthorization authorization; + case REQUEST: HttpRequest request; + case RESPONSE: HttpResponse response; } } } From e888bcf0c1fb6366ec29dffe8b80b5ddd5216eb6 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 17:29:02 +0100 Subject: [PATCH 101/167] fix mv kafka.idl --- .../exporter/stdout/internal/stream/KafkaEventHandler.java | 4 ++-- .../src/main/resources/META-INF/zilla/kafka.idl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index 612ed27cf5..16834b6064 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -20,7 +20,7 @@ import org.agrona.DirectBuffer; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaAuthorizationEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaAuthorizationFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; public class KafkaEventHandler extends EventHandler @@ -51,7 +51,7 @@ public void handleEvent( { case AUTHORIZATION: { - KafkaAuthorizationEventFW e = event.authorization(); + KafkaAuthorizationFW e = event.authorization(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.printf(KAFKA_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index ae378355be..d2e2a96dc3 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -548,14 +548,14 @@ scope kafka FAILURE (1) } - struct KafkaAuthorizationEvent extends core::event::Event + struct KafkaAuthorization extends core::event::Event { Result result; } union KafkaEvent switch (KafkaEventType) { - case AUTHORIZATION: KafkaAuthorizationEvent authorization; + case AUTHORIZATION: KafkaAuthorization authorization; case API_VERSION_REJECTED: core::event::Event apiVersionRejected; } } From 730ecaf2e552f2186b74f25bc17c10ba5f3ec43f Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 17:30:39 +0100 Subject: [PATCH 102/167] fix mv mqtt.idl --- .../exporter/stdout/internal/stream/MqttEventHandler.java | 4 ++-- .../src/main/resources/META-INF/zilla/mqtt.idl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index 0b97e9f576..34e329bf2a 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -19,7 +19,7 @@ import org.agrona.DirectBuffer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; public class MqttEventHandler extends EventHandler @@ -47,7 +47,7 @@ public void handleEvent( switch (event.kind()) { case AUTHORIZATION: - MqttAuthorizationEventFW e = event.authorization(); + MqttAuthorizationFW e = event.authorization(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.printf(MQTT_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, diff --git a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl index b88d28ce96..89a4c1ec8a 100644 --- a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl +++ b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl @@ -276,7 +276,7 @@ scope mqtt FAILURE (1) } - struct MqttAuthorizationEvent extends core::event::Event + struct MqttAuthorization extends core::event::Event { Result result; string8 identity; @@ -284,7 +284,7 @@ scope mqtt union MqttEvent switch (MqttEventType) { - case AUTHORIZATION: MqttAuthorizationEvent authorization; + case AUTHORIZATION: MqttAuthorization authorization; } } } From 4c4b0e6300428662a27f89a1609eb33b9dbbfcc0 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 17:34:01 +0100 Subject: [PATCH 103/167] fix mv schema_registry.idl --- .../src/main/resources/META-INF/zilla/schema_registry.idl | 4 ++-- .../stdout/internal/stream/SchemaRegistryEventHandler.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl index a9125e3964..e4e5d74067 100644 --- a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl +++ b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl @@ -21,7 +21,7 @@ scope schema_registry REMOTE_ACCESS_REJECTED (1) } - struct SchemaRegistryRemoteAccessRejectedEvent extends core::event::Event + struct SchemaRegistryRemoteAccessRejected extends core::event::Event { string16 url; string8 method; @@ -30,7 +30,7 @@ scope schema_registry union SchemaRegistryEvent switch (SchemaRegistryEventType) { - case REMOTE_ACCESS_REJECTED: SchemaRegistryRemoteAccessRejectedEvent remoteAccessRejected; + case REMOTE_ACCESS_REJECTED: SchemaRegistryRemoteAccessRejected remoteAccessRejected; } } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index fd8b5a21ef..4dec65fca6 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -20,7 +20,7 @@ import org.agrona.DirectBuffer; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryRemoteAccessRejectedEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryRemoteAccessRejectedFW; public class SchemaRegistryEventHandler extends EventHandler { @@ -48,7 +48,7 @@ public void handleEvent( switch (event.kind()) { case REMOTE_ACCESS_REJECTED: - SchemaRegistryRemoteAccessRejectedEventFW e = event.remoteAccessRejected(); + SchemaRegistryRemoteAccessRejectedFW e = event.remoteAccessRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.printf(REMOTE_ACCESS_REJECTED, e.timestamp(), e.traceId(), namespace, binding, asString(e.url()), From f359b76d845caa42d8604d39d24f4e93e9e74e0d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 17:36:22 +0100 Subject: [PATCH 104/167] fix mv tls.idl --- .../exporter/stdout/internal/stream/TlsEventHandler.java | 4 ++-- .../src/main/resources/META-INF/zilla/tls.idl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index 5e949c304b..965146b0cc 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -20,7 +20,7 @@ import org.agrona.DirectBuffer; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsFailedEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsFailedFW; public class TlsEventHandler extends EventHandler { @@ -47,7 +47,7 @@ public void handleEvent( switch (event.kind()) { case TLS_FAILED: - TlsFailedEventFW e = event.tlsFailed(); + TlsFailedFW e = event.tlsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.printf(TLS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, e.error().get().name()); diff --git a/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl b/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl index aa6a1d8926..854e58fa87 100644 --- a/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl +++ b/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl @@ -31,14 +31,14 @@ scope tls UNSPECIFIED_ERROR (5) } - struct TlsFailedEvent extends core::event::Event + struct TlsFailed extends core::event::Event { TlsError error; } union TlsEvent switch (TlsEventType) { - case TLS_FAILED: TlsFailedEvent tlsFailed; + case TLS_FAILED: TlsFailed tlsFailed; } } } From 154f0ef856eead2b237fe927c9309e167406be9c Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 17:55:39 +0100 Subject: [PATCH 105/167] fix Clock --- .../registry/internal/SchemaRegistryEventContext.java | 8 ++++---- .../binding/http/internal/HttpEventContext.java | 8 ++++---- .../binding/kafka/internal/KafkaEventContext.java | 10 +++++----- .../binding/mqtt/internal/MqttEventContext.java | 8 ++++---- .../runtime/binding/tcp/internal/TcpEventContext.java | 8 ++++---- .../runtime/binding/tls/internal/TlsEventContext.java | 8 ++++---- .../aklivity/zilla/runtime/engine/EngineContext.java | 3 ++- .../runtime/engine/internal/registry/EngineWorker.java | 5 +++-- 8 files changed, 30 insertions(+), 28 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index c47db586ac..8e7333aca2 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -16,7 +16,7 @@ import java.net.http.HttpRequest; import java.nio.ByteBuffer; -import java.util.function.LongSupplier; +import java.time.Clock; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -33,14 +33,14 @@ public class SchemaRegistryEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int schemaRegistryTypeId; private final MessageConsumer eventWriter; - private final LongSupplier timestamp; + private final Clock clock; public SchemaRegistryEventContext( EngineContext context) { this.schemaRegistryTypeId = context.supplyTypeId(SchemaRegistryCatalog.NAME); this.eventWriter = context.supplyEventWriter(); - this.timestamp = context.timestamp(); + this.clock = context.clock(); } public void remoteAccessRejected( @@ -51,7 +51,7 @@ public void remoteAccessRejected( SchemaRegistryEventFW event = schemaRegistryEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessRejected(e -> e - .timestamp(timestamp.getAsLong()) + .timestamp(clock.millis()) .namespacedId(catalogId) .url(httpRequest.uri().toString()) .method(httpRequest.method()) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 4ccabf6310..6951d69281 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -16,8 +16,8 @@ package io.aklivity.zilla.runtime.binding.http.internal; import java.nio.ByteBuffer; +import java.time.Clock; import java.util.Map; -import java.util.function.LongSupplier; import org.agrona.concurrent.AtomicBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -41,14 +41,14 @@ public class HttpEventContext new Array32FW.Builder<>(new HttpHeaderFW.Builder(), new HttpHeaderFW()); private final int httpTypeId; private final MessageConsumer eventWriter; - private final LongSupplier timestamp; + private final Clock clock; public HttpEventContext( EngineContext context) { this.httpTypeId = context.supplyTypeId(HttpBinding.NAME); this.eventWriter = context.supplyEventWriter(); - this.timestamp = context.timestamp(); + this.clock = context.clock(); } public void authorization( @@ -61,7 +61,7 @@ public void authorization( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e - .timestamp(timestamp.getAsLong()) + .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) .result(r -> r.set(result)) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index ae1b7b271d..d0f2bed8ba 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -16,7 +16,7 @@ package io.aklivity.zilla.runtime.binding.kafka.internal; import java.nio.ByteBuffer; -import java.util.function.LongSupplier; +import java.time.Clock; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -35,14 +35,14 @@ public class KafkaEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int kafkaTypeId; private final MessageConsumer eventWriter; - private final LongSupplier timestamp; + private final Clock clock; public KafkaEventContext( EngineContext context) { this.kafkaTypeId = context.supplyTypeId(KafkaBinding.NAME); this.eventWriter = context.supplyEventWriter(); - this.timestamp = context.timestamp(); + this.clock = context.clock(); } public void authorization( @@ -54,7 +54,7 @@ public void authorization( KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e - .timestamp(timestamp.getAsLong()) + .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) .result(r -> r.set(result)) @@ -69,7 +69,7 @@ public void apiVersionRejected( KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .apiVersionRejected(e -> e - .timestamp(timestamp.getAsLong()) + .timestamp(clock.millis()) .traceId(traceId) ) .build(); diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 85e70b51c0..39d021bd28 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -16,7 +16,7 @@ package io.aklivity.zilla.runtime.binding.mqtt.internal; import java.nio.ByteBuffer; -import java.util.function.LongSupplier; +import java.time.Clock; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -34,14 +34,14 @@ public class MqttEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int mqttTypeId; private final MessageConsumer eventWriter; - private final LongSupplier timestamp; + private final Clock clock; public MqttEventContext( EngineContext context) { this.mqttTypeId = context.supplyTypeId(MqttBinding.NAME); this.eventWriter = context.supplyEventWriter(); - this.timestamp = context.timestamp(); + this.clock = context.clock(); } public void authorization( @@ -54,7 +54,7 @@ public void authorization( MqttEventFW event = mqttEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorization(e -> e - .timestamp(timestamp.getAsLong()) + .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) .result(r -> r.set(result)) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 6bf7315960..32211f0d3c 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -17,7 +17,7 @@ import java.net.InetSocketAddress; import java.nio.ByteBuffer; -import java.util.function.LongSupplier; +import java.time.Clock; import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; @@ -34,14 +34,14 @@ public class TcpEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int tcpTypeId; private final MessageConsumer eventWriter; - private final LongSupplier timestamp; + private final Clock clock; public TcpEventContext( EngineContext context) { this.tcpTypeId = context.supplyTypeId(TcpBinding.NAME); this.eventWriter = context.supplyEventWriter(); - this.timestamp = context.timestamp(); + this.clock = context.clock(); } public void dnsResolutionFailed( @@ -53,7 +53,7 @@ public void dnsResolutionFailed( TcpEventFW event = tcpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .dnsFailed(e -> e - .timestamp(timestamp.getAsLong()) + .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) .address(address) diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index b5f8a4a8b8..4d37c966d6 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -16,7 +16,7 @@ package io.aklivity.zilla.runtime.binding.tls.internal; import java.nio.ByteBuffer; -import java.util.function.LongSupplier; +import java.time.Clock; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLKeyException; @@ -39,14 +39,14 @@ public class TlsEventContext private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final int tlsTypeId; private final MessageConsumer eventWriter; - private final LongSupplier timestamp; + private final Clock clock; public TlsEventContext( EngineContext context) { this.tlsTypeId = context.supplyTypeId(TlsBinding.NAME); this.eventWriter = context.supplyEventWriter(); - this.timestamp = context.timestamp(); + this.clock = context.clock(); } public void tlsFailed( @@ -56,7 +56,7 @@ public void tlsFailed( TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsFailed(e -> e - .timestamp(timestamp.getAsLong()) + .timestamp(clock.millis()) .traceId(traceId) .error(r -> r.set(error)) ) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index b068850418..bb3a09aead 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -18,6 +18,7 @@ import java.net.InetAddress; import java.net.URL; import java.nio.channels.SelectableChannel; +import java.time.Clock; import java.util.function.LongSupplier; import org.agrona.MutableDirectBuffer; @@ -161,5 +162,5 @@ void onExporterDetached( MessageReader supplyEventReader(); - LongSupplier timestamp(); + Clock clock(); } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 04efcaa620..4f08dcc2ee 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -42,6 +42,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.channels.SelectableChannel; +import java.time.Clock; import java.time.Duration; import java.util.BitSet; import java.util.Collection; @@ -921,9 +922,9 @@ public MessageConsumer supplyEventWriter() } @Override - public LongSupplier timestamp() + public Clock clock() { - return () -> timestamps ? System.nanoTime() : 0L; + return Clock.systemUTC(); } private void onSystemMessage( From 31f69a855a289b395ea010ba1c8b66c3d675d308 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 18:14:45 +0100 Subject: [PATCH 106/167] fix EventReader inner class --- runtime/engine/pom.xml | 2 +- .../aklivity/zilla/runtime/engine/Engine.java | 82 ++++++++++--------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/runtime/engine/pom.xml b/runtime/engine/pom.xml index ccea03c210..0d951c1260 100644 --- a/runtime/engine/pom.xml +++ b/runtime/engine/pom.xml @@ -27,7 +27,7 @@ 11 11 0.77 - 3 + 4 diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java index e004ba07de..d6d2bda6ea 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/Engine.java @@ -99,10 +99,6 @@ public final class Engine implements Collector, AutoCloseable private final EngineConfiguration config; private Future watcherTaskRef; - private final EventFW eventRO = new EventFW(); - private int minWorkerIndex; - private long minTimeStamp; - Engine( EngineConfiguration config, Collection bindings, @@ -488,43 +484,9 @@ public long[][] histogramIds() return worker.histogramIds(); } - public int readEvent( - MessageConsumer handler, - int messageCountLimit) - { - int messagesRead = 0; - boolean empty = false; - while (!empty && messagesRead < messageCountLimit) - { - int eventCount = 0; - minWorkerIndex = 0; - minTimeStamp = Long.MAX_VALUE; - for (int j = 0; j < workers.size(); j++) - { - final int workerIndex = j; - int eventPeeked = workers.get(workerIndex).peekEvent((m, b, i, l) -> - { - eventRO.wrap(b, i, i + l); - if (eventRO.timestamp() < minTimeStamp) - { - minTimeStamp = eventRO.timestamp(); - minWorkerIndex = workerIndex; - } - }); - eventCount += eventPeeked; - } - empty = eventCount == 0; - if (!empty) - { - messagesRead += workers.get(minWorkerIndex).readEvent(handler, 1); - } - } - return messagesRead; - } - public MessageReader supplyEventReader() { - return this::readEvent; + return new EventReader(); } public String supplyLocalName( @@ -541,6 +503,48 @@ public int supplyLabelId( return worker.supplyTypeId(label); } + private final class EventReader implements MessageReader + { + private final EventFW eventRO = new EventFW(); + private int minWorkerIndex; + private long minTimeStamp; + + @Override + public int read( + MessageConsumer handler, + int messageCountLimit) + { + int messagesRead = 0; + boolean empty = false; + while (!empty && messagesRead < messageCountLimit) + { + int eventCount = 0; + minWorkerIndex = 0; + minTimeStamp = Long.MAX_VALUE; + for (int j = 0; j < workers.size(); j++) + { + final int workerIndex = j; + int eventPeeked = workers.get(workerIndex).peekEvent((m, b, i, l) -> + { + eventRO.wrap(b, i, i + l); + if (eventRO.timestamp() < minTimeStamp) + { + minTimeStamp = eventRO.timestamp(); + minWorkerIndex = workerIndex; + } + }); + eventCount += eventPeeked; + } + empty = eventCount == 0; + if (!empty) + { + messagesRead += workers.get(minWorkerIndex).readEvent(handler, 1); + } + } + return messagesRead; + } + } + // visible for testing public final class ContextImpl implements EngineExtContext { From 853f794f4873b6d5030849debba8a0fad32404ac Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 20 Feb 2024 18:20:06 +0100 Subject: [PATCH 107/167] fix timestamp --- .../zilla/runtime/binding/http/internal/HttpEventContext.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 6951d69281..a56ca48011 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -79,6 +79,7 @@ public void request( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .request(e -> e + .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) .headers(headers)) @@ -104,6 +105,7 @@ public void response( HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .response(e -> e + .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) .headers(headers)) From 4f9009d928c04dfe37b5f7329569402607c73f31 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 08:57:55 +0100 Subject: [PATCH 108/167] fix kafka --- .../stream/KafkaClientGroupFactory.java | 12 +++++------ .../KafkaClientOffsetCommitFactory.java | 2 +- .../stream/KafkaClientOffsetFetchFactory.java | 2 +- .../stream/KafkaClientSaslHandshaker.java | 20 +++++++++---------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java index 4ac2bbbfd8..a5999b3b25 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java @@ -878,7 +878,7 @@ private int decodeFindCoordinatorResponse( findCoordinatorResponse.host(), findCoordinatorResponse.port()); break; default: - onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeClusterReject; break; @@ -1013,7 +1013,7 @@ private int decodeJoinGroupResponse( joinGroupResponse.memberId().asString()); break; default: - onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1073,7 +1073,7 @@ private int decodeSyncGroupResponse( client.onSyncGroupResponse(traceId, authorization, syncGroupResponse.assignment()); break; default: - onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1136,7 +1136,7 @@ private int decodeHeartbeatResponse( client.onHeartbeatResponse(traceId, authorization); break; default: - onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1201,7 +1201,7 @@ private int decodeLeaveGroupResponse( } else { - onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } @@ -1216,7 +1216,7 @@ private int decodeLeaveGroupResponse( } else { - onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java index ff4c276882..54eadfe84b 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java @@ -589,7 +589,7 @@ private int decodeOffsetCommitPartition( } else { - onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeReject; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java index f4966d55da..a99670ec69 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java @@ -661,7 +661,7 @@ private int decodeOffsetFetchPartition( client.decoder = decodeOffsetFetchPartitions; break; default: - onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, errorCode); client.errorCode = errorCode; client.decoder = decodeReject; break; diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index f5fb387af7..d216d9a2e6 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -427,6 +427,16 @@ private void doEncodeSaslScramFinalAuthenticateRequest( doDecodeSaslAuthenticateResponse(traceId); } + protected final void onDecodeResponseErrorCode( + long traceId, + int errorCode) + { + if (errorCode == ERROR_UNSUPPORTED_VERSION) + { + event.apiVersionRejected(traceId); + } + } + protected abstract void doNetworkData( long traceId, long budgetId, @@ -834,16 +844,6 @@ private String16FW createClientId( return clientId != null ? new String16FW(clientId) : KAFKA_CLIENT_ID_DEFAULT_VALUE; } - protected void onDecodeResponseErrorCode( - long traceId, - int errorCode) - { - if (errorCode == ERROR_UNSUPPORTED_VERSION) - { - event.apiVersionRejected(traceId); - } - } - public byte[] hmac(byte[] key, byte[] bytes) { try From 68d6ffd132a48b25b62ccb05fa2e070fac16cf4a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 09:01:18 +0100 Subject: [PATCH 109/167] fix tcp --- .../tcp/internal/stream/TcpClientFactory.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index c0c4084725..f27fad9f08 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -259,26 +259,29 @@ private void doNetConnect( { try { - state = TcpState.openingInitial(state); - net.setOption(SO_KEEPALIVE, options != null && options.keepalive); - - if (net.connect(remoteAddress)) + try { - onNetConnected(); + state = TcpState.openingInitial(state); + net.setOption(SO_KEEPALIVE, options != null && options.keepalive); + + if (net.connect(remoteAddress)) + { + onNetConnected(); + } + else + { + networkKey = supplyPollerKey.apply(net); + networkKey.handler(OP_CONNECT, this::onNetConnect); + networkKey.register(OP_CONNECT); + } } - else + catch (UnresolvedAddressException ex) { - networkKey = supplyPollerKey.apply(net); - networkKey.handler(OP_CONNECT, this::onNetConnect); - networkKey.register(OP_CONNECT); + event.dnsResolutionFailed(traceId, routedId, remoteAddress); + throw ex; } } - catch (UnresolvedAddressException ex) - { - event.dnsResolutionFailed(traceId, routedId, remoteAddress); - onNetRejected(); - } - catch (IOException ex) + catch (UnresolvedAddressException | IOException ex) { onNetRejected(); } @@ -293,11 +296,6 @@ private int onNetConnect( net.finishConnect(); onNetConnected(); } - catch (UnresolvedAddressException ex) - { - event.dnsResolutionFailed(0L, routedId, null); - onNetRejected(); - } catch (IOException ex) { onNetRejected(); From 856d40d776e6fd85cc5246d2b235768bb911cf7d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 09:03:14 +0100 Subject: [PATCH 110/167] fix engine --- .../java/io/aklivity/zilla/runtime/engine/EngineContext.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index bb3a09aead..061a05715b 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -68,10 +68,6 @@ long supplyPromiseId( long supplyTraceId(); - int readEvent( - MessageConsumer handler, - int messageCountLimit); - MessageConsumer supplySender( long streamId); From e2a4edfa6cf125947ec82f78ae689fabe8540c43 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 09:09:59 +0100 Subject: [PATCH 111/167] fix stdout exp --- incubator/exporter-stdout/pom.xml | 4 +- .../stdout/internal/StdoutConfiguration.java | 32 +++ .../stdout/internal/StdoutExporter.java | 5 +- .../internal/StdoutExporterContext.java | 7 +- .../internal/StdoutExporterFactorySpi.java | 3 +- .../internal/StdoutExporterHandler.java | 8 +- .../internal/StdoutExporterHandlerTest.java | 187 ------------------ 7 files changed, 43 insertions(+), 203 deletions(-) create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutConfiguration.java delete mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 4194b774b3..9293a5415c 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,8 +26,8 @@ 11 11 - 0.90 - 0 + 0.05 + 10 diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutConfiguration.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutConfiguration.java new file mode 100644 index 0000000000..9d47705dec --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutConfiguration.java @@ -0,0 +1,32 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal; + +import java.io.PrintStream; + +import io.aklivity.zilla.runtime.engine.Configuration; + +public class StdoutConfiguration extends Configuration +{ + public StdoutConfiguration( + Configuration config) + { + } + + public PrintStream output() + { + return System.out; + } +} diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporter.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporter.java index 8e63ed8338..3e606c2d64 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporter.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporter.java @@ -16,7 +16,6 @@ import java.net.URL; -import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.Exporter; import io.aklivity.zilla.runtime.engine.exporter.ExporterContext; @@ -25,10 +24,10 @@ public class StdoutExporter implements Exporter { public static final String NAME = "stdout"; - private final EngineConfiguration config; + private final StdoutConfiguration config; public StdoutExporter( - EngineConfiguration config) + StdoutConfiguration config) { this.config = config; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java index 7d038890a7..c01aba6dc4 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.function.LongFunction; -import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.config.AttributeConfig; import io.aklivity.zilla.runtime.engine.config.ExporterConfig; @@ -29,11 +28,11 @@ public class StdoutExporterContext implements ExporterContext { - private final EngineConfiguration config; + private final StdoutConfiguration config; private final EngineContext context; public StdoutExporterContext( - EngineConfiguration config, + StdoutConfiguration config, EngineContext context) { this.config = config; @@ -48,7 +47,7 @@ public ExporterHandler attach( LongFunction resolveKind) { StdoutExporterConfig stdoutExporter = new StdoutExporterConfig(exporter); - return new StdoutExporterHandler(config, context, stdoutExporter, System.out); + return new StdoutExporterHandler(config, context, stdoutExporter); } @Override diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactorySpi.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactorySpi.java index 1497dd382a..a22c55f81f 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactorySpi.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterFactorySpi.java @@ -15,7 +15,6 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal; import io.aklivity.zilla.runtime.engine.Configuration; -import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.exporter.Exporter; import io.aklivity.zilla.runtime.engine.exporter.ExporterFactorySpi; @@ -31,6 +30,6 @@ public String type() public Exporter create( Configuration config) { - return new StdoutExporter(new EngineConfiguration(config)); + return new StdoutExporter(new StdoutConfiguration(config)); } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 48b38f6230..24e6ff234f 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -16,7 +16,6 @@ import java.io.PrintStream; -import io.aklivity.zilla.runtime.engine.EngineConfiguration; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.exporter.ExporterHandler; import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; @@ -30,13 +29,12 @@ public class StdoutExporterHandler implements ExporterHandler private StdoutEventsStream stdoutEventsStream; public StdoutExporterHandler( - EngineConfiguration config, + StdoutConfiguration config, EngineContext context, - StdoutExporterConfig exporter, - PrintStream out) + StdoutExporterConfig exporter) { this.context = context; - this.out = out; + this.out = config.output(); } @Override diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java deleted file mode 100644 index 90452a581e..0000000000 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandlerTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc - * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at - * - * https://www.aklivity.io/aklivity-community-license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package io.aklivity.zilla.runtime.exporter.stdout.internal; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.agrona.MutableDirectBuffer; -import org.agrona.concurrent.UnsafeBuffer; -import org.junit.Test; - -import io.aklivity.zilla.runtime.engine.EngineConfiguration; -import io.aklivity.zilla.runtime.engine.EngineContext; -import io.aklivity.zilla.runtime.engine.config.ExporterConfig; -import io.aklivity.zilla.runtime.engine.internal.layouts.EventsLayout; -import io.aklivity.zilla.runtime.exporter.stdout.internal.config.StdoutExporterConfig; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.Result; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsError; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; - -public class StdoutExporterHandlerTest -{ - private static final Path ENGINE_PATH = Paths.get("target/zilla-itests"); - private static final Path EVENTS_PATH = ENGINE_PATH.resolve("events"); - private static final int CAPACITY = 1024; - private static final int HTTP_TYPE_ID = 1; - private static final int KAFKA_TYPE_ID = 2; - private static final int MQTT_TYPE_ID = 3; - private static final int SCHEMA_REGISTRY_TYPE_ID = 4; - private static final int TCP_TYPE_ID = 5; - private static final int TLS_TYPE_ID = 6; - private static final String EXPECTED_OUTPUT = - "HTTP Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + - "[identity = identity]\n" + - "HTTP Request [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + - "[name1 = value1] [name2 = value2] \n" + - "HTTP Response [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + - "[name1 = value1] [name2 = value2] \n" + - "Kafka Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + - "Kafka API Version Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding]\n" + - "MQTT Authorization Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + - "[identity = identity]\n" + - "Schema Registry Remote Access Rejected [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] " + - "[url = url] [method = method] [status = 42]\n" + - "TCP DNS Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] [address = address]\n" + - "TLS Failed [timestamp = 77] [traceId = 0x0000000000000042] [binding = ns.binding] [error = HANDSHAKE_ERROR]\n"; - - @Test - public void shouldStart() - { - // GIVEN - EventsLayout layout = new EventsLayout.Builder() - .path(EVENTS_PATH) - .capacity(CAPACITY) - .build(); - MutableDirectBuffer eventBuffer = new UnsafeBuffer(new byte[64]); - HttpEventFW httpAuthorizationEvent = new HttpEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorization(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - .result(r -> r.set(Result.FAILURE)) - .identity("identity") - ).build(); - layout.writeEvent(HTTP_TYPE_ID, httpAuthorizationEvent.buffer(), 0, httpAuthorizationEvent.sizeof()); - HttpEventFW httpRequestEvent = new HttpEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .request(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - .headersItem(h -> h.name("name1").value("value1")) - .headersItem(h -> h.name("name2").value("value2")) - ).build(); - layout.writeEvent(HTTP_TYPE_ID, httpRequestEvent.buffer(), 0, httpRequestEvent.sizeof()); - HttpEventFW httpResponseEvent = new HttpEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .response(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - .headersItem(h -> h.name("name1").value("value1")) - .headersItem(h -> h.name("name2").value("value2")) - ).build(); - layout.writeEvent(HTTP_TYPE_ID, httpResponseEvent.buffer(), 0, httpResponseEvent.sizeof()); - KafkaEventFW kafkaAuthorizationEvent = new KafkaEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorization(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - .result(r -> r.set(Result.FAILURE)) - ).build(); - layout.writeEvent(KAFKA_TYPE_ID, kafkaAuthorizationEvent.buffer(), 0, kafkaAuthorizationEvent.sizeof()); - KafkaEventFW kafkaApiVersionRejectedEvent = new KafkaEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .apiVersionRejected(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - ).build(); - layout.writeEvent(KAFKA_TYPE_ID, kafkaApiVersionRejectedEvent.buffer(), 0, kafkaApiVersionRejectedEvent.sizeof()); - MqttEventFW mqttAuthorizationEvent = new MqttEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorization(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - .result(r -> r.set(Result.FAILURE)) - .identity("identity") - ).build(); - layout.writeEvent(MQTT_TYPE_ID, mqttAuthorizationEvent.buffer(), 0, mqttAuthorizationEvent.sizeof()); - SchemaRegistryEventFW schemaRegistryAuthorizationEvent = new SchemaRegistryEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .remoteAccessRejected(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - .url("url") - .method("method") - .status((short) 42) - ).build(); - layout.writeEvent(SCHEMA_REGISTRY_TYPE_ID, schemaRegistryAuthorizationEvent.buffer(), 0, - schemaRegistryAuthorizationEvent.sizeof()); - TcpEventFW tcpDnsResolutionFailedEvent = new TcpEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .dnsFailed(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - .address("address") - ).build(); - layout.writeEvent(TCP_TYPE_ID, tcpDnsResolutionFailedEvent.buffer(), 0, tcpDnsResolutionFailedEvent.sizeof()); - TlsEventFW tlsFailedEvent = new TlsEventFW.Builder() - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .tlsFailed(e -> e.timestamp(77) - .traceId(0x0000000000000042L) - .namespacedId(0x0000000200000007L) - .error(t -> t.set(TlsError.HANDSHAKE_ERROR)) - ).build(); - layout.writeEvent(TLS_TYPE_ID, tlsFailedEvent.buffer(), 0, tlsFailedEvent.sizeof()); - - EngineConfiguration config = mock(EngineConfiguration.class); - EngineContext context = mock(EngineContext.class); - StdoutExporterConfig exporter = new StdoutExporterConfig(mock(ExporterConfig.class)); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - PrintStream ps = new PrintStream(os); - when(context.lookupTypeId("http")).thenReturn(HTTP_TYPE_ID); - when(context.lookupTypeId("kafka")).thenReturn(KAFKA_TYPE_ID); - when(context.lookupTypeId("mqtt")).thenReturn(MQTT_TYPE_ID); - when(context.lookupTypeId("schema-registry")).thenReturn(SCHEMA_REGISTRY_TYPE_ID); - when(context.lookupTypeId("tcp")).thenReturn(TCP_TYPE_ID); - when(context.lookupTypeId("tls")).thenReturn(TLS_TYPE_ID); - when(context.supplyNamespace(0x0000000200000007L)).thenReturn("ns"); - when(context.supplyLocalName(0x0000000200000007L)).thenReturn("binding"); - when(context.supplyEventReader()).thenReturn(layout::readEvent); - StdoutExporterHandler handler = new StdoutExporterHandler(config, context, exporter, ps); - - // WHEN - handler.start(); - for (int i = 0; i < 42; i++) - { - handler.export(); - } - handler.stop(); - - // THEN - assertThat(os.toString(), equalTo(EXPECTED_OUTPUT)); - } -} From 65597003c2b55553f15b1c062f68f291f7e2fb1c Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 09:16:40 +0100 Subject: [PATCH 112/167] fix tcp --- .../zilla/runtime/binding/tcp/internal/TcpEventContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 32211f0d3c..1ee5ea2870 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -49,7 +49,7 @@ public void dnsResolutionFailed( long routedId, InetSocketAddress remoteAddress) { - String address = remoteAddress == null ? "" : remoteAddress.toString(); + String address = remoteAddress == null ? "" : remoteAddress.getHostString(); TcpEventFW event = tcpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .dnsFailed(e -> e From 72612333faa9905c9f7dad6ec888c4b8133be0d4 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 09:20:35 +0100 Subject: [PATCH 113/167] fix supplyTypeId --- .../exporter/stdout/internal/StdoutExporterHandler.java | 2 +- .../stdout/internal/stream/StdoutEventsStream.java | 8 ++++---- .../io/aklivity/zilla/runtime/engine/EngineContext.java | 3 --- .../zilla/runtime/engine/internal/LabelManager.java | 7 ------- .../runtime/engine/internal/registry/EngineWorker.java | 7 ------- 5 files changed, 5 insertions(+), 22 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 24e6ff234f..63fefe04a9 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -41,7 +41,7 @@ public StdoutExporterHandler( public void start() { stdoutEventsStream = new StdoutEventsStream(context.supplyEventReader(), context::supplyNamespace, - context::supplyLocalName, context::lookupTypeId, out); + context::supplyLocalName, context::supplyTypeId, out); } @Override diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 23751492b3..936eabbf29 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -27,18 +27,18 @@ public class StdoutEventsStream { private final MessageReader readEvent; - private final ToIntFunction lookupTypeId; + private final ToIntFunction supplyTypeId; private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( MessageReader readEvent, LongFunction supplyNamespace, LongFunction supplyLocalName, - ToIntFunction lookupTypeId, + ToIntFunction supplyTypeId, PrintStream out) { this.readEvent = readEvent; - this.lookupTypeId = lookupTypeId; + this.supplyTypeId = supplyTypeId; final HttpEventHandler httpEventHandler = new HttpEventHandler(supplyNamespace, supplyLocalName, out); final KafkaEventHandler kafkaEventHandler = new KafkaEventHandler(supplyNamespace, supplyLocalName, out); @@ -67,7 +67,7 @@ private void addEventHandler( String type, MessageConsumer consumer) { - int labelId = lookupTypeId.applyAsInt(type); + int labelId = supplyTypeId.applyAsInt(type); if (labelId != 0) { eventHandlers.put(labelId, consumer); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 061a05715b..03d54e65d3 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -50,9 +50,6 @@ public interface EngineContext int supplyTypeId( String name); - int lookupTypeId( - String name); - long supplyInitialId( long bindingId); diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/LabelManager.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/LabelManager.java index 2855d6485b..c29ecb95ee 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/LabelManager.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/LabelManager.java @@ -61,13 +61,6 @@ public synchronized int supplyLabelId( return labelIds.computeIfAbsent(label, this::nextLabelId); } - public synchronized int lookupLabelId( - String label) - { - checkSnapshot(); - return labelIds.getOrDefault(label, 0); - } - public synchronized String lookupLabel( int labelId) { diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index 4f08dcc2ee..e06acbce46 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -461,13 +461,6 @@ public int supplyTypeId( return labels.supplyLabelId(name); } - @Override - public int lookupTypeId( - String name) - { - return labels.lookupLabelId(name); - } - @Override public long supplyInitialId( long bindingId) From fa8db9b76b9a359093f86071b5a8ab6fcf619d24 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 10:18:46 +0100 Subject: [PATCH 114/167] fix tls --- .../internal/stream/TlsEventHandler.java | 50 ++- .../binding/tls/internal/TlsEventContext.java | 94 +++-- .../tls/internal/stream/TlsClientFactory.java | 300 +++++++++++----- .../tls/internal/stream/TlsServerFactory.java | 329 ++++++++++++------ .../src/main/resources/META-INF/zilla/tls.idl | 26 +- 5 files changed, 542 insertions(+), 257 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index 965146b0cc..7c477ec986 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -19,13 +19,21 @@ import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsFailedFW; public class TlsEventHandler extends EventHandler { private static final String TLS_FAILED_FORMAT = - "TLS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [error = %s]%n"; + "TLS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String TLS_PROTOCOL_REJECTED = + "TLS Protocol Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String TLS_KEY_REJECTED = + "TLS Key Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String TLS_PEER_NOT_VERIFIED = + "TLS Peer Not Verified [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String TLS_HANDSHAKE_FAILED = + "TLS Handshake Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); @@ -47,11 +55,45 @@ public void handleEvent( switch (event.kind()) { case TLS_FAILED: - TlsFailedFW e = event.tlsFailed(); + { + EventFW e = event.tlsFailed(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(TLS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding); + break; + } + case TLS_PROTOCOL_REJECTED: + { + EventFW e = event.tlsProtocolRejected(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(TLS_PROTOCOL_REJECTED, e.timestamp(), e.traceId(), namespace, binding); + break; + } + case TLS_KEY_REJECTED: + { + EventFW e = event.tlsKeyRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, e.error().get().name()); + out.printf(TLS_KEY_REJECTED, e.timestamp(), e.traceId(), namespace, binding); break; } + case TLS_PEER_NOT_VERIFIED: + { + EventFW e = event.tlsPeerNotVerified(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(TLS_PEER_NOT_VERIFIED, e.timestamp(), e.traceId(), namespace, binding); + break; + } + case TLS_HANDSHAKE_FAILED: + { + EventFW e = event.tlsHandshakeFailed(); + String namespace = supplyNamespace.apply(e.namespacedId()); + String binding = supplyLocalName.apply(e.namespacedId()); + out.printf(TLS_HANDSHAKE_FAILED, e.timestamp(), e.traceId(), namespace, binding); + break; + } + } } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index 4d37c966d6..ef4e8c430e 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -18,15 +18,9 @@ import java.nio.ByteBuffer; import java.time.Clock; -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.SSLKeyException; -import javax.net.ssl.SSLPeerUnverifiedException; -import javax.net.ssl.SSLProtocolException; - import org.agrona.MutableDirectBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsError; import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -50,45 +44,77 @@ public TlsEventContext( } public void tlsFailed( - TlsError error, - long traceId) + long traceId, + long routedId) { TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) - .error(r -> r.set(error)) + .namespacedId(routedId) ) .build(); eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); } - public void tlsFailed( - Exception ex, - long traceId) + public void tlsProtocolRejected( + long traceId, + long routedId) + { + TlsEventFW event = tlsEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .tlsProtocolRejected(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(routedId) + ) + .build(); + eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); + } + + public void tlsKeyRejected( + long traceId, + long routedId) { - TlsError error; - if (ex instanceof SSLProtocolException) - { - error = TlsError.PROTOCOL_ERROR; - } - else if (ex instanceof SSLKeyException) - { - error = TlsError.KEY_ERROR; - } - else if (ex instanceof SSLHandshakeException) - { - error = TlsError.HANDSHAKE_ERROR; - } - else if (ex instanceof SSLPeerUnverifiedException) - { - error = TlsError.PEER_UNVERIFIED_ERROR; - } - else - { - error = TlsError.UNSPECIFIED_ERROR; - } - tlsFailed(error, traceId); + TlsEventFW event = tlsEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .tlsKeyRejected(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(routedId) + ) + .build(); + eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); + } + + public void tlsPeerNotVerified( + long traceId, + long routedId) + { + TlsEventFW event = tlsEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .tlsKeyRejected(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(routedId) + ) + .build(); + eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); + } + + public void tlsHandshakeFailed( + long traceId, + long routedId) + { + TlsEventFW event = tlsEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .tlsKeyRejected(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(routedId) + ) + .build(); + eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index f9b14c805a..441ce68949 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -37,6 +37,10 @@ import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLEngineResult.HandshakeStatus; import javax.net.ssl.SSLException; +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLKeyException; +import javax.net.ssl.SSLPeerUnverifiedException; +import javax.net.ssl.SSLProtocolException; import org.agrona.DirectBuffer; import org.agrona.MutableDirectBuffer; @@ -52,7 +56,6 @@ import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsRecordInfoFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedDataFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedInfoFW; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsError; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.DataFW; @@ -572,56 +575,84 @@ private int decodeNotHandshaking( try { - final SSLEngineResult result = client.tlsEngine.unwrap(inNetByteBuffer, outAppByteBuffer); - final int bytesProduced = result.bytesProduced(); - final int bytesConsumed = result.bytesConsumed(); - - switch (result.getStatus()) + try { - case BUFFER_UNDERFLOW: - case BUFFER_OVERFLOW: - assert false; - break; - case OK: - if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) + final SSLEngineResult result = client.tlsEngine.unwrap(inNetByteBuffer, outAppByteBuffer); + final int bytesProduced = result.bytesProduced(); + final int bytesConsumed = result.bytesConsumed(); + + switch (result.getStatus()) { - if (!client.stream.isPresent()) + case BUFFER_UNDERFLOW: + case BUFFER_OVERFLOW: + assert false; + break; + case OK: + if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) { - client.onDecodeHandshakeFinished(traceId, budgetId); + if (!client.stream.isPresent()) + { + client.onDecodeHandshakeFinished(traceId, budgetId); + } } - } - if (bytesProduced == 0) - { - client.decoder = decodeHandshake; - progress += bytesConsumed; - } - else - { - assert bytesConsumed == tlsRecordBytes; - assert bytesProduced <= bytesConsumed : String.format("%d <= %d", bytesProduced, bytesConsumed); + if (bytesProduced == 0) + { + client.decoder = decodeHandshake; + progress += bytesConsumed; + } + else + { + assert bytesConsumed == tlsRecordBytes; + assert bytesProduced <= bytesConsumed : + String.format("%d <= %d", bytesProduced, bytesConsumed); - tlsUnwrappedDataRW.wrap(buffer, tlsRecordDataOffset, tlsRecordDataLimit) - .payload(outAppBuffer, 0, bytesProduced) - .build(); + tlsUnwrappedDataRW.wrap(buffer, tlsRecordDataOffset, tlsRecordDataLimit) + .payload(outAppBuffer, 0, bytesProduced) + .build(); - client.decodableRecordBytes -= bytesConsumed; - assert client.decodableRecordBytes == 0; + client.decodableRecordBytes -= bytesConsumed; + assert client.decodableRecordBytes == 0; - client.decoder = decodeNotHandshakingUnwrapped; + client.decoder = decodeNotHandshakingUnwrapped; + } + break; + case CLOSED: + assert bytesProduced == 0; + client.onDecodeInboundClosed(traceId); + client.decoder = TlsState.replyClosed(client.state) ? decodeIgnoreAll : decodeHandshake; + progress += bytesConsumed; + break; } - break; - case CLOSED: - assert bytesProduced == 0; - client.onDecodeInboundClosed(traceId); - client.decoder = TlsState.replyClosed(client.state) ? decodeIgnoreAll : decodeHandshake; - progress += bytesConsumed; - break; + } + catch (SSLProtocolException ex) + { + event.tlsProtocolRejected(traceId, client.routedId); + throw ex; + } + catch (SSLKeyException ex) + { + event.tlsKeyRejected(traceId, client.routedId); + throw ex; + } + catch (SSLPeerUnverifiedException ex) + { + event.tlsPeerNotVerified(traceId, client.routedId); + throw ex; + } + catch (SSLHandshakeException ex) + { + event.tlsHandshakeFailed(traceId, client.routedId); + throw ex; + } + catch (SSLException ex) + { + event.tlsFailed(traceId, client.routedId); + throw ex; } } catch (SSLException ex) { - event.tlsFailed(ex, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -755,41 +786,68 @@ private int decodeHandshakeNeedUnwrap( try { - final SSLEngineResult result = client.tlsEngine.unwrap(inNetByteBuffer, outAppByteBuffer); - final int bytesConsumed = result.bytesConsumed(); - final int bytesProduced = result.bytesProduced(); - - switch (result.getStatus()) + try { - case BUFFER_UNDERFLOW: - if (TlsState.replyClosed(client.state)) + final SSLEngineResult result = client.tlsEngine.unwrap(inNetByteBuffer, outAppByteBuffer); + final int bytesConsumed = result.bytesConsumed(); + final int bytesProduced = result.bytesProduced(); + + switch (result.getStatus()) { + case BUFFER_UNDERFLOW: + if (TlsState.replyClosed(client.state)) + { + client.decoder = decodeIgnoreAll; + } + break; + case BUFFER_OVERFLOW: + assert false; + break; + case OK: + assert bytesProduced == 0; + if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) + { + client.onDecodeHandshakeFinished(traceId, budgetId); + } + client.decoder = decodeHandshake; + break; + case CLOSED: + assert bytesProduced == 0; + client.onDecodeInboundClosed(traceId); client.decoder = decodeIgnoreAll; + break; } - break; - case BUFFER_OVERFLOW: - assert false; - break; - case OK: - assert bytesProduced == 0; - if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) - { - client.onDecodeHandshakeFinished(traceId, budgetId); - } - client.decoder = decodeHandshake; - break; - case CLOSED: - assert bytesProduced == 0; - client.onDecodeInboundClosed(traceId); - client.decoder = decodeIgnoreAll; - break; - } - progress += bytesConsumed; + progress += bytesConsumed; + } + catch (SSLProtocolException ex) + { + event.tlsProtocolRejected(traceId, client.routedId); + throw ex; + } + catch (SSLKeyException ex) + { + event.tlsKeyRejected(traceId, client.routedId); + throw ex; + } + catch (SSLPeerUnverifiedException ex) + { + event.tlsPeerNotVerified(traceId, client.routedId); + throw ex; + } + catch (SSLHandshakeException ex) + { + event.tlsHandshakeFailed(traceId, client.routedId); + throw ex; + } + catch (SSLException ex) + { + event.tlsFailed(traceId, client.routedId); + throw ex; + } } catch (SSLException ex) { - event.tlsFailed(ex, traceId); client.cleanupNet(traceId); client.decoder = decodeIgnoreAll; } @@ -1637,7 +1695,7 @@ private void onNetSignalHandshakeTimeout( final long traceId = signal.traceId(); cleanupNet(traceId); - event.tlsFailed(TlsError.HANDSHAKE_ERROR, traceId); + event.tlsHandshakeFailed(traceId, client.routedId); decoder = decodeIgnoreAll; } } @@ -1654,11 +1712,38 @@ private void doNetBegin( try { - tlsEngine.beginHandshake(); + try + { + tlsEngine.beginHandshake(); + } + catch (SSLProtocolException ex) + { + event.tlsProtocolRejected(traceId, client.routedId); + throw ex; + } + catch (SSLKeyException ex) + { + event.tlsKeyRejected(traceId, client.routedId); + throw ex; + } + catch (SSLPeerUnverifiedException ex) + { + event.tlsPeerNotVerified(traceId, client.routedId); + throw ex; + } + catch (SSLHandshakeException ex) + { + event.tlsHandshakeFailed(traceId, client.routedId); + throw ex; + } + catch (SSLException ex) + { + event.tlsFailed(traceId, client.routedId); + throw ex; + } } catch (SSLException ex) { - event.tlsFailed(TlsError.HANDSHAKE_ERROR, traceId); cleanupNet(traceId); } @@ -2006,42 +2091,69 @@ private void doEncodeWrap( try { - loop: - do + try { - final SSLEngineResult result = tlsEngine.wrap(inAppByteBuffer, outNetByteBuffer); - final int bytesProduced = result.bytesProduced(); - - switch (result.getStatus()) + loop: + do { - case BUFFER_OVERFLOW: - case BUFFER_UNDERFLOW: - assert false; - break; - case CLOSED: - assert bytesProduced > 0; - doAppReset(traceId); - state = TlsState.closingReply(state); - break loop; - case OK: - assert bytesProduced > 0 || tlsEngine.isInboundDone(); - if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) + final SSLEngineResult result = tlsEngine.wrap(inAppByteBuffer, outNetByteBuffer); + final int bytesProduced = result.bytesProduced(); + + switch (result.getStatus()) { - if (proactiveReplyBegin) + case BUFFER_OVERFLOW: + case BUFFER_UNDERFLOW: + assert false; + break; + case CLOSED: + assert bytesProduced > 0; + doAppReset(traceId); + state = TlsState.closingReply(state); + break loop; + case OK: + assert bytesProduced > 0 || tlsEngine.isInboundDone(); + if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) { - onDecodeHandshakeFinished(traceId, budgetId); + if (proactiveReplyBegin) + { + onDecodeHandshakeFinished(traceId, budgetId); + } } + break; } - break; - } - } while (inAppByteBuffer.hasRemaining()); + } while (inAppByteBuffer.hasRemaining()); - final int outNetBytesProduced = outNetByteBuffer.position(); - doNetData(traceId, budgetId, outNetBuffer, 0, outNetBytesProduced); + final int outNetBytesProduced = outNetByteBuffer.position(); + doNetData(traceId, budgetId, outNetBuffer, 0, outNetBytesProduced); + } + catch (SSLProtocolException ex) + { + event.tlsProtocolRejected(traceId, client.routedId); + throw ex; + } + catch (SSLKeyException ex) + { + event.tlsKeyRejected(traceId, client.routedId); + throw ex; + } + catch (SSLPeerUnverifiedException ex) + { + event.tlsPeerNotVerified(traceId, client.routedId); + throw ex; + } + catch (SSLHandshakeException ex) + { + event.tlsHandshakeFailed(traceId, client.routedId); + throw ex; + } + catch (SSLException ex) + { + event.tlsFailed(traceId, client.routedId); + throw ex; + } } catch (SSLException ex) { - event.tlsFailed(ex, traceId); cleanupNet(traceId); } } diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java index b51f2bde2f..91d30e9b3d 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsServerFactory.java @@ -42,7 +42,10 @@ import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLEngineResult.HandshakeStatus; import javax.net.ssl.SSLException; +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLKeyException; import javax.net.ssl.SSLPeerUnverifiedException; +import javax.net.ssl.SSLProtocolException; import javax.net.ssl.SSLSession; import javax.security.auth.x500.X500Principal; @@ -59,7 +62,6 @@ import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsRecordInfoFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedDataFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.codec.TlsUnwrappedInfoFW; -import io.aklivity.zilla.runtime.binding.tls.internal.types.event.TlsError; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.AbortFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.BeginFW; import io.aklivity.zilla.runtime.binding.tls.internal.types.stream.DataFW; @@ -527,12 +529,39 @@ private int decodeBeforeHandshake( { try { - server.tlsEngine.beginHandshake(); - server.decoder = decodeHandshake; + try + { + server.tlsEngine.beginHandshake(); + server.decoder = decodeHandshake; + } + catch (SSLProtocolException ex) + { + event.tlsProtocolRejected(traceId, server.routedId); + throw ex; + } + catch (SSLKeyException ex) + { + event.tlsKeyRejected(traceId, server.routedId); + throw ex; + } + catch (SSLPeerUnverifiedException ex) + { + event.tlsPeerNotVerified(traceId, server.routedId); + throw ex; + } + catch (SSLHandshakeException ex) + { + event.tlsHandshakeFailed(traceId, server.routedId); + throw ex; + } + catch (SSLException | RuntimeException ex) + { + event.tlsFailed(traceId, server.routedId); + throw ex; + } } catch (SSLException | RuntimeException ex) { - event.tlsFailed(ex, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -610,48 +639,76 @@ private int decodeNotHandshaking( try { - final SSLEngineResult result = server.tlsEngine.unwrap(inNetByteBuffer, outAppByteBuffer); - final int bytesProduced = result.bytesProduced(); - final int bytesConsumed = result.bytesConsumed(); - - switch (result.getStatus()) + try { - case BUFFER_UNDERFLOW: - case BUFFER_OVERFLOW: - assert false; - break; - case OK: - if (bytesProduced == 0) + final SSLEngineResult result = server.tlsEngine.unwrap(inNetByteBuffer, outAppByteBuffer); + final int bytesProduced = result.bytesProduced(); + final int bytesConsumed = result.bytesConsumed(); + + switch (result.getStatus()) { - server.decoder = decodeHandshake; + case BUFFER_UNDERFLOW: + case BUFFER_OVERFLOW: + assert false; + break; + case OK: + if (bytesProduced == 0) + { + server.decoder = decodeHandshake; + progress += bytesConsumed; + } + else + { + assert bytesConsumed == tlsRecordBytes; + assert bytesProduced <= bytesConsumed : + String.format("%d <= %d", bytesProduced, bytesConsumed); + + tlsUnwrappedDataRW.wrap(buffer, tlsRecordDataOffset, tlsRecordDataLimit) + .payload(outAppBuffer, 0, bytesProduced) + .build(); + + server.decodableRecordBytes -= bytesConsumed; + assert server.decodableRecordBytes == 0; + + server.decoder = decodeNotHandshakingUnwrapped; + } + break; + case CLOSED: + assert bytesProduced == 0; + server.onDecodeInboundClosed(traceId); + server.decoder = TlsState.initialClosed(server.state) ? decodeIgnoreAll : decodeHandshake; progress += bytesConsumed; + break; } - else - { - assert bytesConsumed == tlsRecordBytes; - assert bytesProduced <= bytesConsumed : String.format("%d <= %d", bytesProduced, bytesConsumed); - - tlsUnwrappedDataRW.wrap(buffer, tlsRecordDataOffset, tlsRecordDataLimit) - .payload(outAppBuffer, 0, bytesProduced) - .build(); - - server.decodableRecordBytes -= bytesConsumed; - assert server.decodableRecordBytes == 0; - - server.decoder = decodeNotHandshakingUnwrapped; - } - break; - case CLOSED: - assert bytesProduced == 0; - server.onDecodeInboundClosed(traceId); - server.decoder = TlsState.initialClosed(server.state) ? decodeIgnoreAll : decodeHandshake; - progress += bytesConsumed; - break; + } + catch (SSLProtocolException ex) + { + event.tlsProtocolRejected(traceId, server.routedId); + throw ex; + } + catch (SSLKeyException ex) + { + event.tlsKeyRejected(traceId, server.routedId); + throw ex; + } + catch (SSLPeerUnverifiedException ex) + { + event.tlsPeerNotVerified(traceId, server.routedId); + throw ex; + } + catch (SSLHandshakeException ex) + { + event.tlsHandshakeFailed(traceId, server.routedId); + throw ex; + } + catch (SSLException | RuntimeException ex) + { + event.tlsFailed(traceId, server.routedId); + throw ex; } } catch (SSLException | RuntimeException ex) { - event.tlsFailed(ex, traceId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; } @@ -785,59 +842,86 @@ private int decodeHandshakeNeedUnwrap( try { - final SSLEngineResult result = server.tlsEngine.unwrap(inNetByteBuffer, outAppByteBuffer); - final int bytesConsumed = result.bytesConsumed(); - final int bytesProduced = result.bytesProduced(); - - switch (result.getStatus()) + try { - case BUFFER_UNDERFLOW: - if (TlsState.initialClosed(server.state)) - { - server.decoder = decodeIgnoreAll; - } - break; - case BUFFER_OVERFLOW: - assert false; - break; - case OK: - final HandshakeStatus handshakeStatus = result.getHandshakeStatus(); - if (handshakeStatus == HandshakeStatus.FINISHED) - { - server.onDecodeHandshakeFinished(traceId, budgetId); - } + final SSLEngineResult result = server.tlsEngine.unwrap(inNetByteBuffer, outAppByteBuffer); + final int bytesConsumed = result.bytesConsumed(); + final int bytesProduced = result.bytesProduced(); - if (bytesProduced > 0 && handshakeStatus == HandshakeStatus.FINISHED) - { - final TlsRecordInfoFW tlsRecordInfo = tlsRecordInfoRW - .wrap(buffer, progress, progress + bytesConsumed) - .build(); - final int tlsRecordDataOffset = tlsRecordInfo.limit(); - final int tlsRecordDataLimit = tlsRecordDataOffset + tlsRecordInfo.length(); - - tlsUnwrappedDataRW.wrap(buffer, tlsRecordDataOffset, tlsRecordDataLimit) - .payload(outAppBuffer, 0, bytesProduced) - .build(); - server.decoder = decodeNotHandshakingUnwrapped; - } - else + switch (result.getStatus()) { - server.decoder = decodeHandshake; + case BUFFER_UNDERFLOW: + if (TlsState.initialClosed(server.state)) + { + server.decoder = decodeIgnoreAll; + } + break; + case BUFFER_OVERFLOW: + assert false; + break; + case OK: + final HandshakeStatus handshakeStatus = result.getHandshakeStatus(); + if (handshakeStatus == HandshakeStatus.FINISHED) + { + server.onDecodeHandshakeFinished(traceId, budgetId); + } + + if (bytesProduced > 0 && handshakeStatus == HandshakeStatus.FINISHED) + { + final TlsRecordInfoFW tlsRecordInfo = tlsRecordInfoRW + .wrap(buffer, progress, progress + bytesConsumed) + .build(); + final int tlsRecordDataOffset = tlsRecordInfo.limit(); + final int tlsRecordDataLimit = tlsRecordDataOffset + tlsRecordInfo.length(); + + tlsUnwrappedDataRW.wrap(buffer, tlsRecordDataOffset, tlsRecordDataLimit) + .payload(outAppBuffer, 0, bytesProduced) + .build(); + server.decoder = decodeNotHandshakingUnwrapped; + } + else + { + server.decoder = decodeHandshake; + } + + break; + case CLOSED: + assert bytesProduced == 0; + server.onDecodeInboundClosed(traceId); + server.decoder = decodeIgnoreAll; + break; } - break; - case CLOSED: - assert bytesProduced == 0; - server.onDecodeInboundClosed(traceId); - server.decoder = decodeIgnoreAll; - break; + progress += bytesConsumed; + } + catch (SSLProtocolException ex) + { + event.tlsProtocolRejected(traceId, server.routedId); + throw ex; + } + catch (SSLKeyException ex) + { + event.tlsKeyRejected(traceId, server.routedId); + throw ex; + } + catch (SSLPeerUnverifiedException ex) + { + event.tlsPeerNotVerified(traceId, server.routedId); + throw ex; + } + catch (SSLHandshakeException ex) + { + event.tlsHandshakeFailed(traceId, server.routedId); + throw ex; + } + catch (SSLException | RuntimeException ex) + { + event.tlsFailed(traceId, server.routedId); + throw ex; } - - progress += bytesConsumed; } catch (SSLException | RuntimeException ex) { - event.tlsFailed(ex, traceId); server.doEncodeWrapIfNecessary(traceId, budgetId); server.cleanupNet(traceId); server.decoder = decodeIgnoreAll; @@ -1316,7 +1400,7 @@ private void onNetSignalHandshakeTimeout( handshakeTimeoutFutureId = NO_CANCEL_ID; cleanupNet(traceId); - event.tlsFailed(TlsError.HANDSHAKE_ERROR, traceId); + event.tlsHandshakeFailed(traceId, routedId); decoder = decodeIgnoreAll; } } @@ -1660,40 +1744,67 @@ private void doEncodeWrap( try { - loop: - do + try { - final SSLEngineResult result = tlsEngine.wrap(inAppByteBuffer, outNetByteBuffer); - final int bytesProduced = result.bytesProduced(); - - switch (result.getStatus()) + loop: + do { - case BUFFER_OVERFLOW: - case BUFFER_UNDERFLOW: - assert false; - break; - case CLOSED: - assert bytesProduced > 0; - assert tlsEngine.isOutboundDone(); - stream.ifPresent(s -> s.doAppResetLater(traceId)); - state = TlsState.closingReply(state); - break loop; - case OK: - assert bytesProduced > 0 || tlsEngine.isInboundDone(); - if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) + final SSLEngineResult result = tlsEngine.wrap(inAppByteBuffer, outNetByteBuffer); + final int bytesProduced = result.bytesProduced(); + + switch (result.getStatus()) { - onDecodeHandshakeFinished(traceId, budgetId); + case BUFFER_OVERFLOW: + case BUFFER_UNDERFLOW: + assert false; + break; + case CLOSED: + assert bytesProduced > 0; + assert tlsEngine.isOutboundDone(); + stream.ifPresent(s -> s.doAppResetLater(traceId)); + state = TlsState.closingReply(state); + break loop; + case OK: + assert bytesProduced > 0 || tlsEngine.isInboundDone(); + if (result.getHandshakeStatus() == HandshakeStatus.FINISHED) + { + onDecodeHandshakeFinished(traceId, budgetId); + } + break; } - break; - } - } while (inAppByteBuffer.hasRemaining()); + } while (inAppByteBuffer.hasRemaining()); - final int outNetBytesProduced = outNetByteBuffer.position(); - doNetData(traceId, budgetId, outNetBuffer, 0, outNetBytesProduced); + final int outNetBytesProduced = outNetByteBuffer.position(); + doNetData(traceId, budgetId, outNetBuffer, 0, outNetBytesProduced); + } + catch (SSLProtocolException ex) + { + event.tlsProtocolRejected(traceId, routedId); + throw ex; + } + catch (SSLKeyException ex) + { + event.tlsKeyRejected(traceId, routedId); + throw ex; + } + catch (SSLPeerUnverifiedException ex) + { + event.tlsPeerNotVerified(traceId, routedId); + throw ex; + } + catch (SSLHandshakeException ex) + { + event.tlsHandshakeFailed(traceId, routedId); + throw ex; + } + catch (SSLException | RuntimeException ex) + { + event.tlsFailed(traceId, routedId); + throw ex; + } } catch (SSLException | RuntimeException ex) { - event.tlsFailed(ex, traceId); cleanupNet(traceId); } } diff --git a/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl b/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl index 854e58fa87..c81e96e2c7 100644 --- a/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl +++ b/specs/binding-tls.spec/src/main/resources/META-INF/zilla/tls.idl @@ -19,26 +19,20 @@ scope tls { enum TlsEventType (uint8) { - TLS_FAILED (1) - } - - enum TlsError (uint8) - { - PROTOCOL_ERROR (1), - KEY_ERROR (2), - HANDSHAKE_ERROR (3), - PEER_UNVERIFIED_ERROR (4), - UNSPECIFIED_ERROR (5) - } - - struct TlsFailed extends core::event::Event - { - TlsError error; + TLS_FAILED (1), + TLS_PROTOCOL_REJECTED (2), + TLS_KEY_REJECTED (3), + TLS_PEER_NOT_VERIFIED (4), + TLS_HANDSHAKE_FAILED (5) } union TlsEvent switch (TlsEventType) { - case TLS_FAILED: TlsFailed tlsFailed; + case TLS_FAILED: core::event::Event tlsFailed; + case TLS_PROTOCOL_REJECTED: core::event::Event tlsProtocolRejected; + case TLS_KEY_REJECTED: core::event::Event tlsKeyRejected; + case TLS_PEER_NOT_VERIFIED: core::event::Event tlsPeerNotVerified; + case TLS_HANDSHAKE_FAILED: core::event::Event tlsHandshakeFailed; } } } From df71e7f074b618095f7ca4912220435c3833adc7 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 10:47:24 +0100 Subject: [PATCH 115/167] fix rm http response --- .../stdout/internal/stream/HttpEventHandler.java | 9 --------- .../binding/http/internal/HttpEventContext.java | 16 ---------------- .../http/internal/stream/HttpServerFactory.java | 2 -- .../src/main/resources/META-INF/zilla/http.idl | 9 +-------- 4 files changed, 1 insertion(+), 35 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index f6f03cbe9b..e74b901ac9 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -24,7 +24,6 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpResponseFW; public class HttpEventHandler extends EventHandler { @@ -71,14 +70,6 @@ public void handleEvent( out.format(HTTP_REQUEST_FORMAT, e.timestamp(), e.traceId(), namespace, binding, headersAsString(e.headers())); break; } - case RESPONSE: - { - HttpResponseFW e = event.response(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.format(HTTP_RESPONSE_FORMAT, e.timestamp(), e.traceId(), namespace, binding, headersAsString(e.headers())); - break; - } } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index a56ca48011..d57832b6b8 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -96,20 +96,4 @@ public void request( headers.forEach((n, v) -> headersRW.item(i -> i.name(n).value(v))); request(traceId, routedId, headersRW.build()); } - - public void response( - long traceId, - long routedId, - Array32FW headers) - { - HttpEventFW event = httpEventRW - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .response(e -> e - .timestamp(clock.millis()) - .traceId(traceId) - .namespacedId(routedId) - .headers(headers)) - .build(); - eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); - } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 7fd42b5084..e9e5ebdf28 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -3000,7 +3000,6 @@ private void onResponseBegin( final HttpBeginExFW beginEx = begin.extension().get(beginExRO::tryWrap); final Array32FW headers = beginEx != null ? beginEx.headers() : DEFAULT_HEADERS; - event.response(traceId, routedId, headers); responseState = HttpExchangeState.OPEN; doEncodeHeaders(this, traceId, sessionId, 0L, headers); } @@ -6022,7 +6021,6 @@ private void onResponseBegin( header.name().equals(HEADER_CONTENT_LENGTH)); responseContentLength = contentLengthHeader != null ? parseInt(contentLengthHeader.value().asString()) : -1; - event.response(traceId, routedId, headers); doEncodeHeaders(traceId, authorization, streamId, policy, origin, headers, responseContentLength == 0); } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 37b291f378..9100090e7b 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -55,8 +55,7 @@ scope http enum HttpEventType (uint8) { AUTHORIZATION (1), - REQUEST (2), - RESPONSE (3) + REQUEST (2) } enum Result (uint8) @@ -76,16 +75,10 @@ scope http HttpHeader[] headers; } - struct HttpResponse extends core::event::Event - { - HttpHeader[] headers; - } - union HttpEvent switch (HttpEventType) { case AUTHORIZATION: HttpAuthorization authorization; case REQUEST: HttpRequest request; - case RESPONSE: HttpResponse response; } } } From d766096d4755b90fedbc93fa2f6531c6e186a963 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 10:57:20 +0100 Subject: [PATCH 116/167] fix http auth failure --- .../internal/stream/HttpEventHandler.java | 15 ++++------ .../http/internal/HttpEventContext.java | 28 +++++++++---------- .../internal/stream/HttpServerFactory.java | 4 +-- .../main/resources/META-INF/zilla/http.idl | 13 ++------- 4 files changed, 25 insertions(+), 35 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index e74b901ac9..c839aac806 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -21,18 +21,16 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.Array32FW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.HttpHeaderFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFailureFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestFW; public class HttpEventHandler extends EventHandler { - private static final String HTTP_AUTHORIZATION_FORMAT = - "HTTP Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + private static final String HTTP_AUTHORIZATION_FAILURE_FORMAT = + "HTTP Authorization Failure [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; private static final String HTTP_REQUEST_FORMAT = "HTTP Request [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; - private static final String HTTP_RESPONSE_FORMAT = - "HTTP Response [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -53,13 +51,12 @@ public void handleEvent( final HttpEventFW event = httpEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case AUTHORIZATION: + case AUTHORIZATION_FAILURE: { - HttpAuthorizationFW e = event.authorization(); + HttpAuthorizationFailureFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HTTP_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, - binding, asString(e.identity())); + out.printf(HTTP_AUTHORIZATION_FAILURE_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.identity())); break; } case REQUEST: diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index d57832b6b8..0f86462946 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -25,7 +25,6 @@ import io.aklivity.zilla.runtime.binding.http.internal.types.Array32FW; import io.aklivity.zilla.runtime.binding.http.internal.types.HttpHeaderFW; import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; -import io.aklivity.zilla.runtime.binding.http.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -51,24 +50,25 @@ public HttpEventContext( this.clock = context.clock(); } - public void authorization( + public void authorizationFailure( long sessionId, long traceId, long routedId, String identity) { - Result result = sessionId == 0 ? Result.FAILURE : Result.SUCCESS; - HttpEventFW event = httpEventRW - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorization(e -> e - .timestamp(clock.millis()) - .traceId(traceId) - .namespacedId(routedId) - .result(r -> r.set(result)) - .identity(identity) - ) - .build(); - eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + if (sessionId == 0) + { + HttpEventFW event = httpEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorizationFailure(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(routedId) + .identity(identity) + ) + .build(); + eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + } } public void request( diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index e9e5ebdf28..26dd953acd 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1059,7 +1059,7 @@ else if (!isCorsRequestAllowed(server.binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); - event.authorization(exchangeAuth, traceId, server.routedId, guard.identity(authorization)); + event.authorizationFailure(exchangeAuth, traceId, server.routedId, guard.identity(authorization)); } } @@ -4974,7 +4974,7 @@ else if (!isCorsRequestAllowed(binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(initialId, credentialsMatch); - event.authorization(exchangeAuth, traceId, routedId, guard.identity(authorization)); + event.authorizationFailure(exchangeAuth, traceId, routedId, guard.identity(authorization)); } } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 9100090e7b..3cb40cfdf9 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -54,19 +54,12 @@ scope http { enum HttpEventType (uint8) { - AUTHORIZATION (1), + AUTHORIZATION_FAILURE (1), REQUEST (2) } - enum Result (uint8) + struct HttpAuthorizationFailure extends core::event::Event { - SUCCESS (0), - FAILURE (1) - } - - struct HttpAuthorization extends core::event::Event - { - Result result; string8 identity; } @@ -77,7 +70,7 @@ scope http union HttpEvent switch (HttpEventType) { - case AUTHORIZATION: HttpAuthorization authorization; + case AUTHORIZATION_FAILURE: HttpAuthorizationFailure authorizationFailure; case REQUEST: HttpRequest request; } } From de6cdaf4d78b75fb3b037c6a5f74e20aa1fdf07c Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 11:04:26 +0100 Subject: [PATCH 117/167] fix kafka auth failure --- .../internal/stream/KafkaEventHandler.java | 11 ++++---- .../kafka/internal/KafkaEventContext.java | 26 +++++++++---------- .../stream/KafkaClientSaslHandshaker.java | 4 +-- .../main/resources/META-INF/zilla/kafka.idl | 15 ++--------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index 16834b6064..d178f719a1 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -20,13 +20,12 @@ import org.agrona.DirectBuffer; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaAuthorizationFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; public class KafkaEventHandler extends EventHandler { - private static final String KAFKA_AUTHORIZATION_FORMAT = - "Kafka Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String KAFKA_AUTHORIZATION_FAILURE_FORMAT = + "Kafka Authorization Failure [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; private static final String KAFKA_API_VERSION_REJECTED = "Kafka API Version Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; @@ -49,12 +48,12 @@ public void handleEvent( final KafkaEventFW event = kafkaEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case AUTHORIZATION: + case AUTHORIZATION_FAILURE: { - KafkaAuthorizationFW e = event.authorization(); + EventFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, + out.printf(KAFKA_AUTHORIZATION_FAILURE_FORMAT, e.timestamp(), e.traceId(), namespace, binding); break; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index d0f2bed8ba..b189187622 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -22,7 +22,6 @@ import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.KafkaEventFW; -import io.aklivity.zilla.runtime.binding.kafka.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -45,22 +44,23 @@ public KafkaEventContext( this.clock = context.clock(); } - public void authorization( + public void authorizationFailure( int errorCode, long traceId, long routedId) { - Result result = errorCode == ERROR_NONE ? Result.SUCCESS : Result.FAILURE; - KafkaEventFW event = kafkaEventRW - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorization(e -> e - .timestamp(clock.millis()) - .traceId(traceId) - .namespacedId(routedId) - .result(r -> r.set(result)) - ) - .build(); - eventWriter.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); + if (errorCode != ERROR_NONE) + { + KafkaEventFW event = kafkaEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorizationFailure(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(routedId) + ) + .build(); + eventWriter.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); + } } public void apiVersionRejected( diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index d216d9a2e6..b196e8c953 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -703,7 +703,7 @@ private int decodeSaslPlainAuthenticate( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); - event.authorization(errorCode, traceId, client.routedId); + event.authorizationFailure(errorCode, traceId, client.routedId); progress = authenticateResponse.limit(); @@ -738,7 +738,7 @@ private int decodeSaslScramAuthenticateFirst( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); - event.authorization(errorCode, traceId, client.routedId); + event.authorizationFailure(errorCode, traceId, client.routedId); progress = authenticateResponse.limit(); diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index d2e2a96dc3..b6f642eb6b 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -538,24 +538,13 @@ scope kafka { enum KafkaEventType (uint8) { - AUTHORIZATION (1), + AUTHORIZATION_FAILURE (1), API_VERSION_REJECTED (2) } - enum Result (uint8) - { - SUCCESS (0), - FAILURE (1) - } - - struct KafkaAuthorization extends core::event::Event - { - Result result; - } - union KafkaEvent switch (KafkaEventType) { - case AUTHORIZATION: KafkaAuthorization authorization; + case AUTHORIZATION_FAILURE: core::event::Event authorizationFailure; case API_VERSION_REJECTED: core::event::Event apiVersionRejected; } } From c57b3d22af868426aa583b34a2419955b99c5422 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 11:09:40 +0100 Subject: [PATCH 118/167] fix mqtt auth failure --- .../stdout/internal/stream/EventHandler.java | 8 ------ .../internal/stream/MqttEventHandler.java | 13 ++++----- .../mqtt/internal/MqttEventContext.java | 28 +++++++++---------- .../internal/stream/MqttServerFactory.java | 2 +- .../main/resources/META-INF/zilla/mqtt.idl | 13 ++------- 5 files changed, 24 insertions(+), 40 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java index 4397f7103a..a9e121c93e 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java @@ -20,8 +20,6 @@ import org.agrona.DirectBuffer; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.Result; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.ResultFW; public abstract class EventHandler { @@ -51,10 +49,4 @@ protected static String asString( String s = stringFW.asString(); return s == null ? "" : s; } - - protected static String result( - ResultFW result) - { - return result.get() == Result.SUCCESS ? "Succeeded" : "Failed"; - } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index 34e329bf2a..daa525348a 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -19,13 +19,13 @@ import org.agrona.DirectBuffer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationFailureFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; public class MqttEventHandler extends EventHandler { - private static final String MQTT_AUTHORIZATION_FORMAT = - "MQTT Authorization %s [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + private static final String MQTT_AUTHORIZATION_FAILURE_FORMAT = + "MQTT Authorization Failure [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); @@ -46,12 +46,11 @@ public void handleEvent( MqttEventFW event = mqttEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case AUTHORIZATION: - MqttAuthorizationFW e = event.authorization(); + case AUTHORIZATION_FAILURE: + MqttAuthorizationFailureFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(MQTT_AUTHORIZATION_FORMAT, result(e.result()), e.timestamp(), e.traceId(), namespace, - binding, asString(e.identity())); + out.printf(MQTT_AUTHORIZATION_FAILURE_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.identity())); break; } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index 39d021bd28..a494bc1101 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -22,7 +22,6 @@ import org.agrona.concurrent.UnsafeBuffer; import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.MqttEventFW; -import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.Result; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -44,23 +43,24 @@ public MqttEventContext( this.clock = context.clock(); } - public void authorization( + public void authorizationFailure( long sessionId, long traceId, long routedId, String identity) { - Result result = sessionId == 0 ? Result.FAILURE : Result.SUCCESS; - MqttEventFW event = mqttEventRW - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorization(e -> e - .timestamp(clock.millis()) - .traceId(traceId) - .namespacedId(routedId) - .result(r -> r.set(result)) - .identity(identity) - ) - .build(); - eventWriter.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); + if (sessionId == 0) + { + MqttEventFW event = mqttEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorizationFailure(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(routedId) + .identity(identity) + ) + .build(); + eventWriter.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); + } } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index de95b6240e..e91b03560a 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -2914,7 +2914,7 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) if (credentialsMatch != null) { sessionAuth = guard.reauthorize(initialId, credentialsMatch); - event.authorization(sessionAuth, traceId, routedId, guard.identity(sessionId)); + event.authorizationFailure(sessionAuth, traceId, routedId, guard.identity(sessionId)); } } diff --git a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl index 89a4c1ec8a..d49e1c6ecd 100644 --- a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl +++ b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl @@ -267,24 +267,17 @@ scope mqtt { enum MqttEventType (uint8) { - AUTHORIZATION (1) + AUTHORIZATION_FAILURE (1) } - enum Result (uint8) + struct MqttAuthorizationFailure extends core::event::Event { - SUCCESS (0), - FAILURE (1) - } - - struct MqttAuthorization extends core::event::Event - { - Result result; string8 identity; } union MqttEvent switch (MqttEventType) { - case AUTHORIZATION: MqttAuthorization authorization; + case AUTHORIZATION_FAILURE: MqttAuthorizationFailure authorizationFailure; } } } From d68172733e1c170bf40123fa22d245ff76a773ce Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 13:20:19 +0100 Subject: [PATCH 119/167] fix http log format --- .../stdout/internal/stream/EventHandler.java | 7 ++++ .../internal/stream/HttpEventHandler.java | 34 ++++--------------- .../http/internal/HttpEventContext.java | 29 +++++----------- .../internal/stream/HttpServerFactory.java | 8 ++--- .../main/resources/META-INF/zilla/http.idl | 11 ++---- 5 files changed, 30 insertions(+), 59 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java index a9e121c93e..227b433e85 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java @@ -49,4 +49,11 @@ protected static String asString( String s = stringFW.asString(); return s == null ? "" : s; } + + protected static String identity( + StringFW stringFW) + { + String s = stringFW.asString(); + return s == null || s.isEmpty() ? "-" : s; + } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index c839aac806..4466d6d939 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -19,18 +19,13 @@ import org.agrona.DirectBuffer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.Array32FW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.HttpHeaderFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFailureFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpDefaultEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestFW; public class HttpEventHandler extends EventHandler { - private static final String HTTP_AUTHORIZATION_FAILURE_FORMAT = - "HTTP Authorization Failure [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; - private static final String HTTP_REQUEST_FORMAT = - "HTTP Request [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] %s%n"; + private static final String HTTP_AUTHORIZATION_FAILURE_FORMAT = "HTTP_AUTHORIZATION_FAILURE 0x%016x %s.%s %s %d%n"; + private static final String HTTP_REQUEST_FORMAT = "HTTP_REQUEST 0x%016x %s.%s %s %d%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -53,35 +48,20 @@ public void handleEvent( { case AUTHORIZATION_FAILURE: { - HttpAuthorizationFailureFW e = event.authorizationFailure(); + HttpDefaultEventFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HTTP_AUTHORIZATION_FAILURE_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.identity())); + out.printf(HTTP_AUTHORIZATION_FAILURE_FORMAT, e.traceId(), namespace, binding, identity(e.identity()), e.timestamp()); break; } case REQUEST: { - HttpRequestFW e = event.request(); + HttpDefaultEventFW e = event.request(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.format(HTTP_REQUEST_FORMAT, e.timestamp(), e.traceId(), namespace, binding, headersAsString(e.headers())); + out.format(HTTP_REQUEST_FORMAT, e.traceId(), namespace, binding, identity(e.identity()), e.timestamp()); break; } } } - - private static String headersAsString( - Array32FW headers) - { - StringBuilder sb = new StringBuilder(); - headers.forEach(h -> - { - sb.append("["); - sb.append(h.name().asString()); - sb.append(" = "); - sb.append(h.value().asString()); - sb.append("] "); - }); - return sb.toString(); - } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 0f86462946..477a86e0e0 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -17,27 +17,21 @@ import java.nio.ByteBuffer; import java.time.Clock; -import java.util.Map; import org.agrona.concurrent.AtomicBuffer; import org.agrona.concurrent.UnsafeBuffer; -import io.aklivity.zilla.runtime.binding.http.internal.types.Array32FW; -import io.aklivity.zilla.runtime.binding.http.internal.types.HttpHeaderFW; import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.engine.guard.GuardHandler; public class HttpEventContext { private static final int EVENT_BUFFER_CAPACITY = 2048; - private static final int HEADER_BUFFER_CAPACITY = 1024; private final AtomicBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final HttpEventFW.Builder httpEventRW = new HttpEventFW.Builder(); - private final AtomicBuffer headerBuffer = new UnsafeBuffer(new byte[HEADER_BUFFER_CAPACITY]); - private final Array32FW.Builder headersRW = - new Array32FW.Builder<>(new HttpHeaderFW.Builder(), new HttpHeaderFW()); private final int httpTypeId; private final MessageConsumer eventWriter; private final Clock clock; @@ -54,10 +48,12 @@ public void authorizationFailure( long sessionId, long traceId, long routedId, - String identity) + GuardHandler guard, + long authorization) { if (sessionId == 0) { + String identity = guard == null ? null : guard.identity(authorization); HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorizationFailure(e -> e @@ -74,26 +70,19 @@ public void authorizationFailure( public void request( long traceId, long routedId, - Array32FW headers) + GuardHandler guard, + long authorization) { + String identity = guard == null ? null : guard.identity(authorization); HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .request(e -> e .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) - .headers(headers)) + .identity(identity) + ) .build(); eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); } - - public void request( - long traceId, - long routedId, - Map headers) - { - headersRW.wrap(headerBuffer, 0, headerBuffer.capacity()); - headers.forEach((n, v) -> headersRW.item(i -> i.name(n).value(v))); - request(traceId, routedId, headersRW.build()); - } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 26dd953acd..30d1148bf2 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1059,7 +1059,7 @@ else if (!isCorsRequestAllowed(server.binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); - event.authorizationFailure(exchangeAuth, traceId, server.routedId, guard.identity(authorization)); + event.authorizationFailure(exchangeAuth, traceId, server.routedId, guard, authorization); } } @@ -2272,7 +2272,7 @@ private boolean onDecodeHeaders( final HttpHeaderFW connection = beginEx.headers().matchFirst(h -> HEADER_CONNECTION.equals(h.name())); exchange.responseClosing = connection != null && connectionClose.reset(connection.value().asString()).matches(); - event.request(traceId, routedId, beginEx.headers()); + event.request(traceId, routedId, guard, authorization); this.exchange = exchange; } return headersValid; @@ -4928,7 +4928,7 @@ else if (headersDecoder.httpError()) else { final Map headers = headersDecoder.headers; - event.request(traceId, routedId, headers); + event.request(traceId, routedId, guard, authorization); if (isCorsPreflightRequest(headers)) { if (!endRequest) @@ -4974,7 +4974,7 @@ else if (!isCorsRequestAllowed(binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(initialId, credentialsMatch); - event.authorizationFailure(exchangeAuth, traceId, routedId, guard.identity(authorization)); + event.authorizationFailure(exchangeAuth, traceId, routedId, guard, authorization); } } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 3cb40cfdf9..fc39948496 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -58,20 +58,15 @@ scope http REQUEST (2) } - struct HttpAuthorizationFailure extends core::event::Event + struct HttpDefaultEvent extends core::event::Event { string8 identity; } - struct HttpRequest extends core::event::Event - { - HttpHeader[] headers; - } - union HttpEvent switch (HttpEventType) { - case AUTHORIZATION_FAILURE: HttpAuthorizationFailure authorizationFailure; - case REQUEST: HttpRequest request; + case AUTHORIZATION_FAILURE: HttpDefaultEvent authorizationFailure; + case REQUEST: HttpDefaultEvent request; } } } From cbb63160897d5b44f45070ca31a72a4c1afceebc Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 13:24:50 +0100 Subject: [PATCH 120/167] fix kafka log format --- .../stdout/internal/stream/KafkaEventHandler.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index d178f719a1..ea04b8b69f 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -24,10 +24,8 @@ public class KafkaEventHandler extends EventHandler { - private static final String KAFKA_AUTHORIZATION_FAILURE_FORMAT = - "Kafka Authorization Failure [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; - private static final String KAFKA_API_VERSION_REJECTED = - "Kafka API Version Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String KAFKA_AUTHORIZATION_FAILURE_FORMAT = "KAFKA_AUTHORIZATION_FAILURE 0x%016x %s.%s - %d%n"; + private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "KAFKA_API_VERSION_REJECTED 0x%016x %s.%s - %d%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); @@ -53,8 +51,7 @@ public void handleEvent( EventFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_AUTHORIZATION_FAILURE_FORMAT, e.timestamp(), e.traceId(), namespace, - binding); + out.printf(KAFKA_AUTHORIZATION_FAILURE_FORMAT, e.traceId(), namespace, binding, e.timestamp()); break; } case API_VERSION_REJECTED: @@ -62,7 +59,7 @@ public void handleEvent( EventFW e = event.apiVersionRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_API_VERSION_REJECTED, e.timestamp(), e.traceId(), namespace, binding); + out.printf(KAFKA_API_VERSION_REJECTED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); break; } } From 11790f1e7856196fdb259f301c9c507c2fadda46 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 13:29:31 +0100 Subject: [PATCH 121/167] fix mqtt log format --- .../exporter/stdout/internal/stream/MqttEventHandler.java | 5 ++--- .../runtime/binding/mqtt/internal/MqttEventContext.java | 5 ++++- .../binding/mqtt/internal/stream/MqttServerFactory.java | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index daa525348a..cf96fac2c6 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -24,8 +24,7 @@ public class MqttEventHandler extends EventHandler { - private static final String MQTT_AUTHORIZATION_FAILURE_FORMAT = - "MQTT Authorization Failure [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [identity = %s]%n"; + private static final String MQTT_AUTHORIZATION_FAILURE_FORMAT = "MQTT_AUTHORIZATION_FAILURE 0x%016x %s.%s %s %d%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); @@ -50,7 +49,7 @@ public void handleEvent( MqttAuthorizationFailureFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(MQTT_AUTHORIZATION_FAILURE_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.identity())); + out.printf(MQTT_AUTHORIZATION_FAILURE_FORMAT, e.traceId(), namespace, binding, identity(e.identity()), e.timestamp()); break; } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index a494bc1101..c24321ad63 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -24,6 +24,7 @@ import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.MqttEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.engine.guard.GuardHandler; public class MqttEventContext { @@ -47,10 +48,12 @@ public void authorizationFailure( long sessionId, long traceId, long routedId, - String identity) + GuardHandler guard, + long authorization) { if (sessionId == 0) { + String identity = guard == null ? null : guard.identity(authorization); MqttEventFW event = mqttEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .authorizationFailure(e -> e diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index e91b03560a..103e1b3670 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -2914,7 +2914,7 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) if (credentialsMatch != null) { sessionAuth = guard.reauthorize(initialId, credentialsMatch); - event.authorizationFailure(sessionAuth, traceId, routedId, guard.identity(sessionId)); + event.authorizationFailure(sessionAuth, traceId, routedId, guard, sessionId); } } From c802e2c32b79dfa8c7e6e7e23fa7817f4fa3fdba Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 13:33:14 +0100 Subject: [PATCH 122/167] fix tcp log format --- .../exporter/stdout/internal/stream/TcpEventHandler.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index de2f57c993..9ba15fd540 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -24,8 +24,7 @@ public class TcpEventHandler extends EventHandler { - private static final String TCP_DNS_FAILED_FORMAT = - "TCP DNS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [address = %s]%n"; + private static final String TCP_DNS_FAILED_FORMAT = "TCP_DNS_FAILED 0x%016x %s.%s - %d %s%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); @@ -50,7 +49,7 @@ public void handleEvent( TcpDnsFailedFW e = event.dnsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TCP_DNS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding, asString(e.address())); + out.printf(TCP_DNS_FAILED_FORMAT, e.traceId(), namespace, binding, e.timestamp(), asString(e.address())); break; } } From 41a8d3b8451fe437afdb99ec1603a08a92951ae7 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 13:40:18 +0100 Subject: [PATCH 123/167] fix tls log format --- .../internal/stream/TlsEventHandler.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index 7c477ec986..b5ed8bae79 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -24,16 +24,11 @@ public class TlsEventHandler extends EventHandler { - private static final String TLS_FAILED_FORMAT = - "TLS Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; - private static final String TLS_PROTOCOL_REJECTED = - "TLS Protocol Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; - private static final String TLS_KEY_REJECTED = - "TLS Key Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; - private static final String TLS_PEER_NOT_VERIFIED = - "TLS Peer Not Verified [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; - private static final String TLS_HANDSHAKE_FAILED = - "TLS Handshake Failed [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s]%n"; + private static final String TLS_FAILED_FORMAT = "TLS_FAILED 0x%016x %s.%s - %d%n"; + private static final String TLS_PROTOCOL_REJECTED_FORMAT = "TLS_PROTOCOL_REJECTED 0x%016x %s.%s - %d%n"; + private static final String TLS_KEY_REJECTED_FORMAT = "TLS_KEY_REJECTED 0x%016x %s.%s - %d%n"; + private static final String TLS_PEER_NOT_VERIFIED_FORMAT = "TLS_PEER_NOT_VERIFIED 0x%016x %s.%s - %d%n"; + private static final String TLS_HANDSHAKE_FAILED_FORMAT = "TLS_HANDSHAKE_FAILED 0x%016x %s.%s - %d%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); @@ -59,7 +54,7 @@ public void handleEvent( EventFW e = event.tlsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_FAILED_FORMAT, e.timestamp(), e.traceId(), namespace, binding); + out.printf(TLS_FAILED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); break; } case TLS_PROTOCOL_REJECTED: @@ -67,7 +62,7 @@ public void handleEvent( EventFW e = event.tlsProtocolRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_PROTOCOL_REJECTED, e.timestamp(), e.traceId(), namespace, binding); + out.printf(TLS_PROTOCOL_REJECTED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); break; } case TLS_KEY_REJECTED: @@ -75,7 +70,7 @@ public void handleEvent( EventFW e = event.tlsKeyRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_KEY_REJECTED, e.timestamp(), e.traceId(), namespace, binding); + out.printf(TLS_KEY_REJECTED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); break; } case TLS_PEER_NOT_VERIFIED: @@ -83,7 +78,7 @@ public void handleEvent( EventFW e = event.tlsPeerNotVerified(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_PEER_NOT_VERIFIED, e.timestamp(), e.traceId(), namespace, binding); + out.printf(TLS_PEER_NOT_VERIFIED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); break; } case TLS_HANDSHAKE_FAILED: @@ -91,7 +86,7 @@ public void handleEvent( EventFW e = event.tlsHandshakeFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_HANDSHAKE_FAILED, e.timestamp(), e.traceId(), namespace, binding); + out.printf(TLS_HANDSHAKE_FAILED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); break; } } From cc4987c3f96962badfbb67e73a25cb7cec201c16 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 21 Feb 2024 13:59:45 +0100 Subject: [PATCH 124/167] fix schreg log format --- .../src/main/resources/META-INF/zilla/schema_registry.idl | 2 +- .../registry/internal/SchemaRegistryCatalogHandler.java | 4 ++-- .../registry/internal/SchemaRegistryEventContext.java | 8 ++++---- .../internal/stream/SchemaRegistryEventHandler.java | 8 +++----- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl index e4e5d74067..7e00302d25 100644 --- a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl +++ b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl @@ -23,8 +23,8 @@ scope schema_registry struct SchemaRegistryRemoteAccessRejected extends core::event::Event { - string16 url; string8 method; + string16 baseUrl; int16 status; } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java index 88f47fd777..d172089ac8 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java @@ -221,13 +221,13 @@ private String sendHttpRequest( String responseBody = success ? httpResponse.body() : null; if (!success) { - event.remoteAccessRejected(catalogId, httpRequest, httpResponse.statusCode()); + event.remoteAccessRejected(catalogId, baseUrl, httpRequest.method(), httpResponse.statusCode()); } return responseBody; } catch (Exception ex) { - event.remoteAccessRejected(catalogId, httpRequest, 0); + event.remoteAccessRejected(catalogId, baseUrl, httpRequest.method(), 0); } return null; } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 8e7333aca2..d9c39f1cad 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -14,7 +14,6 @@ */ package io.aklivity.zilla.runtime.catalog.schema.registry.internal; -import java.net.http.HttpRequest; import java.nio.ByteBuffer; import java.time.Clock; @@ -45,7 +44,8 @@ public SchemaRegistryEventContext( public void remoteAccessRejected( long catalogId, - HttpRequest httpRequest, + String baseUrl, + String method, int status) { SchemaRegistryEventFW event = schemaRegistryEventRW @@ -53,8 +53,8 @@ public void remoteAccessRejected( .remoteAccessRejected(e -> e .timestamp(clock.millis()) .namespacedId(catalogId) - .url(httpRequest.uri().toString()) - .method(httpRequest.method()) + .method(method) + .baseUrl(baseUrl) .status((short) status) ) .build(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index 4dec65fca6..dc848751ac 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -24,9 +24,7 @@ public class SchemaRegistryEventHandler extends EventHandler { - private static final String REMOTE_ACCESS_REJECTED = - "Schema Registry Remote Access Rejected [timestamp = %d] [traceId = 0x%016x] [binding = %s.%s] [url = %s] " + - "[method = %s] [status = %d]%n"; + private static final String REMOTE_ACCESS_REJECTED = "SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED 0x%016x %s.%s - %d %s %s %d%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); @@ -51,8 +49,8 @@ public void handleEvent( SchemaRegistryRemoteAccessRejectedFW e = event.remoteAccessRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(REMOTE_ACCESS_REJECTED, e.timestamp(), e.traceId(), namespace, binding, asString(e.url()), - asString(e.method()), e.status()); + out.printf(REMOTE_ACCESS_REJECTED, e.traceId(), namespace, binding, e.timestamp(), asString(e.method()), + asString(e.baseUrl()), e.status()); break; } } From 71a681840702691259da0b10f4dbd9991c4afb84 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 09:39:51 +0100 Subject: [PATCH 125/167] fix revert schreg --- .../src/main/resources/META-INF/zilla/schema_registry.idl | 2 +- .../registry/internal/SchemaRegistryCatalogHandler.java | 4 ++-- .../registry/internal/SchemaRegistryEventContext.java | 8 ++++---- .../internal/stream/SchemaRegistryEventHandler.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl index 7e00302d25..df61e3605c 100644 --- a/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl +++ b/incubator/catalog-schema-registry.spec/src/main/resources/META-INF/zilla/schema_registry.idl @@ -24,7 +24,7 @@ scope schema_registry struct SchemaRegistryRemoteAccessRejected extends core::event::Event { string8 method; - string16 baseUrl; + string16 url; int16 status; } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java index d172089ac8..88f47fd777 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryCatalogHandler.java @@ -221,13 +221,13 @@ private String sendHttpRequest( String responseBody = success ? httpResponse.body() : null; if (!success) { - event.remoteAccessRejected(catalogId, baseUrl, httpRequest.method(), httpResponse.statusCode()); + event.remoteAccessRejected(catalogId, httpRequest, httpResponse.statusCode()); } return responseBody; } catch (Exception ex) { - event.remoteAccessRejected(catalogId, baseUrl, httpRequest.method(), 0); + event.remoteAccessRejected(catalogId, httpRequest, 0); } return null; } diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index d9c39f1cad..63b97940ea 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -14,6 +14,7 @@ */ package io.aklivity.zilla.runtime.catalog.schema.registry.internal; +import java.net.http.HttpRequest; import java.nio.ByteBuffer; import java.time.Clock; @@ -44,8 +45,7 @@ public SchemaRegistryEventContext( public void remoteAccessRejected( long catalogId, - String baseUrl, - String method, + HttpRequest httpRequest, int status) { SchemaRegistryEventFW event = schemaRegistryEventRW @@ -53,8 +53,8 @@ public void remoteAccessRejected( .remoteAccessRejected(e -> e .timestamp(clock.millis()) .namespacedId(catalogId) - .method(method) - .baseUrl(baseUrl) + .method(httpRequest.method()) + .url(httpRequest.uri().toString()) .status((short) status) ) .build(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index dc848751ac..0a600316d7 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -50,7 +50,7 @@ public void handleEvent( String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.printf(REMOTE_ACCESS_REJECTED, e.traceId(), namespace, binding, e.timestamp(), asString(e.method()), - asString(e.baseUrl()), e.status()); + asString(e.url()), e.status()); break; } } From 02f3b7b851bc29aa0eb56ffc18cb2ef1093579b4 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 09:44:15 +0100 Subject: [PATCH 126/167] fix identity --- .../exporter/stdout/internal/stream/EventHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java index 227b433e85..e3e24ba4fa 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java @@ -51,9 +51,9 @@ protected static String asString( } protected static String identity( - StringFW stringFW) + StringFW identity) { - String s = stringFW.asString(); - return s == null || s.isEmpty() ? "-" : s; + int length = identity.length(); + return length <= 0 ? "-" : identity.asString(); } } From 0532c2ce1fc2175d5a6df08a412fa58d2c4c103d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 09:46:54 +0100 Subject: [PATCH 127/167] fix rm traceId --- .../internal/stream/HttpEventHandler.java | 8 ++++---- .../internal/stream/KafkaEventHandler.java | 8 ++++---- .../internal/stream/MqttEventHandler.java | 4 ++-- .../stream/SchemaRegistryEventHandler.java | 4 ++-- .../internal/stream/TcpEventHandler.java | 4 ++-- .../internal/stream/TlsEventHandler.java | 20 +++++++++---------- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index 4466d6d939..212ae7cbae 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -24,8 +24,8 @@ public class HttpEventHandler extends EventHandler { - private static final String HTTP_AUTHORIZATION_FAILURE_FORMAT = "HTTP_AUTHORIZATION_FAILURE 0x%016x %s.%s %s %d%n"; - private static final String HTTP_REQUEST_FORMAT = "HTTP_REQUEST 0x%016x %s.%s %s %d%n"; + private static final String HTTP_AUTHORIZATION_FAILURE_FORMAT = "HTTP_AUTHORIZATION_FAILURE %s.%s %s %d%n"; + private static final String HTTP_REQUEST_FORMAT = "HTTP_REQUEST %s.%s %s %d%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -51,7 +51,7 @@ public void handleEvent( HttpDefaultEventFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HTTP_AUTHORIZATION_FAILURE_FORMAT, e.traceId(), namespace, binding, identity(e.identity()), e.timestamp()); + out.printf(HTTP_AUTHORIZATION_FAILURE_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); break; } case REQUEST: @@ -59,7 +59,7 @@ public void handleEvent( HttpDefaultEventFW e = event.request(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.format(HTTP_REQUEST_FORMAT, e.traceId(), namespace, binding, identity(e.identity()), e.timestamp()); + out.format(HTTP_REQUEST_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index ea04b8b69f..6dbec8bc10 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -24,8 +24,8 @@ public class KafkaEventHandler extends EventHandler { - private static final String KAFKA_AUTHORIZATION_FAILURE_FORMAT = "KAFKA_AUTHORIZATION_FAILURE 0x%016x %s.%s - %d%n"; - private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "KAFKA_API_VERSION_REJECTED 0x%016x %s.%s - %d%n"; + private static final String KAFKA_AUTHORIZATION_FAILURE_FORMAT = "KAFKA_AUTHORIZATION_FAILURE %s.%s - %d%n"; + private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "KAFKA_API_VERSION_REJECTED %s.%s - %d%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); @@ -51,7 +51,7 @@ public void handleEvent( EventFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_AUTHORIZATION_FAILURE_FORMAT, e.traceId(), namespace, binding, e.timestamp()); + out.printf(KAFKA_AUTHORIZATION_FAILURE_FORMAT, namespace, binding, e.timestamp()); break; } case API_VERSION_REJECTED: @@ -59,7 +59,7 @@ public void handleEvent( EventFW e = event.apiVersionRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_API_VERSION_REJECTED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); + out.printf(KAFKA_API_VERSION_REJECTED_FORMAT, namespace, binding, e.timestamp()); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index cf96fac2c6..dc6a9a0924 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -24,7 +24,7 @@ public class MqttEventHandler extends EventHandler { - private static final String MQTT_AUTHORIZATION_FAILURE_FORMAT = "MQTT_AUTHORIZATION_FAILURE 0x%016x %s.%s %s %d%n"; + private static final String MQTT_AUTHORIZATION_FAILURE_FORMAT = "MQTT_AUTHORIZATION_FAILURE %s.%s %s %d%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); @@ -49,7 +49,7 @@ public void handleEvent( MqttAuthorizationFailureFW e = event.authorizationFailure(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(MQTT_AUTHORIZATION_FAILURE_FORMAT, e.traceId(), namespace, binding, identity(e.identity()), e.timestamp()); + out.printf(MQTT_AUTHORIZATION_FAILURE_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index 0a600316d7..cab5df8df3 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -24,7 +24,7 @@ public class SchemaRegistryEventHandler extends EventHandler { - private static final String REMOTE_ACCESS_REJECTED = "SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED 0x%016x %s.%s - %d %s %s %d%n"; + private static final String REMOTE_ACCESS_REJECTED = "SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED %s.%s - %d %s %s %d%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); @@ -49,7 +49,7 @@ public void handleEvent( SchemaRegistryRemoteAccessRejectedFW e = event.remoteAccessRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(REMOTE_ACCESS_REJECTED, e.traceId(), namespace, binding, e.timestamp(), asString(e.method()), + out.printf(REMOTE_ACCESS_REJECTED, namespace, binding, e.timestamp(), asString(e.method()), asString(e.url()), e.status()); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index 9ba15fd540..ff53ef6284 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -24,7 +24,7 @@ public class TcpEventHandler extends EventHandler { - private static final String TCP_DNS_FAILED_FORMAT = "TCP_DNS_FAILED 0x%016x %s.%s - %d %s%n"; + private static final String TCP_DNS_FAILED_FORMAT = "TCP_DNS_FAILED %s.%s - %d %s%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); @@ -49,7 +49,7 @@ public void handleEvent( TcpDnsFailedFW e = event.dnsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TCP_DNS_FAILED_FORMAT, e.traceId(), namespace, binding, e.timestamp(), asString(e.address())); + out.printf(TCP_DNS_FAILED_FORMAT, namespace, binding, e.timestamp(), asString(e.address())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index b5ed8bae79..57631dac86 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -24,11 +24,11 @@ public class TlsEventHandler extends EventHandler { - private static final String TLS_FAILED_FORMAT = "TLS_FAILED 0x%016x %s.%s - %d%n"; - private static final String TLS_PROTOCOL_REJECTED_FORMAT = "TLS_PROTOCOL_REJECTED 0x%016x %s.%s - %d%n"; - private static final String TLS_KEY_REJECTED_FORMAT = "TLS_KEY_REJECTED 0x%016x %s.%s - %d%n"; - private static final String TLS_PEER_NOT_VERIFIED_FORMAT = "TLS_PEER_NOT_VERIFIED 0x%016x %s.%s - %d%n"; - private static final String TLS_HANDSHAKE_FAILED_FORMAT = "TLS_HANDSHAKE_FAILED 0x%016x %s.%s - %d%n"; + private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s.%s - %d%n"; + private static final String TLS_PROTOCOL_REJECTED_FORMAT = "TLS_PROTOCOL_REJECTED %s.%s - %d%n"; + private static final String TLS_KEY_REJECTED_FORMAT = "TLS_KEY_REJECTED %s.%s - %d%n"; + private static final String TLS_PEER_NOT_VERIFIED_FORMAT = "TLS_PEER_NOT_VERIFIED %s.%s - %d%n"; + private static final String TLS_HANDSHAKE_FAILED_FORMAT = "TLS_HANDSHAKE_FAILED %s.%s - %d%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); @@ -54,7 +54,7 @@ public void handleEvent( EventFW e = event.tlsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_FAILED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); + out.printf(TLS_FAILED_FORMAT, namespace, binding, e.timestamp()); break; } case TLS_PROTOCOL_REJECTED: @@ -62,7 +62,7 @@ public void handleEvent( EventFW e = event.tlsProtocolRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_PROTOCOL_REJECTED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); + out.printf(TLS_PROTOCOL_REJECTED_FORMAT, namespace, binding, e.timestamp()); break; } case TLS_KEY_REJECTED: @@ -70,7 +70,7 @@ public void handleEvent( EventFW e = event.tlsKeyRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_KEY_REJECTED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); + out.printf(TLS_KEY_REJECTED_FORMAT, namespace, binding, e.timestamp()); break; } case TLS_PEER_NOT_VERIFIED: @@ -78,7 +78,7 @@ public void handleEvent( EventFW e = event.tlsPeerNotVerified(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_PEER_NOT_VERIFIED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); + out.printf(TLS_PEER_NOT_VERIFIED_FORMAT, namespace, binding, e.timestamp()); break; } case TLS_HANDSHAKE_FAILED: @@ -86,7 +86,7 @@ public void handleEvent( EventFW e = event.tlsHandshakeFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_HANDSHAKE_FAILED_FORMAT, e.traceId(), namespace, binding, e.timestamp()); + out.printf(TLS_HANDSHAKE_FAILED_FORMAT, namespace, binding, e.timestamp()); break; } } From 4736c149803d8ca4ebeca66598ce843aa591715b Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 09:51:41 +0100 Subject: [PATCH 128/167] fix rm event type name --- .../exporter/stdout/internal/stream/HttpEventHandler.java | 4 ++-- .../stdout/internal/stream/KafkaEventHandler.java | 4 ++-- .../exporter/stdout/internal/stream/MqttEventHandler.java | 2 +- .../internal/stream/SchemaRegistryEventHandler.java | 2 +- .../exporter/stdout/internal/stream/TcpEventHandler.java | 2 +- .../exporter/stdout/internal/stream/TlsEventHandler.java | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index 212ae7cbae..69dca0eb20 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -24,8 +24,8 @@ public class HttpEventHandler extends EventHandler { - private static final String HTTP_AUTHORIZATION_FAILURE_FORMAT = "HTTP_AUTHORIZATION_FAILURE %s.%s %s %d%n"; - private static final String HTTP_REQUEST_FORMAT = "HTTP_REQUEST %s.%s %s %d%n"; + private static final String HTTP_AUTHORIZATION_FAILURE_FORMAT = "AUTHORIZATION_FAILURE %s.%s %s %d%n"; + private static final String HTTP_REQUEST_FORMAT = "REQUEST %s.%s %s %d%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index 6dbec8bc10..687904a551 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -24,8 +24,8 @@ public class KafkaEventHandler extends EventHandler { - private static final String KAFKA_AUTHORIZATION_FAILURE_FORMAT = "KAFKA_AUTHORIZATION_FAILURE %s.%s - %d%n"; - private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "KAFKA_API_VERSION_REJECTED %s.%s - %d%n"; + private static final String KAFKA_AUTHORIZATION_FAILURE_FORMAT = "AUTHORIZATION_FAILURE %s.%s - %d%n"; + private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s.%s - %d%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index dc6a9a0924..26bd93e7fd 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -24,7 +24,7 @@ public class MqttEventHandler extends EventHandler { - private static final String MQTT_AUTHORIZATION_FAILURE_FORMAT = "MQTT_AUTHORIZATION_FAILURE %s.%s %s %d%n"; + private static final String MQTT_AUTHORIZATION_FAILURE_FORMAT = "AUTHORIZATION_FAILURE %s.%s %s %d%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index cab5df8df3..0c65795c61 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -24,7 +24,7 @@ public class SchemaRegistryEventHandler extends EventHandler { - private static final String REMOTE_ACCESS_REJECTED = "SCHEMA_REGISTRY_REMOTE_ACCESS_REJECTED %s.%s - %d %s %s %d%n"; + private static final String REMOTE_ACCESS_REJECTED = "REMOTE_ACCESS_REJECTED %s.%s - %d %s %s %d%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index ff53ef6284..15dbd3820f 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -24,7 +24,7 @@ public class TcpEventHandler extends EventHandler { - private static final String TCP_DNS_FAILED_FORMAT = "TCP_DNS_FAILED %s.%s - %d %s%n"; + private static final String TCP_DNS_FAILED_FORMAT = "DNS_FAILED %s.%s - %d %s%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index 57631dac86..c8d5abe85c 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -25,10 +25,10 @@ public class TlsEventHandler extends EventHandler { private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s.%s - %d%n"; - private static final String TLS_PROTOCOL_REJECTED_FORMAT = "TLS_PROTOCOL_REJECTED %s.%s - %d%n"; - private static final String TLS_KEY_REJECTED_FORMAT = "TLS_KEY_REJECTED %s.%s - %d%n"; - private static final String TLS_PEER_NOT_VERIFIED_FORMAT = "TLS_PEER_NOT_VERIFIED %s.%s - %d%n"; - private static final String TLS_HANDSHAKE_FAILED_FORMAT = "TLS_HANDSHAKE_FAILED %s.%s - %d%n"; + private static final String TLS_PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s.%s - %d%n"; + private static final String TLS_KEY_REJECTED_FORMAT = "KEY_REJECTED %s.%s - %d%n"; + private static final String TLS_PEER_NOT_VERIFIED_FORMAT = "PEER_NOT_VERIFIED %s.%s - %d%n"; + private static final String TLS_HANDSHAKE_FAILED_FORMAT = "HANDSHAKE_FAILED %s.%s - %d%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); From af555ce9c166d9e1ea4e1ad46aaa71850bfa2917 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 09:58:03 +0100 Subject: [PATCH 129/167] fix http --- .../stdout/internal/stream/HttpEventHandler.java | 14 +++++++------- .../binding/http/internal/HttpEventContext.java | 8 ++++---- .../http/internal/stream/HttpServerFactory.java | 8 ++++---- .../src/main/resources/META-INF/zilla/http.idl | 8 ++++---- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index 69dca0eb20..fdc9934734 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -24,8 +24,8 @@ public class HttpEventHandler extends EventHandler { - private static final String HTTP_AUTHORIZATION_FAILURE_FORMAT = "AUTHORIZATION_FAILURE %s.%s %s %d%n"; - private static final String HTTP_REQUEST_FORMAT = "REQUEST %s.%s %s %d%n"; + private static final String HTTP_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s %d%n"; + private static final String HTTP_REQUEST_FORMAT = "REQUEST_ACCEPTED %s.%s %s %d%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -46,17 +46,17 @@ public void handleEvent( final HttpEventFW event = httpEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case AUTHORIZATION_FAILURE: + case AUTHORIZATION_FAILED: { - HttpDefaultEventFW e = event.authorizationFailure(); + HttpDefaultEventFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HTTP_AUTHORIZATION_FAILURE_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); + out.printf(HTTP_AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); break; } - case REQUEST: + case REQUEST_ACCEPTED: { - HttpDefaultEventFW e = event.request(); + HttpDefaultEventFW e = event.requestAccepted(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); out.format(HTTP_REQUEST_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 477a86e0e0..cc50ae3869 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -44,7 +44,7 @@ public HttpEventContext( this.clock = context.clock(); } - public void authorizationFailure( + public void authorizationFailed( long sessionId, long traceId, long routedId, @@ -56,7 +56,7 @@ public void authorizationFailure( String identity = guard == null ? null : guard.identity(authorization); HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorizationFailure(e -> e + .authorizationFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) @@ -67,7 +67,7 @@ public void authorizationFailure( } } - public void request( + public void requestAccepted( long traceId, long routedId, GuardHandler guard, @@ -76,7 +76,7 @@ public void request( String identity = guard == null ? null : guard.identity(authorization); HttpEventFW event = httpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .request(e -> e + .requestAccepted(e -> e .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 30d1148bf2..25b60a774d 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1059,7 +1059,7 @@ else if (!isCorsRequestAllowed(server.binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); - event.authorizationFailure(exchangeAuth, traceId, server.routedId, guard, authorization); + event.authorizationFailed(exchangeAuth, traceId, server.routedId, guard, authorization); } } @@ -2272,7 +2272,7 @@ private boolean onDecodeHeaders( final HttpHeaderFW connection = beginEx.headers().matchFirst(h -> HEADER_CONNECTION.equals(h.name())); exchange.responseClosing = connection != null && connectionClose.reset(connection.value().asString()).matches(); - event.request(traceId, routedId, guard, authorization); + event.requestAccepted(traceId, routedId, guard, authorization); this.exchange = exchange; } return headersValid; @@ -4928,7 +4928,7 @@ else if (headersDecoder.httpError()) else { final Map headers = headersDecoder.headers; - event.request(traceId, routedId, guard, authorization); + event.requestAccepted(traceId, routedId, guard, authorization); if (isCorsPreflightRequest(headers)) { if (!endRequest) @@ -4974,7 +4974,7 @@ else if (!isCorsRequestAllowed(binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(initialId, credentialsMatch); - event.authorizationFailure(exchangeAuth, traceId, routedId, guard, authorization); + event.authorizationFailed(exchangeAuth, traceId, routedId, guard, authorization); } } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index fc39948496..0acc108044 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -54,8 +54,8 @@ scope http { enum HttpEventType (uint8) { - AUTHORIZATION_FAILURE (1), - REQUEST (2) + AUTHORIZATION_FAILED (1), + REQUEST_ACCEPTED (2) } struct HttpDefaultEvent extends core::event::Event @@ -65,8 +65,8 @@ scope http union HttpEvent switch (HttpEventType) { - case AUTHORIZATION_FAILURE: HttpDefaultEvent authorizationFailure; - case REQUEST: HttpDefaultEvent request; + case AUTHORIZATION_FAILED: HttpDefaultEvent authorizationFailed; + case REQUEST_ACCEPTED: HttpDefaultEvent requestAccepted; } } } From 787424b35019f7d9db02df082d724d1828edbdbe Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 10:03:18 +0100 Subject: [PATCH 130/167] fix kafka --- .../stdout/internal/stream/KafkaEventHandler.java | 8 ++++---- .../runtime/binding/kafka/internal/KafkaEventContext.java | 4 ++-- .../kafka/internal/stream/KafkaClientSaslHandshaker.java | 4 ++-- .../src/main/resources/META-INF/zilla/kafka.idl | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index 687904a551..233e9ebca4 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -24,7 +24,7 @@ public class KafkaEventHandler extends EventHandler { - private static final String KAFKA_AUTHORIZATION_FAILURE_FORMAT = "AUTHORIZATION_FAILURE %s.%s - %d%n"; + private static final String KAFKA_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s - %d%n"; private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s.%s - %d%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); @@ -46,12 +46,12 @@ public void handleEvent( final KafkaEventFW event = kafkaEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case AUTHORIZATION_FAILURE: + case AUTHORIZATION_FAILED: { - EventFW e = event.authorizationFailure(); + EventFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_AUTHORIZATION_FAILURE_FORMAT, namespace, binding, e.timestamp()); + out.printf(KAFKA_AUTHORIZATION_FAILED_FORMAT, namespace, binding, e.timestamp()); break; } case API_VERSION_REJECTED: diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index b189187622..96bcf133c8 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -44,7 +44,7 @@ public KafkaEventContext( this.clock = context.clock(); } - public void authorizationFailure( + public void authorizationFailed( int errorCode, long traceId, long routedId) @@ -53,7 +53,7 @@ public void authorizationFailure( { KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorizationFailure(e -> e + .authorizationFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index b196e8c953..2fb5657c74 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -703,7 +703,7 @@ private int decodeSaslPlainAuthenticate( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); - event.authorizationFailure(errorCode, traceId, client.routedId); + event.authorizationFailed(errorCode, traceId, client.routedId); progress = authenticateResponse.limit(); @@ -738,7 +738,7 @@ private int decodeSaslScramAuthenticateFirst( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); - event.authorizationFailure(errorCode, traceId, client.routedId); + event.authorizationFailed(errorCode, traceId, client.routedId); progress = authenticateResponse.limit(); diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index b6f642eb6b..855b9fd4ff 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -538,13 +538,13 @@ scope kafka { enum KafkaEventType (uint8) { - AUTHORIZATION_FAILURE (1), + AUTHORIZATION_FAILED (1), API_VERSION_REJECTED (2) } union KafkaEvent switch (KafkaEventType) { - case AUTHORIZATION_FAILURE: core::event::Event authorizationFailure; + case AUTHORIZATION_FAILED: core::event::Event authorizationFailed; case API_VERSION_REJECTED: core::event::Event apiVersionRejected; } } From 74ee442c414903e027e0a36f2fdaa52d1fdbed84 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 10:07:04 +0100 Subject: [PATCH 131/167] fix mqtt --- .../stdout/internal/stream/MqttEventHandler.java | 10 +++++----- .../binding/mqtt/internal/MqttEventContext.java | 4 ++-- .../mqtt/internal/stream/MqttServerFactory.java | 2 +- .../src/main/resources/META-INF/zilla/mqtt.idl | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index 26bd93e7fd..855873f176 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -19,12 +19,12 @@ import org.agrona.DirectBuffer; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationFailureFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationFailedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; public class MqttEventHandler extends EventHandler { - private static final String MQTT_AUTHORIZATION_FAILURE_FORMAT = "AUTHORIZATION_FAILURE %s.%s %s %d%n"; + private static final String MQTT_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s %d%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); @@ -45,11 +45,11 @@ public void handleEvent( MqttEventFW event = mqttEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case AUTHORIZATION_FAILURE: - MqttAuthorizationFailureFW e = event.authorizationFailure(); + case AUTHORIZATION_FAILED: + MqttAuthorizationFailedFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(MQTT_AUTHORIZATION_FAILURE_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); + out.printf(MQTT_AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); break; } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index c24321ad63..c875d3a187 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -44,7 +44,7 @@ public MqttEventContext( this.clock = context.clock(); } - public void authorizationFailure( + public void authorizationFailed( long sessionId, long traceId, long routedId, @@ -56,7 +56,7 @@ public void authorizationFailure( String identity = guard == null ? null : guard.identity(authorization); MqttEventFW event = mqttEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorizationFailure(e -> e + .authorizationFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) .namespacedId(routedId) diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index 103e1b3670..220d31e265 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -2914,7 +2914,7 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) if (credentialsMatch != null) { sessionAuth = guard.reauthorize(initialId, credentialsMatch); - event.authorizationFailure(sessionAuth, traceId, routedId, guard, sessionId); + event.authorizationFailed(sessionAuth, traceId, routedId, guard, sessionId); } } diff --git a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl index d49e1c6ecd..00283beda6 100644 --- a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl +++ b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl @@ -267,17 +267,17 @@ scope mqtt { enum MqttEventType (uint8) { - AUTHORIZATION_FAILURE (1) + AUTHORIZATION_FAILED (1) } - struct MqttAuthorizationFailure extends core::event::Event + struct MqttAuthorizationFailed extends core::event::Event { string8 identity; } union MqttEvent switch (MqttEventType) { - case AUTHORIZATION_FAILURE: MqttAuthorizationFailure authorizationFailure; + case AUTHORIZATION_FAILED: MqttAuthorizationFailed authorizationFailed; } } } From 43c7b7c5f3467d10ed318e9beff8aeadeae9fd5c Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 11:04:59 +0100 Subject: [PATCH 132/167] fix date time format --- .../stdout/internal/stream/EventHandler.java | 14 +++++++++++++ .../internal/stream/HttpEventHandler.java | 8 ++++---- .../internal/stream/KafkaEventHandler.java | 8 ++++---- .../internal/stream/MqttEventHandler.java | 4 ++-- .../stream/SchemaRegistryEventHandler.java | 4 ++-- .../internal/stream/TcpEventHandler.java | 4 ++-- .../internal/stream/TlsEventHandler.java | 20 +++++++++---------- 7 files changed, 38 insertions(+), 24 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java index e3e24ba4fa..ad72264a2b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java @@ -15,6 +15,10 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; +import java.time.Instant; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.function.LongFunction; import org.agrona.DirectBuffer; @@ -23,6 +27,8 @@ public abstract class EventHandler { + protected static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z"); + protected final LongFunction supplyNamespace; protected final LongFunction supplyLocalName; protected final PrintStream out; @@ -56,4 +62,12 @@ protected static String identity( int length = identity.length(); return length <= 0 ? "-" : identity.asString(); } + + protected static String asDateTime( + long timestamp) + { + Instant instant = Instant.ofEpochMilli(timestamp); + OffsetDateTime offsetDateTime = OffsetDateTime.ofInstant(instant, ZoneId.systemDefault()); + return offsetDateTime.format(FORMATTER); + } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index fdc9934734..aeba181aaa 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -24,8 +24,8 @@ public class HttpEventHandler extends EventHandler { - private static final String HTTP_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s %d%n"; - private static final String HTTP_REQUEST_FORMAT = "REQUEST_ACCEPTED %s.%s %s %d%n"; + private static final String HTTP_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s [%s]%n"; + private static final String HTTP_REQUEST_FORMAT = "REQUEST_ACCEPTED %s.%s %s [%s]%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -51,7 +51,7 @@ public void handleEvent( HttpDefaultEventFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HTTP_AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); + out.printf(HTTP_AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); break; } case REQUEST_ACCEPTED: @@ -59,7 +59,7 @@ public void handleEvent( HttpDefaultEventFW e = event.requestAccepted(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.format(HTTP_REQUEST_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); + out.format(HTTP_REQUEST_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index 233e9ebca4..094e5a17d3 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -24,8 +24,8 @@ public class KafkaEventHandler extends EventHandler { - private static final String KAFKA_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s - %d%n"; - private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s.%s - %d%n"; + private static final String KAFKA_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s - [%s]%n"; + private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s.%s - [%s]%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); @@ -51,7 +51,7 @@ public void handleEvent( EventFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_AUTHORIZATION_FAILED_FORMAT, namespace, binding, e.timestamp()); + out.printf(KAFKA_AUTHORIZATION_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case API_VERSION_REJECTED: @@ -59,7 +59,7 @@ public void handleEvent( EventFW e = event.apiVersionRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_API_VERSION_REJECTED_FORMAT, namespace, binding, e.timestamp()); + out.printf(KAFKA_API_VERSION_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index 855873f176..9d872252ab 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -24,7 +24,7 @@ public class MqttEventHandler extends EventHandler { - private static final String MQTT_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s %d%n"; + private static final String MQTT_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s [%s]%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); @@ -49,7 +49,7 @@ public void handleEvent( MqttAuthorizationFailedFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(MQTT_AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), e.timestamp()); + out.printf(MQTT_AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index 0c65795c61..0611bf5942 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -24,7 +24,7 @@ public class SchemaRegistryEventHandler extends EventHandler { - private static final String REMOTE_ACCESS_REJECTED = "REMOTE_ACCESS_REJECTED %s.%s - %d %s %s %d%n"; + private static final String REMOTE_ACCESS_REJECTED = "REMOTE_ACCESS_REJECTED %s.%s - [%s] %s %s %d%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); @@ -49,7 +49,7 @@ public void handleEvent( SchemaRegistryRemoteAccessRejectedFW e = event.remoteAccessRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(REMOTE_ACCESS_REJECTED, namespace, binding, e.timestamp(), asString(e.method()), + out.printf(REMOTE_ACCESS_REJECTED, namespace, binding, asDateTime(e.timestamp()), asString(e.method()), asString(e.url()), e.status()); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index 15dbd3820f..721428edf0 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -24,7 +24,7 @@ public class TcpEventHandler extends EventHandler { - private static final String TCP_DNS_FAILED_FORMAT = "DNS_FAILED %s.%s - %d %s%n"; + private static final String TCP_DNS_FAILED_FORMAT = "DNS_FAILED %s.%s - [%s] %s%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); @@ -49,7 +49,7 @@ public void handleEvent( TcpDnsFailedFW e = event.dnsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TCP_DNS_FAILED_FORMAT, namespace, binding, e.timestamp(), asString(e.address())); + out.printf(TCP_DNS_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp()), asString(e.address())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index c8d5abe85c..61f63ad1d1 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -24,11 +24,11 @@ public class TlsEventHandler extends EventHandler { - private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s.%s - %d%n"; - private static final String TLS_PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s.%s - %d%n"; - private static final String TLS_KEY_REJECTED_FORMAT = "KEY_REJECTED %s.%s - %d%n"; - private static final String TLS_PEER_NOT_VERIFIED_FORMAT = "PEER_NOT_VERIFIED %s.%s - %d%n"; - private static final String TLS_HANDSHAKE_FAILED_FORMAT = "HANDSHAKE_FAILED %s.%s - %d%n"; + private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s.%s - [%s]%n"; + private static final String TLS_PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s.%s - [%s]%n"; + private static final String TLS_KEY_REJECTED_FORMAT = "KEY_REJECTED %s.%s - [%s]%n"; + private static final String TLS_PEER_NOT_VERIFIED_FORMAT = "PEER_NOT_VERIFIED %s.%s - [%s]%n"; + private static final String TLS_HANDSHAKE_FAILED_FORMAT = "HANDSHAKE_FAILED %s.%s - [%s]%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); @@ -54,7 +54,7 @@ public void handleEvent( EventFW e = event.tlsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_FAILED_FORMAT, namespace, binding, e.timestamp()); + out.printf(TLS_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case TLS_PROTOCOL_REJECTED: @@ -62,7 +62,7 @@ public void handleEvent( EventFW e = event.tlsProtocolRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_PROTOCOL_REJECTED_FORMAT, namespace, binding, e.timestamp()); + out.printf(TLS_PROTOCOL_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case TLS_KEY_REJECTED: @@ -70,7 +70,7 @@ public void handleEvent( EventFW e = event.tlsKeyRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_KEY_REJECTED_FORMAT, namespace, binding, e.timestamp()); + out.printf(TLS_KEY_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case TLS_PEER_NOT_VERIFIED: @@ -78,7 +78,7 @@ public void handleEvent( EventFW e = event.tlsPeerNotVerified(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_PEER_NOT_VERIFIED_FORMAT, namespace, binding, e.timestamp()); + out.printf(TLS_PEER_NOT_VERIFIED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case TLS_HANDSHAKE_FAILED: @@ -86,7 +86,7 @@ public void handleEvent( EventFW e = event.tlsHandshakeFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_HANDSHAKE_FAILED_FORMAT, namespace, binding, e.timestamp()); + out.printf(TLS_HANDSHAKE_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } } From 64ccd2cbbfd1fbdb01bc4db59508482f92792c6a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 11:09:31 +0100 Subject: [PATCH 133/167] fix const --- .../stdout/internal/stream/HttpEventHandler.java | 8 ++++---- .../internal/stream/KafkaEventHandler.java | 8 ++++---- .../stdout/internal/stream/MqttEventHandler.java | 4 ++-- .../stdout/internal/stream/TcpEventHandler.java | 4 ++-- .../stdout/internal/stream/TlsEventHandler.java | 16 ++++++++-------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index aeba181aaa..a588e70e98 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -24,8 +24,8 @@ public class HttpEventHandler extends EventHandler { - private static final String HTTP_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s [%s]%n"; - private static final String HTTP_REQUEST_FORMAT = "REQUEST_ACCEPTED %s.%s %s [%s]%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s [%s]%n"; + private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s.%s %s [%s]%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -51,7 +51,7 @@ public void handleEvent( HttpDefaultEventFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HTTP_AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); + out.printf(AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); break; } case REQUEST_ACCEPTED: @@ -59,7 +59,7 @@ public void handleEvent( HttpDefaultEventFW e = event.requestAccepted(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.format(HTTP_REQUEST_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); + out.format(REQUEST_ACCEPTED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index 094e5a17d3..2e06328bda 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -24,8 +24,8 @@ public class KafkaEventHandler extends EventHandler { - private static final String KAFKA_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s - [%s]%n"; - private static final String KAFKA_API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s.%s - [%s]%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s - [%s]%n"; + private static final String API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s.%s - [%s]%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); @@ -51,7 +51,7 @@ public void handleEvent( EventFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_AUTHORIZATION_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + out.printf(AUTHORIZATION_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case API_VERSION_REJECTED: @@ -59,7 +59,7 @@ public void handleEvent( EventFW e = event.apiVersionRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KAFKA_API_VERSION_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + out.printf(API_VERSION_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index 9d872252ab..1dfa2ec832 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -24,7 +24,7 @@ public class MqttEventHandler extends EventHandler { - private static final String MQTT_AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s [%s]%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s [%s]%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); @@ -49,7 +49,7 @@ public void handleEvent( MqttAuthorizationFailedFW e = event.authorizationFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(MQTT_AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); + out.printf(AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index 721428edf0..6d590fb574 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -24,7 +24,7 @@ public class TcpEventHandler extends EventHandler { - private static final String TCP_DNS_FAILED_FORMAT = "DNS_FAILED %s.%s - [%s] %s%n"; + private static final String DNS_FAILED_FORMAT = "DNS_FAILED %s.%s - [%s] %s%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); @@ -49,7 +49,7 @@ public void handleEvent( TcpDnsFailedFW e = event.dnsFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TCP_DNS_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp()), asString(e.address())); + out.printf(DNS_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp()), asString(e.address())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index 61f63ad1d1..0295a1d4b8 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -25,10 +25,10 @@ public class TlsEventHandler extends EventHandler { private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s.%s - [%s]%n"; - private static final String TLS_PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s.%s - [%s]%n"; - private static final String TLS_KEY_REJECTED_FORMAT = "KEY_REJECTED %s.%s - [%s]%n"; - private static final String TLS_PEER_NOT_VERIFIED_FORMAT = "PEER_NOT_VERIFIED %s.%s - [%s]%n"; - private static final String TLS_HANDSHAKE_FAILED_FORMAT = "HANDSHAKE_FAILED %s.%s - [%s]%n"; + private static final String PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s.%s - [%s]%n"; + private static final String KEY_REJECTED_FORMAT = "KEY_REJECTED %s.%s - [%s]%n"; + private static final String PEER_NOT_VERIFIED_FORMAT = "PEER_NOT_VERIFIED %s.%s - [%s]%n"; + private static final String HANDSHAKE_FAILED_FORMAT = "HANDSHAKE_FAILED %s.%s - [%s]%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); @@ -62,7 +62,7 @@ public void handleEvent( EventFW e = event.tlsProtocolRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_PROTOCOL_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + out.printf(PROTOCOL_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case TLS_KEY_REJECTED: @@ -70,7 +70,7 @@ public void handleEvent( EventFW e = event.tlsKeyRejected(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_KEY_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + out.printf(KEY_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case TLS_PEER_NOT_VERIFIED: @@ -78,7 +78,7 @@ public void handleEvent( EventFW e = event.tlsPeerNotVerified(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_PEER_NOT_VERIFIED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + out.printf(PEER_NOT_VERIFIED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } case TLS_HANDSHAKE_FAILED: @@ -86,7 +86,7 @@ public void handleEvent( EventFW e = event.tlsHandshakeFailed(); String namespace = supplyNamespace.apply(e.namespacedId()); String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_HANDSHAKE_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + out.printf(HANDSHAKE_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); break; } } From 37dc1fb306588712e8dbadaa806e1d37b9ce56c5 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 11:42:14 +0100 Subject: [PATCH 134/167] fix supplyQName --- .../internal/StdoutExporterHandler.java | 4 +- .../stdout/internal/stream/EventHandler.java | 9 ++-- .../internal/stream/HttpEventHandler.java | 19 ++++----- .../internal/stream/KafkaEventHandler.java | 19 ++++----- .../internal/stream/MqttEventHandler.java | 12 +++--- .../stream/SchemaRegistryEventHandler.java | 14 +++---- .../internal/stream/StdoutEventsStream.java | 41 ++++++------------- .../internal/stream/TcpEventHandler.java | 12 +++--- .../internal/stream/TlsEventHandler.java | 40 ++++++++---------- .../zilla/runtime/engine/EngineContext.java | 3 ++ .../internal/registry/EngineWorker.java | 8 ++++ 11 files changed, 78 insertions(+), 103 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 63fefe04a9..e2c34daa17 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -40,8 +40,8 @@ public StdoutExporterHandler( @Override public void start() { - stdoutEventsStream = new StdoutEventsStream(context.supplyEventReader(), context::supplyNamespace, - context::supplyLocalName, context::supplyTypeId, out); + stdoutEventsStream = new StdoutEventsStream(context.supplyEventReader(), context::supplyQName, + context::supplyTypeId, out); } @Override diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java index ad72264a2b..37e2b5af5a 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java @@ -29,17 +29,14 @@ public abstract class EventHandler { protected static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z"); - protected final LongFunction supplyNamespace; - protected final LongFunction supplyLocalName; + protected final LongFunction supplyQName; protected final PrintStream out; public EventHandler( - LongFunction supplyNamespace, - LongFunction supplyLocalName, + LongFunction supplyQName, PrintStream out) { - this.supplyNamespace = supplyNamespace; - this.supplyLocalName = supplyLocalName; + this.supplyQName = supplyQName; this.out = out; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java index a588e70e98..7a22b7cb49 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java @@ -24,17 +24,16 @@ public class HttpEventHandler extends EventHandler { - private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s [%s]%n"; - private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s.%s %s [%s]%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s %s [%s]%n"; + private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s %s [%s]%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); public HttpEventHandler( - LongFunction supplyNamespace, - LongFunction supplyLocalName, + LongFunction supplyQName, PrintStream out) { - super(supplyNamespace, supplyLocalName, out); + super(supplyQName, out); } public void handleEvent( @@ -49,17 +48,15 @@ public void handleEvent( case AUTHORIZATION_FAILED: { HttpDefaultEventFW e = event.authorizationFailed(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); break; } case REQUEST_ACCEPTED: { HttpDefaultEventFW e = event.requestAccepted(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.format(REQUEST_ACCEPTED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.format(REQUEST_ACCEPTED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java index 2e06328bda..cffca047f1 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java @@ -24,17 +24,16 @@ public class KafkaEventHandler extends EventHandler { - private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s - [%s]%n"; - private static final String API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s.%s - [%s]%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s - [%s]%n"; + private static final String API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s - [%s]%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); public KafkaEventHandler( - LongFunction supplyNamespace, - LongFunction supplyLocalName, + LongFunction supplyQName, PrintStream out) { - super(supplyNamespace, supplyLocalName, out); + super(supplyQName, out); } public void handleEvent( @@ -49,17 +48,15 @@ public void handleEvent( case AUTHORIZATION_FAILED: { EventFW e = event.authorizationFailed(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(AUTHORIZATION_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(AUTHORIZATION_FAILED_FORMAT, qname, asDateTime(e.timestamp())); break; } case API_VERSION_REJECTED: { EventFW e = event.apiVersionRejected(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(API_VERSION_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(API_VERSION_REJECTED_FORMAT, qname, asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java index 1dfa2ec832..dba909fad2 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java @@ -24,16 +24,15 @@ public class MqttEventHandler extends EventHandler { - private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s.%s %s [%s]%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s %s [%s]%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); public MqttEventHandler( - LongFunction supplyNamespace, - LongFunction supplyLocalName, + LongFunction supplyQName, PrintStream out) { - super(supplyNamespace, supplyLocalName, out); + super(supplyQName, out); } public void handleEvent( @@ -47,9 +46,8 @@ public void handleEvent( { case AUTHORIZATION_FAILED: MqttAuthorizationFailedFW e = event.authorizationFailed(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(AUTHORIZATION_FAILED_FORMAT, namespace, binding, identity(e.identity()), asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java index 0611bf5942..28e9f3a088 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java @@ -24,16 +24,15 @@ public class SchemaRegistryEventHandler extends EventHandler { - private static final String REMOTE_ACCESS_REJECTED = "REMOTE_ACCESS_REJECTED %s.%s - [%s] %s %s %d%n"; + private static final String REMOTE_ACCESS_REJECTED = "REMOTE_ACCESS_REJECTED %s - [%s] %s %s %d%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); public SchemaRegistryEventHandler( - LongFunction supplyNamespace, - LongFunction supplyLocalName, + LongFunction supplyQName, PrintStream out) { - super(supplyNamespace, supplyLocalName, out); + super(supplyQName, out); } public void handleEvent( @@ -47,10 +46,9 @@ public void handleEvent( { case REMOTE_ACCESS_REJECTED: SchemaRegistryRemoteAccessRejectedFW e = event.remoteAccessRejected(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(REMOTE_ACCESS_REJECTED, namespace, binding, asDateTime(e.timestamp()), asString(e.method()), - asString(e.url()), e.status()); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(REMOTE_ACCESS_REJECTED, qname, asDateTime(e.timestamp()), asString(e.method()), asString(e.url()), + e.status()); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 936eabbf29..fdc7f34f2b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -27,33 +27,30 @@ public class StdoutEventsStream { private final MessageReader readEvent; - private final ToIntFunction supplyTypeId; private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( MessageReader readEvent, - LongFunction supplyNamespace, - LongFunction supplyLocalName, + LongFunction supplyQName, ToIntFunction supplyTypeId, PrintStream out) { this.readEvent = readEvent; - this.supplyTypeId = supplyTypeId; - final HttpEventHandler httpEventHandler = new HttpEventHandler(supplyNamespace, supplyLocalName, out); - final KafkaEventHandler kafkaEventHandler = new KafkaEventHandler(supplyNamespace, supplyLocalName, out); - final MqttEventHandler mqttEventHandler = new MqttEventHandler(supplyNamespace, supplyLocalName, out); + final HttpEventHandler httpEventHandler = new HttpEventHandler(supplyQName, out); + final KafkaEventHandler kafkaEventHandler = new KafkaEventHandler(supplyQName, out); + final MqttEventHandler mqttEventHandler = new MqttEventHandler(supplyQName, out); final SchemaRegistryEventHandler schemaRegistryEventHandler = - new SchemaRegistryEventHandler(supplyNamespace, supplyLocalName, out); - final TcpEventHandler tcpEventHandler = new TcpEventHandler(supplyNamespace, supplyLocalName, out); - final TlsEventHandler tlsEventHandler = new TlsEventHandler(supplyNamespace, supplyLocalName, out); + new SchemaRegistryEventHandler(supplyQName, out); + final TcpEventHandler tcpEventHandler = new TcpEventHandler(supplyQName, out); + final TlsEventHandler tlsEventHandler = new TlsEventHandler(supplyQName, out); final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); - addEventHandler(eventHandlers, "http", httpEventHandler::handleEvent); - addEventHandler(eventHandlers, "kafka", kafkaEventHandler::handleEvent); - addEventHandler(eventHandlers, "mqtt", mqttEventHandler::handleEvent); - addEventHandler(eventHandlers, "schema-registry", schemaRegistryEventHandler::handleEvent); - addEventHandler(eventHandlers, "tcp", tcpEventHandler::handleEvent); - addEventHandler(eventHandlers, "tls", tlsEventHandler::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("http"), httpEventHandler::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("kafka"), kafkaEventHandler::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("mqtt"), mqttEventHandler::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("schema-registry"), schemaRegistryEventHandler::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("tcp"), tcpEventHandler::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("tls"), tlsEventHandler::handleEvent); this.eventHandlers = eventHandlers; } @@ -62,18 +59,6 @@ public int process() return readEvent.read(this::handleEvent, 1); } - private void addEventHandler( - Int2ObjectHashMap eventHandlers, - String type, - MessageConsumer consumer) - { - int labelId = supplyTypeId.applyAsInt(type); - if (labelId != 0) - { - eventHandlers.put(labelId, consumer); - } - } - private void handleEvent( int msgTypeId, DirectBuffer buffer, diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java index 6d590fb574..839b188529 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java @@ -24,16 +24,15 @@ public class TcpEventHandler extends EventHandler { - private static final String DNS_FAILED_FORMAT = "DNS_FAILED %s.%s - [%s] %s%n"; + private static final String DNS_FAILED_FORMAT = "DNS_FAILED %s - [%s] %s%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); public TcpEventHandler( - LongFunction supplyNamespace, - LongFunction supplyLocalName, + LongFunction supplyQName, PrintStream out) { - super(supplyNamespace, supplyLocalName, out); + super(supplyQName, out); } public void handleEvent( @@ -47,9 +46,8 @@ public void handleEvent( { case DNS_FAILED: TcpDnsFailedFW e = event.dnsFailed(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(DNS_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp()), asString(e.address())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(DNS_FAILED_FORMAT, qname, asDateTime(e.timestamp()), asString(e.address())); break; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java index 0295a1d4b8..16a0961eed 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java @@ -24,20 +24,19 @@ public class TlsEventHandler extends EventHandler { - private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s.%s - [%s]%n"; - private static final String PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s.%s - [%s]%n"; - private static final String KEY_REJECTED_FORMAT = "KEY_REJECTED %s.%s - [%s]%n"; - private static final String PEER_NOT_VERIFIED_FORMAT = "PEER_NOT_VERIFIED %s.%s - [%s]%n"; - private static final String HANDSHAKE_FAILED_FORMAT = "HANDSHAKE_FAILED %s.%s - [%s]%n"; + private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s - [%s]%n"; + private static final String PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s - [%s]%n"; + private static final String KEY_REJECTED_FORMAT = "KEY_REJECTED %s - [%s]%n"; + private static final String PEER_NOT_VERIFIED_FORMAT = "PEER_NOT_VERIFIED %s - [%s]%n"; + private static final String HANDSHAKE_FAILED_FORMAT = "HANDSHAKE_FAILED %s - [%s]%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); public TlsEventHandler( - LongFunction supplyNamespace, - LongFunction supplyLocalName, + LongFunction supplyQName, PrintStream out) { - super(supplyNamespace, supplyLocalName, out); + super(supplyQName, out); } public void handleEvent( @@ -52,41 +51,36 @@ public void handleEvent( case TLS_FAILED: { EventFW e = event.tlsFailed(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(TLS_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(TLS_FAILED_FORMAT, qname, asDateTime(e.timestamp())); break; } case TLS_PROTOCOL_REJECTED: { EventFW e = event.tlsProtocolRejected(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(PROTOCOL_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(PROTOCOL_REJECTED_FORMAT, qname, asDateTime(e.timestamp())); break; } case TLS_KEY_REJECTED: { EventFW e = event.tlsKeyRejected(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(KEY_REJECTED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(KEY_REJECTED_FORMAT, qname, asDateTime(e.timestamp())); break; } case TLS_PEER_NOT_VERIFIED: { EventFW e = event.tlsPeerNotVerified(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(PEER_NOT_VERIFIED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(PEER_NOT_VERIFIED_FORMAT, qname, asDateTime(e.timestamp())); break; } case TLS_HANDSHAKE_FAILED: { EventFW e = event.tlsHandshakeFailed(); - String namespace = supplyNamespace.apply(e.namespacedId()); - String binding = supplyLocalName.apply(e.namespacedId()); - out.printf(HANDSHAKE_FAILED_FORMAT, namespace, binding, asDateTime(e.timestamp())); + String qname = supplyQName.apply(e.namespacedId()); + out.printf(HANDSHAKE_FAILED_FORMAT, qname, asDateTime(e.timestamp())); break; } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java index 03d54e65d3..0360890834 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/EngineContext.java @@ -119,6 +119,9 @@ String supplyNamespace( String supplyLocalName( long namespacedId); + String supplyQName( + long namespacedId); + BindingHandler streamFactory(); GuardHandler supplyGuard( diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java index e06acbce46..f07bfe1a2f 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/registry/EngineWorker.java @@ -454,6 +454,14 @@ public String supplyLocalName( return labels.lookupLabel(NamespacedId.localId(namespacedId)); } + @Override + public String supplyQName( + long namespacedId) + { + return String.format("%s.%s", labels.lookupLabel(NamespacedId.namespaceId(namespacedId)), + labels.lookupLabel(NamespacedId.localId(namespacedId))); + } + @Override public int supplyTypeId( String name) From 96f0866e62077e7fe772d0d9227d211de64ef1d2 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 11:47:05 +0100 Subject: [PATCH 135/167] fix Stdout*Handler --- .../internal/stream/StdoutEventsStream.java | 20 +++++++------------ ...entHandler.java => StdoutHttpHandler.java} | 4 ++-- ...ntHandler.java => StdoutKafkaHandler.java} | 4 ++-- ...entHandler.java => StdoutMqttHandler.java} | 4 ++-- ....java => StdoutSchemaRegistryHandler.java} | 4 ++-- ...ventHandler.java => StdoutTcpHandler.java} | 4 ++-- ...ventHandler.java => StdoutTlsHandler.java} | 4 ++-- 7 files changed, 19 insertions(+), 25 deletions(-) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/{HttpEventHandler.java => StdoutHttpHandler.java} (96%) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/{KafkaEventHandler.java => StdoutKafkaHandler.java} (96%) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/{MqttEventHandler.java => StdoutMqttHandler.java} (95%) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/{SchemaRegistryEventHandler.java => StdoutSchemaRegistryHandler.java} (94%) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/{TcpEventHandler.java => StdoutTcpHandler.java} (95%) rename incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/{TlsEventHandler.java => StdoutTlsHandler.java} (97%) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index fdc7f34f2b..0785079140 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -37,20 +37,14 @@ public StdoutEventsStream( { this.readEvent = readEvent; - final HttpEventHandler httpEventHandler = new HttpEventHandler(supplyQName, out); - final KafkaEventHandler kafkaEventHandler = new KafkaEventHandler(supplyQName, out); - final MqttEventHandler mqttEventHandler = new MqttEventHandler(supplyQName, out); - final SchemaRegistryEventHandler schemaRegistryEventHandler = - new SchemaRegistryEventHandler(supplyQName, out); - final TcpEventHandler tcpEventHandler = new TcpEventHandler(supplyQName, out); - final TlsEventHandler tlsEventHandler = new TlsEventHandler(supplyQName, out); final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); - eventHandlers.put(supplyTypeId.applyAsInt("http"), httpEventHandler::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("kafka"), kafkaEventHandler::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("mqtt"), mqttEventHandler::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("schema-registry"), schemaRegistryEventHandler::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("tcp"), tcpEventHandler::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("tls"), tlsEventHandler::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("http"), new StdoutHttpHandler(supplyQName, out)::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("kafka"), new StdoutKafkaHandler(supplyQName, out)::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("mqtt"), new StdoutMqttHandler(supplyQName, out)::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("schema-registry"), + new StdoutSchemaRegistryHandler(supplyQName, out)::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("tcp"), new StdoutTcpHandler(supplyQName, out)::handleEvent); + eventHandlers.put(supplyTypeId.applyAsInt("tls"), new StdoutTlsHandler(supplyQName, out)::handleEvent); this.eventHandlers = eventHandlers; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java similarity index 96% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java index 7a22b7cb49..693109ded3 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/HttpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java @@ -22,14 +22,14 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpDefaultEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; -public class HttpEventHandler extends EventHandler +public class StdoutHttpHandler extends EventHandler { private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s %s [%s]%n"; private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s %s [%s]%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); - public HttpEventHandler( + public StdoutHttpHandler( LongFunction supplyQName, PrintStream out) { diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java similarity index 96% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java index cffca047f1..5d4de61cde 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/KafkaEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java @@ -22,14 +22,14 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; -public class KafkaEventHandler extends EventHandler +public class StdoutKafkaHandler extends EventHandler { private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s - [%s]%n"; private static final String API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s - [%s]%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); - public KafkaEventHandler( + public StdoutKafkaHandler( LongFunction supplyQName, PrintStream out) { diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java similarity index 95% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java index dba909fad2..93f99fb6e3 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/MqttEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java @@ -22,13 +22,13 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationFailedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; -public class MqttEventHandler extends EventHandler +public class StdoutMqttHandler extends EventHandler { private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s %s [%s]%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); - public MqttEventHandler( + public StdoutMqttHandler( LongFunction supplyQName, PrintStream out) { diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java similarity index 94% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java index 28e9f3a088..4c6ae9fba5 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/SchemaRegistryEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java @@ -22,13 +22,13 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryRemoteAccessRejectedFW; -public class SchemaRegistryEventHandler extends EventHandler +public class StdoutSchemaRegistryHandler extends EventHandler { private static final String REMOTE_ACCESS_REJECTED = "REMOTE_ACCESS_REJECTED %s - [%s] %s %s %d%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); - public SchemaRegistryEventHandler( + public StdoutSchemaRegistryHandler( LongFunction supplyQName, PrintStream out) { diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java similarity index 95% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java index 839b188529..f0d8c0eec0 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TcpEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java @@ -22,13 +22,13 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpDnsFailedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; -public class TcpEventHandler extends EventHandler +public class StdoutTcpHandler extends EventHandler { private static final String DNS_FAILED_FORMAT = "DNS_FAILED %s - [%s] %s%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); - public TcpEventHandler( + public StdoutTcpHandler( LongFunction supplyQName, PrintStream out) { diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java similarity index 97% rename from incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java rename to incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java index 16a0961eed..ef4d4753a6 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/TlsEventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java @@ -22,7 +22,7 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; -public class TlsEventHandler extends EventHandler +public class StdoutTlsHandler extends EventHandler { private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s - [%s]%n"; private static final String PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s - [%s]%n"; @@ -32,7 +32,7 @@ public class TlsEventHandler extends EventHandler private final TlsEventFW tlsEventRO = new TlsEventFW(); - public TlsEventHandler( + public StdoutTlsHandler( LongFunction supplyQName, PrintStream out) { From 12afe609015d29fd1ebbd4a80ef2372e97923db5 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 12:10:01 +0100 Subject: [PATCH 136/167] fix context --- .../internal/StdoutExporterContext.java | 18 +++++++++++++++ .../internal/StdoutExporterHandler.java | 7 +++--- .../stdout/internal/stream/EventHandler.java | 8 +++---- .../internal/stream/StdoutEventsStream.java | 23 ++++++++----------- .../internal/stream/StdoutHttpHandler.java | 10 ++++---- .../internal/stream/StdoutKafkaHandler.java | 10 ++++---- .../internal/stream/StdoutMqttHandler.java | 8 +++---- .../stream/StdoutSchemaRegistryHandler.java | 8 +++---- .../internal/stream/StdoutTcpHandler.java | 8 +++---- .../internal/stream/StdoutTlsHandler.java | 16 ++++++------- 10 files changed, 65 insertions(+), 51 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java index c01aba6dc4..bb8d7d3adb 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterContext.java @@ -18,6 +18,7 @@ import java.util.function.LongFunction; import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageReader; import io.aklivity.zilla.runtime.engine.config.AttributeConfig; import io.aklivity.zilla.runtime.engine.config.ExporterConfig; import io.aklivity.zilla.runtime.engine.config.KindConfig; @@ -55,4 +56,21 @@ public void detach( long exporterId) { } + + public String supplyQName( + long namespacedId) + { + return context.supplyQName(namespacedId); + } + + public int supplyTypeId( + String name) + { + return context.supplyTypeId(name); + } + + public MessageReader supplyEventReader() + { + return context.supplyEventReader(); + } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index e2c34daa17..6085f06fc3 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -23,7 +23,7 @@ public class StdoutExporterHandler implements ExporterHandler { - private final EngineContext context; + private final StdoutExporterContext context; private final PrintStream out; private StdoutEventsStream stdoutEventsStream; @@ -33,15 +33,14 @@ public StdoutExporterHandler( EngineContext context, StdoutExporterConfig exporter) { - this.context = context; + this.context = new StdoutExporterContext(config, context); this.out = config.output(); } @Override public void start() { - stdoutEventsStream = new StdoutEventsStream(context.supplyEventReader(), context::supplyQName, - context::supplyTypeId, out); + stdoutEventsStream = new StdoutEventsStream(context, out); } @Override diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java index 37e2b5af5a..f8f2a84e8b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/EventHandler.java @@ -19,24 +19,24 @@ import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.function.LongFunction; import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.StringFW; public abstract class EventHandler { protected static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z"); - protected final LongFunction supplyQName; + protected final StdoutExporterContext context; protected final PrintStream out; public EventHandler( - LongFunction supplyQName, + StdoutExporterContext context, PrintStream out) { - this.supplyQName = supplyQName; + this.context = context; this.out = out; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 0785079140..81db687ec8 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -15,14 +15,13 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; -import java.util.function.LongFunction; -import java.util.function.ToIntFunction; import org.agrona.DirectBuffer; import org.agrona.collections.Int2ObjectHashMap; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; import io.aklivity.zilla.runtime.engine.binding.function.MessageReader; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; public class StdoutEventsStream { @@ -30,21 +29,19 @@ public class StdoutEventsStream private final Int2ObjectHashMap eventHandlers; public StdoutEventsStream( - MessageReader readEvent, - LongFunction supplyQName, - ToIntFunction supplyTypeId, + StdoutExporterContext context, PrintStream out) { - this.readEvent = readEvent; + this.readEvent = context.supplyEventReader(); final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); - eventHandlers.put(supplyTypeId.applyAsInt("http"), new StdoutHttpHandler(supplyQName, out)::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("kafka"), new StdoutKafkaHandler(supplyQName, out)::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("mqtt"), new StdoutMqttHandler(supplyQName, out)::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("schema-registry"), - new StdoutSchemaRegistryHandler(supplyQName, out)::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("tcp"), new StdoutTcpHandler(supplyQName, out)::handleEvent); - eventHandlers.put(supplyTypeId.applyAsInt("tls"), new StdoutTlsHandler(supplyQName, out)::handleEvent); + eventHandlers.put(context.supplyTypeId("http"), new StdoutHttpHandler(context, out)::handleEvent); + eventHandlers.put(context.supplyTypeId("kafka"), new StdoutKafkaHandler(context, out)::handleEvent); + eventHandlers.put(context.supplyTypeId("mqtt"), new StdoutMqttHandler(context, out)::handleEvent); + eventHandlers.put(context.supplyTypeId("schema-registry"), + new StdoutSchemaRegistryHandler(context, out)::handleEvent); + eventHandlers.put(context.supplyTypeId("tcp"), new StdoutTcpHandler(context, out)::handleEvent); + eventHandlers.put(context.supplyTypeId("tls"), new StdoutTlsHandler(context, out)::handleEvent); this.eventHandlers = eventHandlers; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java index 693109ded3..197aa07fb2 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java @@ -15,10 +15,10 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; -import java.util.function.LongFunction; import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpDefaultEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; @@ -30,10 +30,10 @@ public class StdoutHttpHandler extends EventHandler private final HttpEventFW httpEventRO = new HttpEventFW(); public StdoutHttpHandler( - LongFunction supplyQName, + StdoutExporterContext context, PrintStream out) { - super(supplyQName, out); + super(context, out); } public void handleEvent( @@ -48,14 +48,14 @@ public void handleEvent( case AUTHORIZATION_FAILED: { HttpDefaultEventFW e = event.authorizationFailed(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); break; } case REQUEST_ACCEPTED: { HttpDefaultEventFW e = event.requestAccepted(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.format(REQUEST_ACCEPTED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java index 5d4de61cde..ac6a1b040f 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java @@ -15,10 +15,10 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; -import java.util.function.LongFunction; import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; @@ -30,10 +30,10 @@ public class StdoutKafkaHandler extends EventHandler private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); public StdoutKafkaHandler( - LongFunction supplyQName, + StdoutExporterContext context, PrintStream out) { - super(supplyQName, out); + super(context, out); } public void handleEvent( @@ -48,14 +48,14 @@ public void handleEvent( case AUTHORIZATION_FAILED: { EventFW e = event.authorizationFailed(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(AUTHORIZATION_FAILED_FORMAT, qname, asDateTime(e.timestamp())); break; } case API_VERSION_REJECTED: { EventFW e = event.apiVersionRejected(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(API_VERSION_REJECTED_FORMAT, qname, asDateTime(e.timestamp())); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java index 93f99fb6e3..e3fa1faeaa 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java @@ -15,10 +15,10 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; -import java.util.function.LongFunction; import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationFailedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; @@ -29,10 +29,10 @@ public class StdoutMqttHandler extends EventHandler private final MqttEventFW mqttEventRO = new MqttEventFW(); public StdoutMqttHandler( - LongFunction supplyQName, + StdoutExporterContext context, PrintStream out) { - super(supplyQName, out); + super(context, out); } public void handleEvent( @@ -46,7 +46,7 @@ public void handleEvent( { case AUTHORIZATION_FAILED: MqttAuthorizationFailedFW e = event.authorizationFailed(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java index 4c6ae9fba5..42ed197bbf 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java @@ -15,10 +15,10 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; -import java.util.function.LongFunction; import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.SchemaRegistryRemoteAccessRejectedFW; @@ -29,10 +29,10 @@ public class StdoutSchemaRegistryHandler extends EventHandler private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); public StdoutSchemaRegistryHandler( - LongFunction supplyQName, + StdoutExporterContext context, PrintStream out) { - super(supplyQName, out); + super(context, out); } public void handleEvent( @@ -46,7 +46,7 @@ public void handleEvent( { case REMOTE_ACCESS_REJECTED: SchemaRegistryRemoteAccessRejectedFW e = event.remoteAccessRejected(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(REMOTE_ACCESS_REJECTED, qname, asDateTime(e.timestamp()), asString(e.method()), asString(e.url()), e.status()); break; diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java index f0d8c0eec0..1da54d0e4b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java @@ -15,10 +15,10 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; -import java.util.function.LongFunction; import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpDnsFailedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TcpEventFW; @@ -29,10 +29,10 @@ public class StdoutTcpHandler extends EventHandler private final TcpEventFW tcpEventRO = new TcpEventFW(); public StdoutTcpHandler( - LongFunction supplyQName, + StdoutExporterContext context, PrintStream out) { - super(supplyQName, out); + super(context, out); } public void handleEvent( @@ -46,7 +46,7 @@ public void handleEvent( { case DNS_FAILED: TcpDnsFailedFW e = event.dnsFailed(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(DNS_FAILED_FORMAT, qname, asDateTime(e.timestamp()), asString(e.address())); break; } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java index ef4d4753a6..5d96aa5e27 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java @@ -15,10 +15,10 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; import java.io.PrintStream; -import java.util.function.LongFunction; import org.agrona.DirectBuffer; +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.TlsEventFW; @@ -33,10 +33,10 @@ public class StdoutTlsHandler extends EventHandler private final TlsEventFW tlsEventRO = new TlsEventFW(); public StdoutTlsHandler( - LongFunction supplyQName, + StdoutExporterContext context, PrintStream out) { - super(supplyQName, out); + super(context, out); } public void handleEvent( @@ -51,35 +51,35 @@ public void handleEvent( case TLS_FAILED: { EventFW e = event.tlsFailed(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(TLS_FAILED_FORMAT, qname, asDateTime(e.timestamp())); break; } case TLS_PROTOCOL_REJECTED: { EventFW e = event.tlsProtocolRejected(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(PROTOCOL_REJECTED_FORMAT, qname, asDateTime(e.timestamp())); break; } case TLS_KEY_REJECTED: { EventFW e = event.tlsKeyRejected(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(KEY_REJECTED_FORMAT, qname, asDateTime(e.timestamp())); break; } case TLS_PEER_NOT_VERIFIED: { EventFW e = event.tlsPeerNotVerified(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(PEER_NOT_VERIFIED_FORMAT, qname, asDateTime(e.timestamp())); break; } case TLS_HANDSHAKE_FAILED: { EventFW e = event.tlsHandshakeFailed(); - String qname = supplyQName.apply(e.namespacedId()); + String qname = context.supplyQName(e.namespacedId()); out.printf(HANDSHAKE_FAILED_FORMAT, qname, asDateTime(e.timestamp())); break; } From 94c2e69634834d266473278d9e005f955c687743 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 17:01:19 +0100 Subject: [PATCH 137/167] fix http add fields --- .../internal/stream/StdoutHttpHandler.java | 12 ++++--- .../http/internal/HttpEventContext.java | 36 ++++++++++++++++++- .../internal/stream/HttpServerFactory.java | 4 +-- .../main/resources/META-INF/zilla/http.idl | 14 ++++++-- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java index 197aa07fb2..3cdc5ddc88 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java @@ -19,13 +19,14 @@ import org.agrona.DirectBuffer; import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpDefaultEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFailedEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestAcceptedEventFW; public class StdoutHttpHandler extends EventHandler { private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s %s [%s]%n"; - private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s %s [%s]%n"; + private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s %s [%s] %s %s %s%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -47,16 +48,17 @@ public void handleEvent( { case AUTHORIZATION_FAILED: { - HttpDefaultEventFW e = event.authorizationFailed(); + HttpAuthorizationFailedEventFW e = event.authorizationFailed(); String qname = context.supplyQName(e.namespacedId()); out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); break; } case REQUEST_ACCEPTED: { - HttpDefaultEventFW e = event.requestAccepted(); + HttpRequestAcceptedEventFW e = event.requestAccepted(); String qname = context.supplyQName(e.namespacedId()); - out.format(REQUEST_ACCEPTED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); + out.format(REQUEST_ACCEPTED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp()), asString(e.scheme()), + asString(e.method()), asString(e.path())); break; } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index cc50ae3869..045c69d330 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -17,10 +17,14 @@ import java.nio.ByteBuffer; import java.time.Clock; +import java.util.Map; import org.agrona.concurrent.AtomicBuffer; import org.agrona.concurrent.UnsafeBuffer; +import io.aklivity.zilla.runtime.binding.http.internal.types.Array32FW; +import io.aklivity.zilla.runtime.binding.http.internal.types.HttpHeaderFW; +import io.aklivity.zilla.runtime.binding.http.internal.types.String8FW; import io.aklivity.zilla.runtime.binding.http.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; @@ -29,6 +33,9 @@ public class HttpEventContext { private static final int EVENT_BUFFER_CAPACITY = 2048; + private static final String8FW HEADER_SCHEME = new String8FW(":scheme"); + private static final String8FW HEADER_METHOD = new String8FW(":method"); + private static final String8FW HEADER_PATH = new String8FW(":path"); private final AtomicBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); private final HttpEventFW.Builder httpEventRW = new HttpEventFW.Builder(); @@ -71,7 +78,31 @@ public void requestAccepted( long traceId, long routedId, GuardHandler guard, - long authorization) + long authorization, + Map headers) + { + String identity = guard == null ? null : guard.identity(authorization); + HttpEventFW event = httpEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .requestAccepted(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(routedId) + .identity(identity) + .scheme(headers.get(":scheme")) + .method(headers.get(":method")) + .path(headers.get(":path")) + ) + .build(); + eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); + } + + public void requestAccepted( + long traceId, + long routedId, + GuardHandler guard, + long authorization, + Array32FW headers) { String identity = guard == null ? null : guard.identity(authorization); HttpEventFW event = httpEventRW @@ -81,6 +112,9 @@ public void requestAccepted( .traceId(traceId) .namespacedId(routedId) .identity(identity) + .scheme(headers.matchFirst(h -> HEADER_SCHEME.equals(h.name())).value().asString()) + .method(headers.matchFirst(h -> HEADER_METHOD.equals(h.name())).value().asString()) + .path(headers.matchFirst(h -> HEADER_PATH.equals(h.name())).value().asString()) ) .build(); eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 25b60a774d..987a44b51f 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -2272,7 +2272,7 @@ private boolean onDecodeHeaders( final HttpHeaderFW connection = beginEx.headers().matchFirst(h -> HEADER_CONNECTION.equals(h.name())); exchange.responseClosing = connection != null && connectionClose.reset(connection.value().asString()).matches(); - event.requestAccepted(traceId, routedId, guard, authorization); + event.requestAccepted(traceId, routedId, guard, authorization, beginEx.headers()); this.exchange = exchange; } return headersValid; @@ -4928,7 +4928,7 @@ else if (headersDecoder.httpError()) else { final Map headers = headersDecoder.headers; - event.requestAccepted(traceId, routedId, guard, authorization); + event.requestAccepted(traceId, routedId, guard, authorization, headers); if (isCorsPreflightRequest(headers)) { if (!endRequest) diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 0acc108044..d480d6a0d4 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -58,15 +58,23 @@ scope http REQUEST_ACCEPTED (2) } - struct HttpDefaultEvent extends core::event::Event + struct HttpAuthorizationFailedEvent extends core::event::Event { string8 identity; } + struct HttpRequestAcceptedEvent extends core::event::Event + { + string8 identity; + string8 scheme; + string8 method; + string16 path; + } + union HttpEvent switch (HttpEventType) { - case AUTHORIZATION_FAILED: HttpDefaultEvent authorizationFailed; - case REQUEST_ACCEPTED: HttpDefaultEvent requestAccepted; + case AUTHORIZATION_FAILED: HttpAuthorizationFailedEvent authorizationFailed; + case REQUEST_ACCEPTED: HttpRequestAcceptedEvent requestAccepted; } } } From 858be23a7f805b268a985083194da945f759154d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 17:12:21 +0100 Subject: [PATCH 138/167] fix http event names --- .../stdout/internal/stream/StdoutHttpHandler.java | 8 ++++---- .../src/main/resources/META-INF/zilla/http.idl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java index 3cdc5ddc88..0b6dd63a47 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java @@ -19,9 +19,9 @@ import org.agrona.DirectBuffer; import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFailedEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFailedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestAcceptedEventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestAcceptedFW; public class StdoutHttpHandler extends EventHandler { @@ -48,14 +48,14 @@ public void handleEvent( { case AUTHORIZATION_FAILED: { - HttpAuthorizationFailedEventFW e = event.authorizationFailed(); + HttpAuthorizationFailedFW e = event.authorizationFailed(); String qname = context.supplyQName(e.namespacedId()); out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); break; } case REQUEST_ACCEPTED: { - HttpRequestAcceptedEventFW e = event.requestAccepted(); + HttpRequestAcceptedFW e = event.requestAccepted(); String qname = context.supplyQName(e.namespacedId()); out.format(REQUEST_ACCEPTED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp()), asString(e.scheme()), asString(e.method()), asString(e.path())); diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index d480d6a0d4..db62371dd1 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -58,12 +58,12 @@ scope http REQUEST_ACCEPTED (2) } - struct HttpAuthorizationFailedEvent extends core::event::Event + struct HttpAuthorizationFailed extends core::event::Event { string8 identity; } - struct HttpRequestAcceptedEvent extends core::event::Event + struct HttpRequestAccepted extends core::event::Event { string8 identity; string8 scheme; @@ -73,8 +73,8 @@ scope http union HttpEvent switch (HttpEventType) { - case AUTHORIZATION_FAILED: HttpAuthorizationFailedEvent authorizationFailed; - case REQUEST_ACCEPTED: HttpRequestAcceptedEvent requestAccepted; + case AUTHORIZATION_FAILED: HttpAuthorizationFailed authorizationFailed; + case REQUEST_ACCEPTED: HttpRequestAccepted requestAccepted; } } } From 9f2d72a5332ad65f9d58d5ea1da5336ecb61dc49 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 17:19:59 +0100 Subject: [PATCH 139/167] fix add http authority --- .../exporter/stdout/internal/stream/StdoutHttpHandler.java | 4 ++-- .../zilla/runtime/binding/http/internal/HttpEventContext.java | 3 +++ .../src/main/resources/META-INF/zilla/http.idl | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java index 0b6dd63a47..3f28e63722 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java @@ -26,7 +26,7 @@ public class StdoutHttpHandler extends EventHandler { private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s %s [%s]%n"; - private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s %s [%s] %s %s %s%n"; + private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s %s [%s] %s %s %s %s%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -58,7 +58,7 @@ public void handleEvent( HttpRequestAcceptedFW e = event.requestAccepted(); String qname = context.supplyQName(e.namespacedId()); out.format(REQUEST_ACCEPTED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp()), asString(e.scheme()), - asString(e.method()), asString(e.path())); + asString(e.method()), asString(e.authority()), asString(e.path())); break; } } diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 045c69d330..45616e2046 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -35,6 +35,7 @@ public class HttpEventContext private static final int EVENT_BUFFER_CAPACITY = 2048; private static final String8FW HEADER_SCHEME = new String8FW(":scheme"); private static final String8FW HEADER_METHOD = new String8FW(":method"); + private static final String8FW HEADER_AUTHORITY = new String8FW(":authority"); private static final String8FW HEADER_PATH = new String8FW(":path"); private final AtomicBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); @@ -91,6 +92,7 @@ public void requestAccepted( .identity(identity) .scheme(headers.get(":scheme")) .method(headers.get(":method")) + .authority(headers.get(":authority")) .path(headers.get(":path")) ) .build(); @@ -114,6 +116,7 @@ public void requestAccepted( .identity(identity) .scheme(headers.matchFirst(h -> HEADER_SCHEME.equals(h.name())).value().asString()) .method(headers.matchFirst(h -> HEADER_METHOD.equals(h.name())).value().asString()) + .authority(headers.matchFirst(h -> HEADER_AUTHORITY.equals(h.name())).value().asString()) .path(headers.matchFirst(h -> HEADER_PATH.equals(h.name())).value().asString()) ) .build(); diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index db62371dd1..61f9bce246 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -68,6 +68,7 @@ scope http string8 identity; string8 scheme; string8 method; + string16 authority; string16 path; } From e807d0427067ad75163a194a6827f6903898ec9e Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Thu, 22 Feb 2024 17:52:37 +0100 Subject: [PATCH 140/167] fix --- runtime/binding-tls/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/binding-tls/pom.xml b/runtime/binding-tls/pom.xml index 4e4f751993..1fd6bcd4d1 100644 --- a/runtime/binding-tls/pom.xml +++ b/runtime/binding-tls/pom.xml @@ -26,7 +26,7 @@ 11 11 - 0.76 + 0.75 0 From bd9c1a4288bfe6aef62a190a011a808bcdeaada7 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 08:39:10 +0100 Subject: [PATCH 141/167] impl first k3po test in stdexp --- incubator/exporter-stdout.spec/pom.xml | 2 +- .../my_server.authorization.credentials.yaml | 48 +++++++++++++ incubator/exporter-stdout/pom.xml | 8 ++- .../stdout/internal/StdoutConfiguration.java | 37 +++++++++- .../internal/StdoutExporterHandler.java | 8 +-- .../internal/events/Http11EventsIT.java | 68 +++++++++++++++++++ .../internal/events/StdoutOutputRule.java | 64 +++++++++++++++++ 7 files changed, 228 insertions(+), 7 deletions(-) create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/my_server.authorization.credentials.yaml create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/StdoutOutputRule.java diff --git a/incubator/exporter-stdout.spec/pom.xml b/incubator/exporter-stdout.spec/pom.xml index b786f0b919..5d2ed40d44 100644 --- a/incubator/exporter-stdout.spec/pom.xml +++ b/incubator/exporter-stdout.spec/pom.xml @@ -9,7 +9,7 @@ io.aklivity.zilla specs develop-SNAPSHOT - ../../specs/pom.xml + ../pom.xml exporter-stdout.spec diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/my_server.authorization.credentials.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/my_server.authorization.credentials.yaml new file mode 100644 index 0000000000..29be8c74a1 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/my_server.authorization.credentials.yaml @@ -0,0 +1,48 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +--- +name: test +telemetry: + exporters: + stdout0: + type: stdout +guards: + test0: + type: test + options: + credentials: TOKEN + lifetime: PT5S + challenge: PT5S +bindings: + net0: + type: http + kind: server + options: + versions: + - http/1.1 + authorization: + test0: + credentials: + cookies: + access_token: "{credentials}" + headers: + authorization: Bearer {credentials} + query: + access_token: "{credentials}" + routes: + - exit: app0 + guarded: + test0: [] diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 9293a5415c..6586d468d5 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -7,7 +7,7 @@ 4.0.0 io.aklivity.zilla - runtime + incubator develop-SNAPSHOT ../pom.xml @@ -86,6 +86,12 @@ ${project.version} test + + ${project.groupId} + binding-http + ${project.version} + test + junit junit diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutConfiguration.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutConfiguration.java index 9d47705dec..bbc9cfb038 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutConfiguration.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutConfiguration.java @@ -15,18 +15,53 @@ package io.aklivity.zilla.runtime.exporter.stdout.internal; import java.io.PrintStream; +import java.lang.reflect.Field; + +import org.agrona.LangUtil; import io.aklivity.zilla.runtime.engine.Configuration; public class StdoutConfiguration extends Configuration { + private static final ConfigurationDef STDOUT_CONFIG; + + public static final PropertyDef STDOUT_OUTPUT; + + static + { + final ConfigurationDef config = new ConfigurationDef("zilla.exporter.stdout"); + STDOUT_OUTPUT = config.property(PrintStream.class, "output", + StdoutConfiguration::decodeOutput, c -> System.out); + STDOUT_CONFIG = config; + } + public StdoutConfiguration( Configuration config) { + super(STDOUT_CONFIG, config); } public PrintStream output() { - return System.out; + return STDOUT_OUTPUT.get(this); + } + + private static PrintStream decodeOutput( + Configuration config, + String value) + { + try + { + int fieldAt = value.lastIndexOf("."); + Class ownerClass = Class.forName(value.substring(0, fieldAt)); + String fieldName = value.substring(fieldAt + 1); + Field field = ownerClass.getDeclaredField(fieldName); + return (PrintStream) field.get(null); + } + catch (Throwable ex) + { + LangUtil.rethrowUnchecked(ex); + } + return null; } } diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java index 6085f06fc3..98a0ed322e 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/StdoutExporterHandler.java @@ -26,7 +26,7 @@ public class StdoutExporterHandler implements ExporterHandler private final StdoutExporterContext context; private final PrintStream out; - private StdoutEventsStream stdoutEventsStream; + private StdoutEventsStream events; public StdoutExporterHandler( StdoutConfiguration config, @@ -40,18 +40,18 @@ public StdoutExporterHandler( @Override public void start() { - stdoutEventsStream = new StdoutEventsStream(context, out); + events = new StdoutEventsStream(context, out); } @Override public int export() { - return stdoutEventsStream.process(); + return events.process(); } @Override public void stop() { - this.stdoutEventsStream = null; + this.events = null; } } diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java new file mode 100644 index 0000000000..2cef378bcb --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.events; + +import static io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration.HTTP_SERVER_HEADER; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import java.util.regex.Pattern; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +import io.aklivity.zilla.runtime.engine.test.EngineRule; +import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; +import io.aklivity.zilla.runtime.engine.test.annotation.Configure; + +public class Http11EventsIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/authorization"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); + + private final EngineRule engine = new EngineRule() + .directory("target/zilla-itests") + .countersBufferCapacity(8192) + .configure(HTTP_SERVER_HEADER, "Zilla") + .configurationRoot("io/aklivity/zilla/specs/binding/http/config/v1.1") + .external("app0") + .clean(); + + private final StdoutOutputRule output = new StdoutOutputRule(); + + @Rule + public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); + + @Test + @Configuration("my_server.authorization.credentials.yaml") + @Specification({ + "${net}/reject.credentials.header/client", + }) + @Configure(name = "zilla.exporter.stdout.output", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + public void shouldRejectCredentialsHeader() throws Exception + { + k3po.finish(); + output.expect(Pattern.compile("AUTHORIZATION_FAILED test.net0 test \\[[^\\]]+\\]\n")); + } +} diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/StdoutOutputRule.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/StdoutOutputRule.java new file mode 100644 index 0000000000..f5f2272985 --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/StdoutOutputRule.java @@ -0,0 +1,64 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.events; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.matchesPattern; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.util.regex.Pattern; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +public final class StdoutOutputRule implements TestRule +{ + public static final PrintStream OUT; + + private static final ByteArrayOutputStream BOS; + + static + { + BOS = new ByteArrayOutputStream(); + OUT = new PrintStream(BOS); + } + + private Pattern expected; + + @Override + public Statement apply( + Statement base, + Description description) + { + return new Statement() + { + @Override + public void evaluate() throws Throwable + { + base.evaluate(); + assertThat(BOS.toString(StandardCharsets.UTF_8), matchesPattern(expected)); + } + }; + } + + public void expect( + Pattern expected) + { + this.expected = expected; + } +} From 434cbee7a095c3f5e04858d454b6e332ed51e903 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 08:46:10 +0100 Subject: [PATCH 142/167] fix stdexp formats --- .../stdout/internal/stream/StdoutHttpHandler.java | 4 ++-- .../stdout/internal/stream/StdoutKafkaHandler.java | 4 ++-- .../stdout/internal/stream/StdoutMqttHandler.java | 2 +- .../internal/stream/StdoutSchemaRegistryHandler.java | 2 +- .../stdout/internal/stream/StdoutTcpHandler.java | 2 +- .../stdout/internal/stream/StdoutTlsHandler.java | 10 +++++----- .../stdout/internal/events/Http11EventsIT.java | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java index 3f28e63722..1a04f254f7 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java @@ -25,8 +25,8 @@ public class StdoutHttpHandler extends EventHandler { - private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s %s [%s]%n"; - private static final String REQUEST_ACCEPTED_FORMAT = "REQUEST_ACCEPTED %s %s [%s] %s %s %s %s%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "%s %s [%s] AUTHORIZATION_FAILED%n"; + private static final String REQUEST_ACCEPTED_FORMAT = "%s %s [%s] REQUEST_ACCEPTED %s %s %s %s%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java index ac6a1b040f..a645dd67fa 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java @@ -24,8 +24,8 @@ public class StdoutKafkaHandler extends EventHandler { - private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s - [%s]%n"; - private static final String API_VERSION_REJECTED_FORMAT = "API_VERSION_REJECTED %s - [%s]%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "%s - [%s] AUTHORIZATION_FAILED%n"; + private static final String API_VERSION_REJECTED_FORMAT = "%s - [%s] API_VERSION_REJECTED%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java index e3fa1faeaa..eeb19ee4f5 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java @@ -24,7 +24,7 @@ public class StdoutMqttHandler extends EventHandler { - private static final String AUTHORIZATION_FAILED_FORMAT = "AUTHORIZATION_FAILED %s %s [%s]%n"; + private static final String AUTHORIZATION_FAILED_FORMAT = "%s %s [%s] AUTHORIZATION_FAILED%n"; private final MqttEventFW mqttEventRO = new MqttEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java index 42ed197bbf..376826b0fd 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutSchemaRegistryHandler.java @@ -24,7 +24,7 @@ public class StdoutSchemaRegistryHandler extends EventHandler { - private static final String REMOTE_ACCESS_REJECTED = "REMOTE_ACCESS_REJECTED %s - [%s] %s %s %d%n"; + private static final String REMOTE_ACCESS_REJECTED = "%s - [%s] REMOTE_ACCESS_REJECTED %s %s %d%n"; private final SchemaRegistryEventFW schemaRegistryEventRO = new SchemaRegistryEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java index 1da54d0e4b..0584a4eddf 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTcpHandler.java @@ -24,7 +24,7 @@ public class StdoutTcpHandler extends EventHandler { - private static final String DNS_FAILED_FORMAT = "DNS_FAILED %s - [%s] %s%n"; + private static final String DNS_FAILED_FORMAT = "%s - [%s] DNS_FAILED %s%n"; private final TcpEventFW tcpEventRO = new TcpEventFW(); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java index 5d96aa5e27..a3ecce6abf 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutTlsHandler.java @@ -24,11 +24,11 @@ public class StdoutTlsHandler extends EventHandler { - private static final String TLS_FAILED_FORMAT = "TLS_FAILED %s - [%s]%n"; - private static final String PROTOCOL_REJECTED_FORMAT = "PROTOCOL_REJECTED %s - [%s]%n"; - private static final String KEY_REJECTED_FORMAT = "KEY_REJECTED %s - [%s]%n"; - private static final String PEER_NOT_VERIFIED_FORMAT = "PEER_NOT_VERIFIED %s - [%s]%n"; - private static final String HANDSHAKE_FAILED_FORMAT = "HANDSHAKE_FAILED %s - [%s]%n"; + private static final String TLS_FAILED_FORMAT = "%s - [%s] TLS_FAILED%n"; + private static final String PROTOCOL_REJECTED_FORMAT = "%s - [%s] PROTOCOL_REJECTED%n"; + private static final String KEY_REJECTED_FORMAT = "%s - [%s] KEY_REJECTED%n"; + private static final String PEER_NOT_VERIFIED_FORMAT = "%s - [%s] PEER_NOT_VERIFIED%n"; + private static final String HANDSHAKE_FAILED_FORMAT = "%s - [%s] HANDSHAKE_FAILED%n"; private final TlsEventFW tlsEventRO = new TlsEventFW(); diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java index 2cef378bcb..af4b79c4f8 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java @@ -63,6 +63,6 @@ public class Http11EventsIT public void shouldRejectCredentialsHeader() throws Exception { k3po.finish(); - output.expect(Pattern.compile("AUTHORIZATION_FAILED test.net0 test \\[[^\\]]+\\]\n")); + output.expect(Pattern.compile("test.net0 test \\[[^\\]]+\\] AUTHORIZATION_FAILED\n")); } } From a0b1ddb2b34395e2475861a25bf91e5218ce6545 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 08:53:42 +0100 Subject: [PATCH 143/167] fix engine test --- runtime/engine/pom.xml | 2 +- .../runtime/engine/internal/EngineTest.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/runtime/engine/pom.xml b/runtime/engine/pom.xml index 0d951c1260..ccea03c210 100644 --- a/runtime/engine/pom.xml +++ b/runtime/engine/pom.xml @@ -27,7 +27,7 @@ 11 11 0.77 - 4 + 3 diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java index 711dca56e2..4ae65aba4e 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/internal/EngineTest.java @@ -34,6 +34,7 @@ import io.aklivity.zilla.runtime.engine.Engine; import io.aklivity.zilla.runtime.engine.EngineConfiguration; +import io.aklivity.zilla.runtime.engine.binding.function.MessageReader; import io.aklivity.zilla.runtime.engine.ext.EngineExtContext; import io.aklivity.zilla.runtime.engine.ext.EngineExtSpi; @@ -250,6 +251,30 @@ public void shouldNotConfigureUnknownScheme() throws Exception } } + @Test + public void shouldReadEvents() + { + List errors = new LinkedList<>(); + EngineConfiguration config = new EngineConfiguration(properties); + try (Engine engine = Engine.builder() + .config(config) + .errorHandler(errors::add) + .build()) + { + engine.start(); + MessageReader events = engine.supplyEventReader(); + events.read((m, b, i, l) -> {}, 1); + } + catch (Throwable ex) + { + errors.add(ex); + } + finally + { + assertThat(errors, empty()); + } + } + public static final class TestEngineExt implements EngineExtSpi { public static volatile CountDownLatch registerLatch = new CountDownLatch(1); From bcd294482702260a9bdd8c1dd2a33d41aee6d2c6 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 09:26:22 +0100 Subject: [PATCH 144/167] fix kafka --- .../internal/stream/StdoutKafkaHandler.java | 7 +++--- .../kafka/internal/KafkaEventContext.java | 8 +++++- .../stream/KafkaClientDescribeFactory.java | 11 +++++++- .../stream/KafkaClientFetchFactory.java | 12 +++++++-- .../stream/KafkaClientGroupFactory.java | 25 +++++++++++++------ .../stream/KafkaClientMetaFactory.java | 12 +++++++-- .../KafkaClientOffsetCommitFactory.java | 3 ++- .../stream/KafkaClientOffsetFetchFactory.java | 3 ++- .../stream/KafkaClientProduceFactory.java | 10 +++++++- .../stream/KafkaClientSaslHandshaker.java | 5 +++- .../main/resources/META-INF/zilla/kafka.idl | 8 +++++- 11 files changed, 83 insertions(+), 21 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java index a645dd67fa..bae2026051 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutKafkaHandler.java @@ -20,12 +20,13 @@ import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.EventFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaApiVersionRejectedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.KafkaEventFW; public class StdoutKafkaHandler extends EventHandler { private static final String AUTHORIZATION_FAILED_FORMAT = "%s - [%s] AUTHORIZATION_FAILED%n"; - private static final String API_VERSION_REJECTED_FORMAT = "%s - [%s] API_VERSION_REJECTED%n"; + private static final String API_VERSION_REJECTED_FORMAT = "%s - [%s] API_VERSION_REJECTED %d %d%n"; private final KafkaEventFW kafkaEventRO = new KafkaEventFW(); @@ -54,9 +55,9 @@ public void handleEvent( } case API_VERSION_REJECTED: { - EventFW e = event.apiVersionRejected(); + KafkaApiVersionRejectedFW e = event.apiVersionRejected(); String qname = context.supplyQName(e.namespacedId()); - out.printf(API_VERSION_REJECTED_FORMAT, qname, asDateTime(e.timestamp())); + out.printf(API_VERSION_REJECTED_FORMAT, qname, asDateTime(e.timestamp()), e.apiKey(), e.apiVersion()); break; } } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 96bcf133c8..6c033b78c1 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -64,13 +64,19 @@ public void authorizationFailed( } public void apiVersionRejected( - long traceId) + long traceId, + long bindingId, + int apiKey, + int apiVersion) { KafkaEventFW event = kafkaEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .apiVersionRejected(e -> e .timestamp(clock.millis()) .traceId(traceId) + .namespacedId(bindingId) + .apiKey(apiKey) + .apiVersion(apiVersion) ) .build(); eventWriter.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java index 1430b779d6..95c1a8dc53 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientDescribeFactory.java @@ -965,7 +965,7 @@ public void onDecodeResource( assert resource.equals(this.topic); break; default: - onDecodeResponseErrorCode(traceId, errorCode); + onDecodeResponseErrorCode(traceId, originId, errorCode); final KafkaResetExFW resetEx = kafkaResetExRW.wrap(extBuffer, 0, extBuffer.capacity()) .typeId(kafkaTypeId) .error(errorCode) @@ -976,6 +976,15 @@ public void onDecodeResource( } } + private void onDecodeResponseErrorCode( + long traceId, + long originId, + int errorCode) + { + super.onDecodeResponseErrorCode(traceId, originId, DESCRIBE_CONFIGS_API_KEY, DESCRIBE_CONFIGS_API_VERSION, + errorCode); + } + private void onNetwork( int msgTypeId, DirectBuffer buffer, diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java index 8da1d13607..b44b82d71c 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientFetchFactory.java @@ -2949,7 +2949,7 @@ private void onDecodeOffsetsPartition( this.nextOffset = partitionOffset; break; default: - onDecodeResponseErrorCode(traceId, errorCode); + onDecodeResponseErrorCode(traceId, originId, errorCode); cleanupApplication(traceId, errorCode); doNetworkEnd(traceId, authorization); break; @@ -2991,7 +2991,7 @@ private void onDecodeFetchPartition( } else { - onDecodeResponseErrorCode(traceId, errorCode); + onDecodeResponseErrorCode(traceId, originId, errorCode); } cleanupApplication(traceId, errorCode); @@ -3000,6 +3000,14 @@ private void onDecodeFetchPartition( } } + private void onDecodeResponseErrorCode( + long traceId, + long originId, + int errorCode) + { + super.onDecodeResponseErrorCode(traceId, originId, FETCH_API_KEY, FETCH_API_VERSION, errorCode); + } + private void onDecodeFetchTransactionAbort( long traceId, long authorization, diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java index a5999b3b25..dfb7a72bd3 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientGroupFactory.java @@ -878,7 +878,8 @@ private int decodeFindCoordinatorResponse( findCoordinatorResponse.host(), findCoordinatorResponse.port()); break; default: - client.onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, client.originId, FIND_COORDINATOR_API_KEY, + FIND_COORDINATOR_API_VERSION, errorCode); client.errorCode = errorCode; client.decoder = decodeClusterReject; break; @@ -1013,7 +1014,7 @@ private int decodeJoinGroupResponse( joinGroupResponse.memberId().asString()); break; default: - client.onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, client.originId, JOIN_GROUP_API_KEY, JOIN_GROUP_VERSION, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1073,7 +1074,7 @@ private int decodeSyncGroupResponse( client.onSyncGroupResponse(traceId, authorization, syncGroupResponse.assignment()); break; default: - client.onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, client.originId, SYNC_GROUP_API_KEY, SYNC_GROUP_VERSION, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1136,7 +1137,7 @@ private int decodeHeartbeatResponse( client.onHeartbeatResponse(traceId, authorization); break; default: - client.onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, client.originId, HEARTBEAT_API_KEY, HEARTBEAT_VERSION, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; break; @@ -1201,7 +1202,8 @@ private int decodeLeaveGroupResponse( } else { - client.onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, client.originId, LEAVE_GROUP_API_KEY, + LEAVE_GROUP_VERSION, errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } @@ -1216,7 +1218,8 @@ private int decodeLeaveGroupResponse( } else { - client.onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, client.originId, LEAVE_GROUP_API_KEY, LEAVE_GROUP_VERSION, + errorCode); client.errorCode = errorCode; client.decoder = decodeCoordinatorReject; } @@ -2571,12 +2574,20 @@ public void onDecodeResource( assert resource.equals(delegate.nodeId); break; default: - onDecodeResponseErrorCode(traceId, errorCode); + onDecodeResponseErrorCode(traceId, originId, errorCode); onNetworkError(traceId, errorCode); break; } } + private void onDecodeResponseErrorCode( + long traceId, + long originId, + int errorCode) + { + super.onDecodeResponseErrorCode(traceId, originId, DESCRIBE_CONFIGS_API_KEY, DESCRIBE_CONFIGS_API_VERSION, errorCode); + } + private void onNetwork( int msgTypeId, DirectBuffer buffer, diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java index 83624dd4a4..13c016633d 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientMetaFactory.java @@ -1810,7 +1810,7 @@ private void onDecodeTopic( newPartitions.clear(); break; default: - onDecodeResponseErrorCode(traceId, errorCode); + onDecodeResponseErrorCode(traceId, originId, errorCode); final KafkaResetExFW resetEx = kafkaResetExRW.wrap(extBuffer, 0, extBuffer.capacity()) .typeId(kafkaTypeId) .error(errorCode) @@ -1833,10 +1833,18 @@ private void onDecodePartition( } else { - onDecodeResponseErrorCode(traceId, partitionError); + onDecodeResponseErrorCode(traceId, originId, partitionError); } } + private void onDecodeResponseErrorCode( + long traceId, + long originId, + int errorCode) + { + super.onDecodeResponseErrorCode(traceId, originId, METADATA_API_KEY, METADATA_API_VERSION, errorCode); + } + @Override protected void onDecodeSaslResponse( long traceId) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java index 54eadfe84b..b7ca22b1f8 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetCommitFactory.java @@ -589,7 +589,8 @@ private int decodeOffsetCommitPartition( } else { - client.onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, client.originId, OFFSET_COMMIT_API_KEY, OFFSET_COMMIT_API_VERSION, + errorCode); client.errorCode = errorCode; client.decoder = decodeReject; } diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java index a99670ec69..4e753c0789 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientOffsetFetchFactory.java @@ -661,7 +661,8 @@ private int decodeOffsetFetchPartition( client.decoder = decodeOffsetFetchPartitions; break; default: - client.onDecodeResponseErrorCode(traceId, errorCode); + client.onDecodeResponseErrorCode(traceId, client.originId, OFFSET_FETCH_API_KEY, OFFSET_FETCH_API_VERSION, + errorCode); client.errorCode = errorCode; client.decoder = decodeReject; break; diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java index 2085423ade..9be9f026d2 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientProduceFactory.java @@ -2271,7 +2271,7 @@ private void onDecodeProducePartition( assert partitionId == this.partitionId; break; default: - onDecodeResponseErrorCode(traceId, errorCode); + onDecodeResponseErrorCode(traceId, originId, errorCode); final KafkaResetExFW resetEx = kafkaResetExRW.wrap(extBuffer, 0, extBuffer.capacity()) .typeId(kafkaTypeId) .error(errorCode) @@ -2282,6 +2282,14 @@ private void onDecodeProducePartition( } } + private void onDecodeResponseErrorCode( + long traceId, + long originId, + int errorCode) + { + super.onDecodeResponseErrorCode(traceId, originId, PRODUCE_API_KEY, PRODUCE_API_VERSION, errorCode); + } + @Override protected void onDecodeSaslResponse( long traceId) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index 2fb5657c74..eaefe4424c 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -429,11 +429,14 @@ private void doEncodeSaslScramFinalAuthenticateRequest( protected final void onDecodeResponseErrorCode( long traceId, + long bindingId, + int apiKey, + int apiVersion, int errorCode) { if (errorCode == ERROR_UNSUPPORTED_VERSION) { - event.apiVersionRejected(traceId); + event.apiVersionRejected(traceId, bindingId, apiKey, apiVersion); } } diff --git a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl index 855b9fd4ff..a9f3222680 100644 --- a/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl +++ b/specs/binding-kafka.spec/src/main/resources/META-INF/zilla/kafka.idl @@ -542,10 +542,16 @@ scope kafka API_VERSION_REJECTED (2) } + struct KafkaApiVersionRejected extends core::event::Event + { + int32 apiKey; + int32 apiVersion; + } + union KafkaEvent switch (KafkaEventType) { case AUTHORIZATION_FAILED: core::event::Event authorizationFailed; - case API_VERSION_REJECTED: core::event::Event apiVersionRejected; + case API_VERSION_REJECTED: KafkaApiVersionRejected apiVersionRejected; } } } From 9c54422c70e678fc912935ef15468120847411f5 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 09:37:11 +0100 Subject: [PATCH 145/167] fix tls --- .../tls/internal/stream/TlsClientFactory.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java index 441ce68949..b111b35b77 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/stream/TlsClientFactory.java @@ -627,27 +627,27 @@ private int decodeNotHandshaking( } catch (SSLProtocolException ex) { - event.tlsProtocolRejected(traceId, client.routedId); + event.tlsProtocolRejected(traceId, client.originId); throw ex; } catch (SSLKeyException ex) { - event.tlsKeyRejected(traceId, client.routedId); + event.tlsKeyRejected(traceId, client.originId); throw ex; } catch (SSLPeerUnverifiedException ex) { - event.tlsPeerNotVerified(traceId, client.routedId); + event.tlsPeerNotVerified(traceId, client.originId); throw ex; } catch (SSLHandshakeException ex) { - event.tlsHandshakeFailed(traceId, client.routedId); + event.tlsHandshakeFailed(traceId, client.originId); throw ex; } catch (SSLException ex) { - event.tlsFailed(traceId, client.routedId); + event.tlsFailed(traceId, client.originId); throw ex; } } @@ -822,27 +822,27 @@ private int decodeHandshakeNeedUnwrap( } catch (SSLProtocolException ex) { - event.tlsProtocolRejected(traceId, client.routedId); + event.tlsProtocolRejected(traceId, client.originId); throw ex; } catch (SSLKeyException ex) { - event.tlsKeyRejected(traceId, client.routedId); + event.tlsKeyRejected(traceId, client.originId); throw ex; } catch (SSLPeerUnverifiedException ex) { - event.tlsPeerNotVerified(traceId, client.routedId); + event.tlsPeerNotVerified(traceId, client.originId); throw ex; } catch (SSLHandshakeException ex) { - event.tlsHandshakeFailed(traceId, client.routedId); + event.tlsHandshakeFailed(traceId, client.originId); throw ex; } catch (SSLException ex) { - event.tlsFailed(traceId, client.routedId); + event.tlsFailed(traceId, client.originId); throw ex; } } @@ -1695,7 +1695,7 @@ private void onNetSignalHandshakeTimeout( final long traceId = signal.traceId(); cleanupNet(traceId); - event.tlsHandshakeFailed(traceId, client.routedId); + event.tlsHandshakeFailed(traceId, client.originId); decoder = decodeIgnoreAll; } } @@ -1718,27 +1718,27 @@ private void doNetBegin( } catch (SSLProtocolException ex) { - event.tlsProtocolRejected(traceId, client.routedId); + event.tlsProtocolRejected(traceId, client.originId); throw ex; } catch (SSLKeyException ex) { - event.tlsKeyRejected(traceId, client.routedId); + event.tlsKeyRejected(traceId, client.originId); throw ex; } catch (SSLPeerUnverifiedException ex) { - event.tlsPeerNotVerified(traceId, client.routedId); + event.tlsPeerNotVerified(traceId, client.originId); throw ex; } catch (SSLHandshakeException ex) { - event.tlsHandshakeFailed(traceId, client.routedId); + event.tlsHandshakeFailed(traceId, client.originId); throw ex; } catch (SSLException ex) { - event.tlsFailed(traceId, client.routedId); + event.tlsFailed(traceId, client.originId); throw ex; } } @@ -2128,27 +2128,27 @@ private void doEncodeWrap( } catch (SSLProtocolException ex) { - event.tlsProtocolRejected(traceId, client.routedId); + event.tlsProtocolRejected(traceId, client.originId); throw ex; } catch (SSLKeyException ex) { - event.tlsKeyRejected(traceId, client.routedId); + event.tlsKeyRejected(traceId, client.originId); throw ex; } catch (SSLPeerUnverifiedException ex) { - event.tlsPeerNotVerified(traceId, client.routedId); + event.tlsPeerNotVerified(traceId, client.originId); throw ex; } catch (SSLHandshakeException ex) { - event.tlsHandshakeFailed(traceId, client.routedId); + event.tlsHandshakeFailed(traceId, client.originId); throw ex; } catch (SSLException ex) { - event.tlsFailed(traceId, client.routedId); + event.tlsFailed(traceId, client.originId); throw ex; } } From 115405d7c3a88de2928af3db6b65afcaee0ea8f1 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 10:41:25 +0100 Subject: [PATCH 146/167] fix bindingId in *EventContext --- .../http/internal/HttpEventContext.java | 12 +++++------ .../kafka/internal/KafkaEventContext.java | 4 ++-- .../mqtt/internal/MqttEventContext.java | 4 ++-- .../binding/tcp/internal/TcpEventContext.java | 4 ++-- .../binding/tls/internal/TlsEventContext.java | 20 +++++++++---------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index 45616e2046..a27f759791 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -55,7 +55,7 @@ public HttpEventContext( public void authorizationFailed( long sessionId, long traceId, - long routedId, + long bindingId, GuardHandler guard, long authorization) { @@ -67,7 +67,7 @@ public void authorizationFailed( .authorizationFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) .identity(identity) ) .build(); @@ -77,7 +77,7 @@ public void authorizationFailed( public void requestAccepted( long traceId, - long routedId, + long bindingId, GuardHandler guard, long authorization, Map headers) @@ -88,7 +88,7 @@ public void requestAccepted( .requestAccepted(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) .identity(identity) .scheme(headers.get(":scheme")) .method(headers.get(":method")) @@ -101,7 +101,7 @@ public void requestAccepted( public void requestAccepted( long traceId, - long routedId, + long bindingId, GuardHandler guard, long authorization, Array32FW headers) @@ -112,7 +112,7 @@ public void requestAccepted( .requestAccepted(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) .identity(identity) .scheme(headers.matchFirst(h -> HEADER_SCHEME.equals(h.name())).value().asString()) .method(headers.matchFirst(h -> HEADER_METHOD.equals(h.name())).value().asString()) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 6c033b78c1..6e773042aa 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -47,7 +47,7 @@ public KafkaEventContext( public void authorizationFailed( int errorCode, long traceId, - long routedId) + long bindingId) { if (errorCode != ERROR_NONE) { @@ -56,7 +56,7 @@ public void authorizationFailed( .authorizationFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) ) .build(); eventWriter.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java index c875d3a187..1ad69bb3b8 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java @@ -47,7 +47,7 @@ public MqttEventContext( public void authorizationFailed( long sessionId, long traceId, - long routedId, + long bindingId, GuardHandler guard, long authorization) { @@ -59,7 +59,7 @@ public void authorizationFailed( .authorizationFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) .identity(identity) ) .build(); diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index 1ee5ea2870..ff9edf4e43 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -46,7 +46,7 @@ public TcpEventContext( public void dnsResolutionFailed( long traceId, - long routedId, + long bindingId, InetSocketAddress remoteAddress) { String address = remoteAddress == null ? "" : remoteAddress.getHostString(); @@ -55,7 +55,7 @@ public void dnsResolutionFailed( .dnsFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) .address(address) ) .build(); diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index ef4e8c430e..b742088b8b 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -45,14 +45,14 @@ public TlsEventContext( public void tlsFailed( long traceId, - long routedId) + long bindingId) { TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) ) .build(); eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); @@ -60,14 +60,14 @@ public void tlsFailed( public void tlsProtocolRejected( long traceId, - long routedId) + long bindingId) { TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsProtocolRejected(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) ) .build(); eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); @@ -75,14 +75,14 @@ public void tlsProtocolRejected( public void tlsKeyRejected( long traceId, - long routedId) + long bindingId) { TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsKeyRejected(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) ) .build(); eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); @@ -90,14 +90,14 @@ public void tlsKeyRejected( public void tlsPeerNotVerified( long traceId, - long routedId) + long bindingId) { TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsKeyRejected(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) ) .build(); eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); @@ -105,14 +105,14 @@ public void tlsPeerNotVerified( public void tlsHandshakeFailed( long traceId, - long routedId) + long bindingId) { TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .tlsKeyRejected(e -> e .timestamp(clock.millis()) .traceId(traceId) - .namespacedId(routedId) + .namespacedId(bindingId) ) .build(); eventWriter.accept(tlsTypeId, event.buffer(), event.offset(), event.limit()); From e1d6a9832f78b66bb3569cd189d06641b7f44298 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 10:47:15 +0100 Subject: [PATCH 147/167] fix idl --- .../registry/internal/SchemaRegistryEventContext.java | 1 + .../engine.spec/src/main/resources/META-INF/zilla/core.idl | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java index 63b97940ea..42770a31b1 100644 --- a/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java +++ b/incubator/catalog-schema-registry/src/main/java/io/aklivity/zilla/runtime/catalog/schema/registry/internal/SchemaRegistryEventContext.java @@ -52,6 +52,7 @@ public void remoteAccessRejected( .wrap(eventBuffer, 0, eventBuffer.capacity()) .remoteAccessRejected(e -> e .timestamp(clock.millis()) + .traceId(0L) .namespacedId(catalogId) .method(httpRequest.method()) .url(httpRequest.uri().toString()) diff --git a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl index 44699df113..05dfc800aa 100644 --- a/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl +++ b/specs/engine.spec/src/main/resources/META-INF/zilla/core.idl @@ -105,9 +105,9 @@ scope core { struct Event { - int64 timestamp = 0; - int64 traceId = 0; - int64 namespacedId = 0; + int64 timestamp; + int64 traceId; + int64 namespacedId; } } } From 4f3ecc00d1be90bcb08ef9a5eecfd8cb7474ad79 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 12:44:47 +0100 Subject: [PATCH 148/167] WIP jwt authFail --- incubator/exporter-stdout/pom.xml | 8 ++- .../internal/stream/StdoutEventsStream.java | 1 + .../internal/stream/StdoutJwtHandler.java | 54 ++++++++++++++++ runtime/guard-jwt/pom.xml | 19 ++++++ .../guard/jwt/internal/JwtEventContext.java | 61 +++++++++++++++++++ .../guard/jwt/internal/JwtGuardContext.java | 4 +- .../guard/jwt/internal/JwtGuardHandler.java | 13 +++- .../jwt/internal/JwtGuardHandlerTest.java | 54 ++++++++++------ specs/guard-jwt.spec/pom.xml | 20 ++++++ .../src/main/resources/META-INF/zilla/jwt.idl | 34 +++++++++++ 10 files changed, 245 insertions(+), 23 deletions(-) create mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutJwtHandler.java create mode 100644 runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtEventContext.java create mode 100644 specs/guard-jwt.spec/src/main/resources/META-INF/zilla/jwt.idl diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 6586d468d5..3e3889f574 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -79,6 +79,12 @@ ${project.version} provided + + ${project.groupId} + guard-jwt.spec + ${project.version} + provided + ${project.groupId} engine @@ -150,7 +156,7 @@ flyweight-maven-plugin ${project.version} - core http kafka mqtt schema_registry tcp tls + core http jwt kafka mqtt schema_registry tcp tls io.aklivity.zilla.runtime.exporter.stdout.internal.types diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index 81db687ec8..d37d471a4e 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -36,6 +36,7 @@ public StdoutEventsStream( final Int2ObjectHashMap eventHandlers = new Int2ObjectHashMap<>(); eventHandlers.put(context.supplyTypeId("http"), new StdoutHttpHandler(context, out)::handleEvent); + eventHandlers.put(context.supplyTypeId("jwt"), new StdoutJwtHandler(context, out)::handleEvent); eventHandlers.put(context.supplyTypeId("kafka"), new StdoutKafkaHandler(context, out)::handleEvent); eventHandlers.put(context.supplyTypeId("mqtt"), new StdoutMqttHandler(context, out)::handleEvent); eventHandlers.put(context.supplyTypeId("schema-registry"), diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutJwtHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutJwtHandler.java new file mode 100644 index 0000000000..7acf1ee0fe --- /dev/null +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutJwtHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; + +import java.io.PrintStream; + +import org.agrona.DirectBuffer; + +import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.JwtAuthorizationFailedFW; +import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.JwtEventFW; + +public class StdoutJwtHandler extends EventHandler +{ + private static final String AUTHORIZATION_FAILED_FORMAT = "%s %s [%s] AUTHORIZATION_FAILED%n"; + + private final JwtEventFW jwtEventRO = new JwtEventFW(); + + public StdoutJwtHandler( + StdoutExporterContext context, + PrintStream out) + { + super(context, out); + } + + public void handleEvent( + int msgTypeId, + DirectBuffer buffer, + int index, + int length) + { + JwtEventFW event = jwtEventRO.wrap(buffer, index, index + length); + switch (event.kind()) + { + case AUTHORIZATION_FAILED: + JwtAuthorizationFailedFW e = event.authorizationFailed(); + String qname = context.supplyQName(e.namespacedId()); + out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); + break; + } + } +} diff --git a/runtime/guard-jwt/pom.xml b/runtime/guard-jwt/pom.xml index 143b7c3182..fa3544628a 100644 --- a/runtime/guard-jwt/pom.xml +++ b/runtime/guard-jwt/pom.xml @@ -103,6 +103,22 @@ org.jasig.maven maven-notice-plugin + + ${project.groupId} + flyweight-maven-plugin + ${project.version} + + core jwt + io.aklivity.zilla.runtime.guard.jwt.internal.types + + + + + generate + + + + com.mycila license-maven-plugin @@ -185,6 +201,9 @@ org.jacoco jacoco-maven-plugin + + io/aklivity/zilla/runtime/guard/jwt/internal/types/**/*.class + BUNDLE diff --git a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtEventContext.java b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtEventContext.java new file mode 100644 index 0000000000..99d0fa6146 --- /dev/null +++ b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtEventContext.java @@ -0,0 +1,61 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.guard.jwt.internal; + +import java.nio.ByteBuffer; +import java.time.Clock; + +import org.agrona.MutableDirectBuffer; +import org.agrona.concurrent.UnsafeBuffer; + +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; +import io.aklivity.zilla.runtime.guard.jwt.internal.types.event.JwtEventFW; + +public class JwtEventContext +{ + private static final int EVENT_BUFFER_CAPACITY = 1024; + + private final JwtEventFW.Builder jwtEventRW = new JwtEventFW.Builder(); + private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); + private final int jwtTypeId; + private final MessageConsumer eventWriter; + private final Clock clock; + + public JwtEventContext( + EngineContext context) + { + this.jwtTypeId = context.supplyTypeId(JwtGuard.NAME); + this.eventWriter = context.supplyEventWriter(); + this.clock = context.clock(); + } + + public void authorizationFailed( + long traceId, + long bindingId, + String identity) + { + JwtEventFW event = jwtEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorizationFailed(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(bindingId) + .identity(identity) + ) + .build(); + eventWriter.accept(jwtTypeId, event.buffer(), event.offset(), event.limit()); + } +} diff --git a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardContext.java b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardContext.java index 1412213c25..55c141be78 100644 --- a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardContext.java +++ b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardContext.java @@ -28,12 +28,14 @@ final class JwtGuardContext implements GuardContext { private final Long2ObjectHashMap handlersById; private final LongSupplier supplyAuthorizedId; + private final EngineContext context; JwtGuardContext( Configuration config, EngineContext context) { this.handlersById = new Long2ObjectHashMap<>(); + this.context = context; this.supplyAuthorizedId = context::supplyAuthorizedId; } @@ -42,7 +44,7 @@ public JwtGuardHandler attach( GuardConfig guard) { JwtOptionsConfig options = (JwtOptionsConfig) guard.options; - JwtGuardHandler handler = new JwtGuardHandler(options, supplyAuthorizedId, guard.readURL); + JwtGuardHandler handler = new JwtGuardHandler(options, context, supplyAuthorizedId, guard.readURL); handlersById.put(guard.id, handler); return handler; } diff --git a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java index 54f2358905..82715660b0 100644 --- a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java +++ b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java @@ -42,6 +42,7 @@ import org.jose4j.jwt.consumer.InvalidJwtException; import org.jose4j.lang.JoseException; +import io.aklivity.zilla.runtime.engine.EngineContext; import io.aklivity.zilla.runtime.engine.guard.GuardHandler; import io.aklivity.zilla.runtime.guard.jwt.config.JwtKeyConfig; import io.aklivity.zilla.runtime.guard.jwt.config.JwtKeySetConfig; @@ -59,9 +60,11 @@ public class JwtGuardHandler implements GuardHandler private final Long2ObjectHashMap sessionsById; private final LongSupplier supplyAuthorizedId; private final Long2ObjectHashMap sessionStoresByContextId; + private final JwtEventContext event; public JwtGuardHandler( JwtOptionsConfig options, + EngineContext context, LongSupplier supplyAuthorizedId, Function readURL) { @@ -113,6 +116,7 @@ public JwtGuardHandler( this.supplyAuthorizedId = supplyAuthorizedId; this.sessionsById = new Long2ObjectHashMap<>(); this.sessionStoresByContextId = new Long2ObjectHashMap<>(); + this.event = new JwtEventContext(context); } @Override @@ -121,6 +125,7 @@ public long reauthorize( String credentials) { JwtSession session = null; + String subject = null; authorize: try @@ -161,7 +166,7 @@ public long reauthorize( break authorize; } - String subject = claims.getSubject(); + subject = claims.getSubject(); List roles = Optional.ofNullable(claims.getClaimValue("scope")) .map(s -> s.toString().intern()) .map(s -> s.split("\\s+")) @@ -185,7 +190,11 @@ public long reauthorize( { // not authorized } - + if (session == null) + { + // TODO: Ati - traceId, bindingId + event.authorizationFailed(0L, 0L, subject); + } return session != null ? session.authorized : NOT_AUTHORIZED; } diff --git a/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandlerTest.java b/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandlerTest.java index 88649c6a63..81dd7647db 100644 --- a/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandlerTest.java +++ b/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandlerTest.java @@ -24,8 +24,11 @@ import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.security.KeyPair; +import java.time.Clock; import java.time.Duration; import java.time.Instant; import java.util.function.Function; @@ -34,14 +37,27 @@ import org.jose4j.jws.JsonWebSignature; import org.jose4j.jwt.JwtClaims; import org.jose4j.lang.JoseException; +import org.junit.Before; import org.junit.Test; +import io.aklivity.zilla.runtime.engine.EngineContext; +import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; import io.aklivity.zilla.runtime.guard.jwt.config.JwtOptionsConfig; public class JwtGuardHandlerTest { private static final Function READ_KEYS_URL = url -> "{}"; + private EngineContext context; + + @Before + public void init() + { + context = mock(EngineContext.class); + when(context.clock()).thenReturn(mock(Clock.class)); + when(context.supplyEventWriter()).thenReturn(mock(MessageConsumer.class)); + } + @Test public void shouldAuthorize() throws Exception { @@ -53,7 +69,7 @@ public void shouldAuthorize() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -86,7 +102,7 @@ public void shouldChallengeDuringChallengeWindow() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -115,7 +131,7 @@ public void shouldNotChallengeDuringWindowWithoutSubject() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -143,7 +159,7 @@ public void shouldNotChallengeBeforeChallengeWindow() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -172,7 +188,7 @@ public void shouldNotChallengeAgainDuringChallengeWindow() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -201,7 +217,7 @@ public void shouldNotAuthorizeWhenAlgorithmDiffers() throws Exception .audience("testAudience") .key(RFC7515_RS256_CONFIG) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); JwtClaims claims = new JwtClaims(); claims.setClaim("iss", "test issuer"); @@ -223,7 +239,7 @@ public void shouldNotAuthorizeWhenSignatureInvalid() throws Exception .audience("testAudience") .key(RFC7515_RS256_CONFIG) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); JwtClaims claims = new JwtClaims(); claims.setClaim("iss", "test issuer"); @@ -247,7 +263,7 @@ public void shouldNotAuthorizeWhenIssuerDiffers() throws Exception .audience("testAudience") .key(RFC7515_RS256_CONFIG) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); JwtClaims claims = new JwtClaims(); claims.setClaim("iss", "not test issuer"); @@ -269,7 +285,7 @@ public void shouldNotAuthorizeWhenAudienceDiffers() throws Exception .audience("testAudience") .key(RFC7515_RS256_CONFIG) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); JwtClaims claims = new JwtClaims(); claims.setClaim("iss", "test issuer"); @@ -291,7 +307,7 @@ public void shouldNotAuthorizeWhenExpired() throws Exception .audience("testAudience") .key(RFC7515_RS256_CONFIG) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -316,7 +332,7 @@ public void shouldNotAuthorizeWhenNotYetValid() throws Exception .audience("testAudience") .key(RFC7515_RS256_CONFIG) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -343,7 +359,7 @@ public void shouldNotVerifyAuthorizedWhenRolesInsufficient() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); JwtClaims claims = new JwtClaims(); claims.setClaim("iss", "test issuer"); @@ -369,7 +385,7 @@ public void shouldReauthorizeWhenExpirationLater() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -404,7 +420,7 @@ public void shouldReauthorizeWhenScopeBroader() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -440,7 +456,7 @@ public void shouldNotReauthorizeWhenExpirationEarlier() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -475,7 +491,7 @@ public void shouldNotReauthorizeWhenScopeNarrower() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -512,7 +528,7 @@ public void shouldNotReauthorizeWhenSubjectDiffers() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -549,7 +565,7 @@ public void shouldNotReauthorizeWhenContextDiffers() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); @@ -585,7 +601,7 @@ public void shouldDeauthorize() throws Exception .key(RFC7515_RS256_CONFIG) .challenge(challenge) .build(); - JwtGuardHandler guard = new JwtGuardHandler(options, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); + JwtGuardHandler guard = new JwtGuardHandler(options, context, new MutableLong(1L)::getAndIncrement, READ_KEYS_URL); Instant now = Instant.now(); diff --git a/specs/guard-jwt.spec/pom.xml b/specs/guard-jwt.spec/pom.xml index ebe02ac328..ab5d123aed 100644 --- a/specs/guard-jwt.spec/pom.xml +++ b/specs/guard-jwt.spec/pom.xml @@ -63,6 +63,23 @@ org.jasig.maven maven-notice-plugin + + ${project.groupId} + flyweight-maven-plugin + ${project.version} + + core jwt + io.aklivity.zilla.specs.guard.jwt.internal.types + + + + + validate + generate + + + + com.mycila license-maven-plugin @@ -86,6 +103,9 @@ org.jacoco jacoco-maven-plugin + + io/aklivity/zilla/specs/guard/jwt/internal/types/**/*.class + BUNDLE diff --git a/specs/guard-jwt.spec/src/main/resources/META-INF/zilla/jwt.idl b/specs/guard-jwt.spec/src/main/resources/META-INF/zilla/jwt.idl new file mode 100644 index 0000000000..997f9bf859 --- /dev/null +++ b/specs/guard-jwt.spec/src/main/resources/META-INF/zilla/jwt.idl @@ -0,0 +1,34 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +scope jwt +{ + scope event + { + enum JwtEventType (uint8) + { + AUTHORIZATION_FAILED (1) + } + + struct JwtAuthorizationFailed extends core::event::Event + { + string8 identity; + } + + union JwtEvent switch (JwtEventType) + { + case AUTHORIZATION_FAILED: JwtAuthorizationFailed authorizationFailed; + } + } +} From e01ae34ab445454ac1b1e0080c5bb25688863b8b Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 12:55:51 +0100 Subject: [PATCH 149/167] WIP jwt traceId, bindingId --- .../internal/stream/HttpServerFactory.java | 10 ++-- .../internal/stream/MqttServerFactory.java | 2 +- .../runtime/engine/guard/GuardHandler.java | 2 + .../test/internal/guard/TestGuardHandler.java | 2 + .../guard/jwt/internal/JwtGuardHandler.java | 5 +- .../jwt/internal/JwtGuardHandlerTest.java | 50 +++++++++---------- .../guard/jwt/internal/JwtGuardTest.java | 14 +++--- 7 files changed, 45 insertions(+), 40 deletions(-) diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 987a44b51f..6d34ab71a4 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1046,7 +1046,7 @@ else if (!isCorsRequestAllowed(server.binding, headers)) final String credentialsMatch = server.credentials.apply(headers::get); if (credentialsMatch != null) { - guard.reauthorize(server.initialId, credentialsMatch); + guard.reauthorize(traceId, server.routedId, server.initialId, credentialsMatch); } server.doEncodeHeaders(traceId, authorization, budgetId, headers204); } @@ -1058,7 +1058,7 @@ else if (!isCorsRequestAllowed(server.binding, headers)) final String credentialsMatch = server.credentials.apply(headers::get); if (credentialsMatch != null) { - exchangeAuth = guard.reauthorize(server.initialId, credentialsMatch); + exchangeAuth = guard.reauthorize(traceId, server.routedId, server.initialId, credentialsMatch); event.authorizationFailed(exchangeAuth, traceId, server.routedId, guard, authorization); } } @@ -4961,7 +4961,7 @@ else if (!isCorsRequestAllowed(binding, headers)) final String credentialsMatch = credentials.apply(headers::get); if (credentialsMatch != null) { - guard.reauthorize(initialId, credentialsMatch); + guard.reauthorize(traceId, routedId, initialId, credentialsMatch); } doEncodeHeaders(traceId, authorization, streamId, headers204, true); } @@ -4973,7 +4973,7 @@ else if (!isCorsRequestAllowed(binding, headers)) final String credentialsMatch = credentials.apply(headers::get); if (credentialsMatch != null) { - exchangeAuth = guard.reauthorize(initialId, credentialsMatch); + exchangeAuth = guard.reauthorize(traceId, routedId, initialId, credentialsMatch); event.authorizationFailed(exchangeAuth, traceId, routedId, guard, authorization); } } @@ -5348,7 +5348,7 @@ private void doEncodePromise( final String credentialsMatch = credentials.apply(headers::get); if (credentialsMatch != null) { - exchangeAuth = guard.reauthorize(initialId, credentialsMatch); + exchangeAuth = guard.reauthorize(traceId, routedId, initialId, credentialsMatch); } } diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index 220d31e265..c7968101a0 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -2913,7 +2913,7 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) if (credentialsMatch != null) { - sessionAuth = guard.reauthorize(initialId, credentialsMatch); + sessionAuth = guard.reauthorize(traceId, routedId, initialId, credentialsMatch); event.authorizationFailed(sessionAuth, traceId, routedId, guard, sessionId); } } diff --git a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/guard/GuardHandler.java b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/guard/GuardHandler.java index 54c3f372fc..a9da2772fe 100644 --- a/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/guard/GuardHandler.java +++ b/runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/guard/GuardHandler.java @@ -30,6 +30,8 @@ public interface GuardHandler * @return the session identifier */ long reauthorize( + long traceId, + long bindingId, long contextId, String credentials); diff --git a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/test/internal/guard/TestGuardHandler.java b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/test/internal/guard/TestGuardHandler.java index 1e872dfcdd..ccc663209e 100644 --- a/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/test/internal/guard/TestGuardHandler.java +++ b/runtime/engine/src/test/java/io/aklivity/zilla/runtime/engine/test/internal/guard/TestGuardHandler.java @@ -50,6 +50,8 @@ public TestGuardHandler( @Override public long reauthorize( + long traceId, + long bindingId, long contextId, String credentials) { diff --git a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java index 82715660b0..3d5cede109 100644 --- a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java +++ b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java @@ -121,6 +121,8 @@ public JwtGuardHandler( @Override public long reauthorize( + long traceId, + long bindingId, long contextId, String credentials) { @@ -192,8 +194,7 @@ public long reauthorize( } if (session == null) { - // TODO: Ati - traceId, bindingId - event.authorizationFailed(0L, 0L, subject); + event.authorizationFailed(traceId, bindingId, subject); } return session != null ? session.authorized : NOT_AUTHORIZED; } diff --git a/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandlerTest.java b/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandlerTest.java index 81dd7647db..90bd4add79 100644 --- a/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandlerTest.java +++ b/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandlerTest.java @@ -82,7 +82,7 @@ public void shouldAuthorize() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertThat(sessionId, not(equalTo(0L))); assertThat(guard.identity(sessionId), equalTo("testSubject")); @@ -115,7 +115,7 @@ public void shouldChallengeDuringChallengeWindow() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertTrue(guard.challenge(sessionId, now.plusSeconds(8L).toEpochMilli())); } @@ -143,7 +143,7 @@ public void shouldNotChallengeDuringWindowWithoutSubject() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertFalse(guard.challenge(sessionId, now.plusSeconds(8L).toEpochMilli())); } @@ -172,7 +172,7 @@ public void shouldNotChallengeBeforeChallengeWindow() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertFalse(guard.challenge(sessionId, now.plusSeconds(5L).toEpochMilli())); } @@ -201,7 +201,7 @@ public void shouldNotChallengeAgainDuringChallengeWindow() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertTrue(guard.challenge(sessionId, now.plusSeconds(8L).toEpochMilli())); assertFalse(guard.challenge(sessionId, now.plusSeconds(8L).toEpochMilli())); @@ -225,7 +225,7 @@ public void shouldNotAuthorizeWhenAlgorithmDiffers() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS512"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertThat(sessionId, equalTo(0L)); } @@ -249,7 +249,7 @@ public void shouldNotAuthorizeWhenSignatureInvalid() throws Exception .replaceFirst("\\.[^X]", ".X") .replaceFirst("\\.[^Y]", ".Y"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertThat(sessionId, equalTo(0L)); } @@ -271,7 +271,7 @@ public void shouldNotAuthorizeWhenIssuerDiffers() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertThat(sessionId, equalTo(0L)); } @@ -293,7 +293,7 @@ public void shouldNotAuthorizeWhenAudienceDiffers() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertThat(sessionId, equalTo(0L)); } @@ -318,7 +318,7 @@ public void shouldNotAuthorizeWhenExpired() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertThat(sessionId, equalTo(0L)); } @@ -343,7 +343,7 @@ public void shouldNotAuthorizeWhenNotYetValid() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertThat(sessionId, equalTo(0L)); } @@ -368,7 +368,7 @@ public void shouldNotVerifyAuthorizedWhenRolesInsufficient() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); assertThat(sessionId, not(equalTo(0L))); assertFalse(guard.verify(sessionId, asList("read:stream", "write:stream"))); @@ -398,12 +398,12 @@ public void shouldReauthorizeWhenExpirationLater() throws Exception String tokenPlus10 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus10 = guard.reauthorize(101L, tokenPlus10); + long sessionIdPlus10 = guard.reauthorize(0L, 0L, 101L, tokenPlus10); claims.setClaim("exp", now.getEpochSecond() + 60L); String tokenPlus60 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus60 = guard.reauthorize(101L, tokenPlus60); + long sessionIdPlus60 = guard.reauthorize(0L, 0L, 101L, tokenPlus60); assertThat(sessionIdPlus60, equalTo(sessionIdPlus10)); assertThat(guard.expiresAt(sessionIdPlus10), equalTo(ofSeconds(now.getEpochSecond() + 60L).toMillis())); @@ -433,13 +433,13 @@ public void shouldReauthorizeWhenScopeBroader() throws Exception String tokenPlus10 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus10 = guard.reauthorize(101L, tokenPlus10); + long sessionIdPlus10 = guard.reauthorize(0L, 0L, 101L, tokenPlus10); claims.setClaim("exp", now.getEpochSecond() + 60L); claims.setClaim("scope", "read:stream write:stream"); String tokenPlus60 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus60 = guard.reauthorize(101L, tokenPlus60); + long sessionIdPlus60 = guard.reauthorize(0L, 0L, 101L, tokenPlus60); assertThat(sessionIdPlus60, equalTo(sessionIdPlus10)); assertThat(guard.expiresAt(sessionIdPlus10), equalTo(ofSeconds(now.getEpochSecond() + 60L).toMillis())); @@ -469,12 +469,12 @@ public void shouldNotReauthorizeWhenExpirationEarlier() throws Exception String tokenPlus10 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus10 = guard.reauthorize(101L, tokenPlus10); + long sessionIdPlus10 = guard.reauthorize(0L, 0L, 101L, tokenPlus10); claims.setClaim("exp", now.getEpochSecond() + 5L); String tokenPlus5 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus5 = guard.reauthorize(101L, tokenPlus5); + long sessionIdPlus5 = guard.reauthorize(0L, 0L, 101L, tokenPlus5); assertThat(sessionIdPlus5, equalTo(sessionIdPlus10)); assertThat(guard.expiresAt(sessionIdPlus10), equalTo(ofSeconds(now.getEpochSecond() + 10L).toMillis())); @@ -504,13 +504,13 @@ public void shouldNotReauthorizeWhenScopeNarrower() throws Exception String tokenPlus10 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus10 = guard.reauthorize(101L, tokenPlus10); + long sessionIdPlus10 = guard.reauthorize(0L, 0L, 101L, tokenPlus10); claims.setClaim("exp", now.getEpochSecond() + 60L); claims.setClaim("scope", "read:stream"); String tokenPlus60 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus60 = guard.reauthorize(101L, tokenPlus60); + long sessionIdPlus60 = guard.reauthorize(0L, 0L, 101L, tokenPlus60); assertThat(sessionIdPlus60, not(equalTo(sessionIdPlus10))); assertThat(guard.expiresAt(sessionIdPlus10), equalTo(ofSeconds(now.getEpochSecond() + 10L).toMillis())); @@ -541,13 +541,13 @@ public void shouldNotReauthorizeWhenSubjectDiffers() throws Exception String tokenPlus10 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus10 = guard.reauthorize(101L, tokenPlus10); + long sessionIdPlus10 = guard.reauthorize(0L, 0L, 101L, tokenPlus10); claims.setClaim("sub", "otherSubject"); claims.setClaim("exp", now.getEpochSecond() + 60L); String tokenPlus60 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus60 = guard.reauthorize(101L, tokenPlus60); + long sessionIdPlus60 = guard.reauthorize(0L, 0L, 101L, tokenPlus60); assertThat(sessionIdPlus60, not(equalTo(sessionIdPlus10))); assertThat(guard.expiresAt(sessionIdPlus10), equalTo(ofSeconds(now.getEpochSecond() + 10L).toMillis())); @@ -578,12 +578,12 @@ public void shouldNotReauthorizeWhenContextDiffers() throws Exception String tokenPlus10 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus10 = guard.reauthorize(101L, tokenPlus10); + long sessionIdPlus10 = guard.reauthorize(0L, 0L, 101L, tokenPlus10); claims.setClaim("exp", now.getEpochSecond() + 60L); String tokenPlus60 = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionIdPlus60 = guard.reauthorize(202L, tokenPlus60); + long sessionIdPlus60 = guard.reauthorize(0L, 0L, 202L, tokenPlus60); assertThat(sessionIdPlus60, not(equalTo(sessionIdPlus10))); assertThat(guard.expiresAt(sessionIdPlus10), equalTo(ofSeconds(now.getEpochSecond() + 10L).toMillis())); @@ -614,7 +614,7 @@ public void shouldDeauthorize() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = guard.reauthorize(101L, token); + long sessionId = guard.reauthorize(0L, 0L, 101L, token); guard.deauthorize(sessionId); } diff --git a/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardTest.java b/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardTest.java index 9d54435ab1..1f41b642a8 100644 --- a/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardTest.java +++ b/runtime/guard-jwt/src/test/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardTest.java @@ -167,7 +167,7 @@ public void shouldNotVerifyRolesWhenInsufficient() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long authorizedId = handler.reauthorize(101L, token); + long authorizedId = handler.reauthorize(0L, 0L, 101L, token); assertFalse(verifier.test(authorizedId)); } @@ -220,7 +220,7 @@ public void shouldVerifyRolesWhenExact() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = handler.reauthorize(101L, token); + long sessionId = handler.reauthorize(0L, 0L, 101L, token); assertTrue(verifier.test(sessionId)); } @@ -272,7 +272,7 @@ public void shouldVerifyRolesWhenSuperset() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = handler.reauthorize(101L, token); + long sessionId = handler.reauthorize(0L, 0L, 101L, token); assertTrue(verifier.test(sessionId)); } @@ -323,7 +323,7 @@ public void shouldVerifyRolesWhenEmpty() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = handler.reauthorize(101L, token); + long sessionId = handler.reauthorize(0L, 0L, 101L, token); assertTrue(verifier.test(sessionId)); } @@ -374,7 +374,7 @@ public void shouldVerifyWhenIndexDiffers() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = handler.reauthorize(101L, token); + long sessionId = handler.reauthorize(0L, 0L, 101L, token); assertTrue(verifier.test(sessionId)); } @@ -425,7 +425,7 @@ public void shouldIdentify() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = handler.reauthorize(101L, token); + long sessionId = handler.reauthorize(0L, 0L, 101L, token); assertEquals("testSubject", identifier.apply(sessionId)); } @@ -478,7 +478,7 @@ public void shouldIdentifyWhenIndexDiffers() throws Exception String token = sign(claims.toJson(), "test", RFC7515_RS256, "RS256"); - long sessionId = handler.reauthorize(101L, token); + long sessionId = handler.reauthorize(0L, 0L, 101L, token); assertEquals("testSubject", identifier.apply(sessionId)); } From 15937c6394c5d128bbf5ef96b9870e63906e8d31 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 13:17:57 +0100 Subject: [PATCH 150/167] WIP rm mqtt --- incubator/exporter-stdout/pom.xml | 8 +-- .../internal/stream/StdoutEventsStream.java | 1 - .../internal/stream/StdoutMqttHandler.java | 54 --------------- .../mqtt/internal/MqttEventContext.java | 69 ------------------- .../internal/stream/MqttServerFactory.java | 4 -- .../main/resources/META-INF/zilla/mqtt.idl | 19 ----- 6 files changed, 1 insertion(+), 154 deletions(-) delete mode 100644 incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java delete mode 100644 runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 3e3889f574..47e588bb61 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -55,12 +55,6 @@ ${project.version} provided - - ${project.groupId} - binding-mqtt.spec - ${project.version} - provided - ${project.groupId} binding-tcp.spec @@ -156,7 +150,7 @@ flyweight-maven-plugin ${project.version} - core http jwt kafka mqtt schema_registry tcp tls + core http jwt kafka schema_registry tcp tls io.aklivity.zilla.runtime.exporter.stdout.internal.types diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java index d37d471a4e..c6e330f377 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutEventsStream.java @@ -38,7 +38,6 @@ public StdoutEventsStream( eventHandlers.put(context.supplyTypeId("http"), new StdoutHttpHandler(context, out)::handleEvent); eventHandlers.put(context.supplyTypeId("jwt"), new StdoutJwtHandler(context, out)::handleEvent); eventHandlers.put(context.supplyTypeId("kafka"), new StdoutKafkaHandler(context, out)::handleEvent); - eventHandlers.put(context.supplyTypeId("mqtt"), new StdoutMqttHandler(context, out)::handleEvent); eventHandlers.put(context.supplyTypeId("schema-registry"), new StdoutSchemaRegistryHandler(context, out)::handleEvent); eventHandlers.put(context.supplyTypeId("tcp"), new StdoutTcpHandler(context, out)::handleEvent); diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java deleted file mode 100644 index eeb19ee4f5..0000000000 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutMqttHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc - * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at - * - * https://www.aklivity.io/aklivity-community-license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package io.aklivity.zilla.runtime.exporter.stdout.internal.stream; - -import java.io.PrintStream; - -import org.agrona.DirectBuffer; - -import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttAuthorizationFailedFW; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.MqttEventFW; - -public class StdoutMqttHandler extends EventHandler -{ - private static final String AUTHORIZATION_FAILED_FORMAT = "%s %s [%s] AUTHORIZATION_FAILED%n"; - - private final MqttEventFW mqttEventRO = new MqttEventFW(); - - public StdoutMqttHandler( - StdoutExporterContext context, - PrintStream out) - { - super(context, out); - } - - public void handleEvent( - int msgTypeId, - DirectBuffer buffer, - int index, - int length) - { - MqttEventFW event = mqttEventRO.wrap(buffer, index, index + length); - switch (event.kind()) - { - case AUTHORIZATION_FAILED: - MqttAuthorizationFailedFW e = event.authorizationFailed(); - String qname = context.supplyQName(e.namespacedId()); - out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); - break; - } - } -} diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java deleted file mode 100644 index 1ad69bb3b8..0000000000 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/MqttEventContext.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc. - * - * Aklivity licenses this file to you 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.aklivity.zilla.runtime.binding.mqtt.internal; - -import java.nio.ByteBuffer; -import java.time.Clock; - -import org.agrona.MutableDirectBuffer; -import org.agrona.concurrent.UnsafeBuffer; - -import io.aklivity.zilla.runtime.binding.mqtt.internal.types.event.MqttEventFW; -import io.aklivity.zilla.runtime.engine.EngineContext; -import io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer; -import io.aklivity.zilla.runtime.engine.guard.GuardHandler; - -public class MqttEventContext -{ - private static final int EVENT_BUFFER_CAPACITY = 1024; - - private final MqttEventFW.Builder mqttEventRW = new MqttEventFW.Builder(); - private final MutableDirectBuffer eventBuffer = new UnsafeBuffer(ByteBuffer.allocate(EVENT_BUFFER_CAPACITY)); - private final int mqttTypeId; - private final MessageConsumer eventWriter; - private final Clock clock; - - public MqttEventContext( - EngineContext context) - { - this.mqttTypeId = context.supplyTypeId(MqttBinding.NAME); - this.eventWriter = context.supplyEventWriter(); - this.clock = context.clock(); - } - - public void authorizationFailed( - long sessionId, - long traceId, - long bindingId, - GuardHandler guard, - long authorization) - { - if (sessionId == 0) - { - String identity = guard == null ? null : guard.identity(authorization); - MqttEventFW event = mqttEventRW - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorizationFailed(e -> e - .timestamp(clock.millis()) - .traceId(traceId) - .namespacedId(bindingId) - .identity(identity) - ) - .build(); - eventWriter.accept(mqttTypeId, event.buffer(), event.offset(), event.limit()); - } - } -} diff --git a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java index c7968101a0..7d8e6a7f5b 100644 --- a/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java +++ b/runtime/binding-mqtt/src/main/java/io/aklivity/zilla/runtime/binding/mqtt/internal/stream/MqttServerFactory.java @@ -111,7 +111,6 @@ import io.aklivity.zilla.runtime.binding.mqtt.config.MqttPatternConfig.MqttConnectProperty; import io.aklivity.zilla.runtime.binding.mqtt.internal.MqttBinding; import io.aklivity.zilla.runtime.binding.mqtt.internal.MqttConfiguration; -import io.aklivity.zilla.runtime.binding.mqtt.internal.MqttEventContext; import io.aklivity.zilla.runtime.binding.mqtt.internal.MqttValidator; import io.aklivity.zilla.runtime.binding.mqtt.internal.config.MqttBindingConfig; import io.aklivity.zilla.runtime.binding.mqtt.internal.config.MqttRouteConfig; @@ -407,7 +406,6 @@ public final class MqttServerFactory implements MqttStreamFactory private final Map decodersByPacketTypeV5; private final IntSupplier supplySubscriptionId; private final EngineContext context; - private final MqttEventContext event; private int maximumPacketSize = Integer.MAX_VALUE; @@ -527,7 +525,6 @@ public MqttServerFactory( this.decodePacketTypeByVersion.put(MQTT_PROTOCOL_VERSION_4, this::decodePacketTypeV4); this.decodePacketTypeByVersion.put(MQTT_PROTOCOL_VERSION_5, this::decodePacketTypeV5); this.supplyValidator = context::supplyValidator; - this.event = new MqttEventContext(context); } @Override @@ -2914,7 +2911,6 @@ else if (this.authField.equals(MqttConnectProperty.PASSWORD)) if (credentialsMatch != null) { sessionAuth = guard.reauthorize(traceId, routedId, initialId, credentialsMatch); - event.authorizationFailed(sessionAuth, traceId, routedId, guard, sessionId); } } diff --git a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl index 00283beda6..9431a6b159 100644 --- a/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl +++ b/specs/binding-mqtt.spec/src/main/resources/META-INF/zilla/mqtt.idl @@ -260,24 +260,5 @@ scope mqtt COMPLETE(0), INCOMPLETE(1) } - - } - - scope event - { - enum MqttEventType (uint8) - { - AUTHORIZATION_FAILED (1) - } - - struct MqttAuthorizationFailed extends core::event::Event - { - string8 identity; - } - - union MqttEvent switch (MqttEventType) - { - case AUTHORIZATION_FAILED: MqttAuthorizationFailed authorizationFailed; - } } } From 259e5fba9f4d20e5861c89b7f457c0ae294c052a Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 13:27:52 +0100 Subject: [PATCH 151/167] WIP fix Http11EventsIT --- ...orization.credentials.yaml => server.yaml} | 21 +++---------------- .../internal/events/Http11EventsIT.java | 18 ++++++++-------- 2 files changed, 12 insertions(+), 27 deletions(-) rename incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/{my_server.authorization.credentials.yaml => server.yaml} (60%) diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/my_server.authorization.credentials.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.yaml similarity index 60% rename from incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/my_server.authorization.credentials.yaml rename to incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.yaml index 29be8c74a1..7202d45307 100644 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/my_server.authorization.credentials.yaml +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.yaml @@ -19,13 +19,6 @@ telemetry: exporters: stdout0: type: stdout -guards: - test0: - type: test - options: - credentials: TOKEN - lifetime: PT5S - challenge: PT5S bindings: net0: type: http @@ -33,16 +26,8 @@ bindings: options: versions: - http/1.1 - authorization: - test0: - credentials: - cookies: - access_token: "{credentials}" - headers: - authorization: Bearer {credentials} - query: - access_token: "{credentials}" routes: - exit: app0 - guarded: - test0: [] + when: + - headers: + :authority: localhost:8080 diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java index af4b79c4f8..c942d6e141 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http11EventsIT.java @@ -14,7 +14,7 @@ */ package io.aklivity.zilla.runtime.exporter.stdout.internal.events; -import static io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration.HTTP_SERVER_HEADER; +import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_BUFFER_SLOT_CAPACITY; import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.rules.RuleChain.outerRule; @@ -35,15 +35,15 @@ public class Http11EventsIT { private final K3poRule k3po = new K3poRule() - .addScriptRoot("net", "io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization") - .addScriptRoot("app", "io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/authorization"); + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/message.format") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/message.format"); private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); private final EngineRule engine = new EngineRule() .directory("target/zilla-itests") .countersBufferCapacity(8192) - .configure(HTTP_SERVER_HEADER, "Zilla") + .configure(ENGINE_BUFFER_SLOT_CAPACITY, 8192) .configurationRoot("io/aklivity/zilla/specs/binding/http/config/v1.1") .external("app0") .clean(); @@ -54,15 +54,15 @@ public class Http11EventsIT public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); @Test - @Configuration("my_server.authorization.credentials.yaml") + @Configuration("server.yaml") @Specification({ - "${net}/reject.credentials.header/client", - }) + "${net}/request.with.headers/client", + "${app}/request.with.headers/server" }) @Configure(name = "zilla.exporter.stdout.output", value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") - public void shouldRejectCredentialsHeader() throws Exception + public void requestWithHeaders() throws Exception { k3po.finish(); - output.expect(Pattern.compile("test.net0 test \\[[^\\]]+\\] AUTHORIZATION_FAILED\n")); + output.expect(Pattern.compile("test.app0 - \\[[^\\]]+\\] REQUEST_ACCEPTED http GET localhost:8080 /\n")); } } From 3ca772b1b43dc505a6ac309271ba90f6043409aa Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 13:37:36 +0100 Subject: [PATCH 152/167] WIP fix rm http authFail --- .../internal/stream/StdoutHttpHandler.java | 9 -------- .../http/internal/HttpEventContext.java | 23 ------------------- .../internal/stream/HttpServerFactory.java | 2 -- .../main/resources/META-INF/zilla/http.idl | 9 +------- 4 files changed, 1 insertion(+), 42 deletions(-) diff --git a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java index 1a04f254f7..86dabe799b 100644 --- a/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java +++ b/incubator/exporter-stdout/src/main/java/io/aklivity/zilla/runtime/exporter/stdout/internal/stream/StdoutHttpHandler.java @@ -19,13 +19,11 @@ import org.agrona.DirectBuffer; import io.aklivity.zilla.runtime.exporter.stdout.internal.StdoutExporterContext; -import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpAuthorizationFailedFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpEventFW; import io.aklivity.zilla.runtime.exporter.stdout.internal.types.event.HttpRequestAcceptedFW; public class StdoutHttpHandler extends EventHandler { - private static final String AUTHORIZATION_FAILED_FORMAT = "%s %s [%s] AUTHORIZATION_FAILED%n"; private static final String REQUEST_ACCEPTED_FORMAT = "%s %s [%s] REQUEST_ACCEPTED %s %s %s %s%n"; private final HttpEventFW httpEventRO = new HttpEventFW(); @@ -46,13 +44,6 @@ public void handleEvent( final HttpEventFW event = httpEventRO.wrap(buffer, index, index + length); switch (event.kind()) { - case AUTHORIZATION_FAILED: - { - HttpAuthorizationFailedFW e = event.authorizationFailed(); - String qname = context.supplyQName(e.namespacedId()); - out.printf(AUTHORIZATION_FAILED_FORMAT, qname, identity(e.identity()), asDateTime(e.timestamp())); - break; - } case REQUEST_ACCEPTED: { HttpRequestAcceptedFW e = event.requestAccepted(); diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java index a27f759791..f4c0ee0fc1 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/HttpEventContext.java @@ -52,29 +52,6 @@ public HttpEventContext( this.clock = context.clock(); } - public void authorizationFailed( - long sessionId, - long traceId, - long bindingId, - GuardHandler guard, - long authorization) - { - if (sessionId == 0) - { - String identity = guard == null ? null : guard.identity(authorization); - HttpEventFW event = httpEventRW - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorizationFailed(e -> e - .timestamp(clock.millis()) - .traceId(traceId) - .namespacedId(bindingId) - .identity(identity) - ) - .build(); - eventWriter.accept(httpTypeId, event.buffer(), event.offset(), event.limit()); - } - } - public void requestAccepted( long traceId, long bindingId, diff --git a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java index 6d34ab71a4..e8f99951e9 100644 --- a/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java +++ b/runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpServerFactory.java @@ -1059,7 +1059,6 @@ else if (!isCorsRequestAllowed(server.binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(traceId, server.routedId, server.initialId, credentialsMatch); - event.authorizationFailed(exchangeAuth, traceId, server.routedId, guard, authorization); } } @@ -4974,7 +4973,6 @@ else if (!isCorsRequestAllowed(binding, headers)) if (credentialsMatch != null) { exchangeAuth = guard.reauthorize(traceId, routedId, initialId, credentialsMatch); - event.authorizationFailed(exchangeAuth, traceId, routedId, guard, authorization); } } diff --git a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl index 61f9bce246..5bffe232f1 100644 --- a/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl +++ b/specs/binding-http.spec/src/main/resources/META-INF/zilla/http.idl @@ -54,13 +54,7 @@ scope http { enum HttpEventType (uint8) { - AUTHORIZATION_FAILED (1), - REQUEST_ACCEPTED (2) - } - - struct HttpAuthorizationFailed extends core::event::Event - { - string8 identity; + REQUEST_ACCEPTED (1) } struct HttpRequestAccepted extends core::event::Event @@ -74,7 +68,6 @@ scope http union HttpEvent switch (HttpEventType) { - case AUTHORIZATION_FAILED: HttpAuthorizationFailed authorizationFailed; case REQUEST_ACCEPTED: HttpRequestAccepted requestAccepted; } } From bb8358071971d05eb92f9bd8a0ddf6ff4643dc26 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 13:44:31 +0100 Subject: [PATCH 153/167] fix kafka authFail --- .../kafka/internal/KafkaEventContext.java | 22 ++++++++----------- .../stream/KafkaClientSaslHandshaker.java | 10 +++++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java index 6e773042aa..86e8bc3168 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/KafkaEventContext.java @@ -45,22 +45,18 @@ public KafkaEventContext( } public void authorizationFailed( - int errorCode, long traceId, long bindingId) { - if (errorCode != ERROR_NONE) - { - KafkaEventFW event = kafkaEventRW - .wrap(eventBuffer, 0, eventBuffer.capacity()) - .authorizationFailed(e -> e - .timestamp(clock.millis()) - .traceId(traceId) - .namespacedId(bindingId) - ) - .build(); - eventWriter.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); - } + KafkaEventFW event = kafkaEventRW + .wrap(eventBuffer, 0, eventBuffer.capacity()) + .authorizationFailed(e -> e + .timestamp(clock.millis()) + .traceId(traceId) + .namespacedId(bindingId) + ) + .build(); + eventWriter.accept(kafkaTypeId, event.buffer(), event.offset(), event.limit()); } public void apiVersionRejected( diff --git a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java index eaefe4424c..ca61063380 100644 --- a/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java +++ b/runtime/binding-kafka/src/main/java/io/aklivity/zilla/runtime/binding/kafka/internal/stream/KafkaClientSaslHandshaker.java @@ -706,7 +706,10 @@ private int decodeSaslPlainAuthenticate( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); - event.authorizationFailed(errorCode, traceId, client.routedId); + if (errorCode != ERROR_NONE) + { + event.authorizationFailed(traceId, client.originId); + } progress = authenticateResponse.limit(); @@ -741,7 +744,10 @@ private int decodeSaslScramAuthenticateFirst( if (authenticateResponse != null) { final int errorCode = authenticateResponse.errorCode(); - event.authorizationFailed(errorCode, traceId, client.routedId); + if (errorCode != ERROR_NONE) + { + event.authorizationFailed(traceId, client.originId); + } progress = authenticateResponse.limit(); From 864a587458a5bee7a261af7f3414845b12b43ad2 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 14:29:20 +0100 Subject: [PATCH 154/167] add http2 test --- .../specs/binding/http/config/v2/server.yaml | 33 +++++++++ .../stdout/internal/events/Http2EventsIT.java | 68 +++++++++++++++++++ .../internal/events/StdoutOutputRule.java | 1 + 3 files changed, 102 insertions(+) create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v2/server.yaml create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http2EventsIT.java diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v2/server.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v2/server.yaml new file mode 100644 index 0000000000..effa3e4a6f --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v2/server.yaml @@ -0,0 +1,33 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +--- +name: test +telemetry: + exporters: + stdout0: + type: stdout +bindings: + net0: + type: http + kind: server + options: + versions: + - h2 + routes: + - exit: app0 + when: + - headers: + :authority: localhost:8080 diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http2EventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http2EventsIT.java new file mode 100644 index 0000000000..e858786c85 --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/Http2EventsIT.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.events; + +import static io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration.HTTP_CONCURRENT_STREAMS; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import java.util.regex.Pattern; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +import io.aklivity.zilla.runtime.engine.test.EngineRule; +import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; +import io.aklivity.zilla.runtime.engine.test.annotation.Configure; + +public class Http2EventsIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/http/streams/network/rfc7540/message.format") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/http/streams/application/rfc7540/message.format"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); + + private final EngineRule engine = new EngineRule() + .directory("target/zilla-itests") + .countersBufferCapacity(8192) + .configure(HTTP_CONCURRENT_STREAMS, 100) + .configurationRoot("io/aklivity/zilla/specs/binding/http/config/v2") + .external("app0") + .clean(); + + private final StdoutOutputRule output = new StdoutOutputRule(); + + @Rule + public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); + + @Test + @Configuration("server.yaml") + @Specification({ + "${net}/connection.headers/client", + "${app}/connection.headers/server" }) + @Configure(name = "zilla.exporter.stdout.output", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + public void connectionHeaders() throws Exception + { + k3po.finish(); + output.expect(Pattern.compile("test.net0 - \\[[^\\]]+\\] REQUEST_ACCEPTED http GET localhost:8080 /\n")); + } +} diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/StdoutOutputRule.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/StdoutOutputRule.java index f5f2272985..be79fd3ba8 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/StdoutOutputRule.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/StdoutOutputRule.java @@ -50,6 +50,7 @@ public Statement apply( @Override public void evaluate() throws Throwable { + BOS.reset(); base.evaluate(); assertThat(BOS.toString(StandardCharsets.UTF_8), matchesPattern(expected)); } From 39ea9a750f911ccf3363482f0d3e66c3e761e432 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 15:00:19 +0100 Subject: [PATCH 155/167] add kafka test --- .../specs/binding/kafka/config/client.yaml | 26 +++++++ incubator/exporter-stdout/pom.xml | 6 ++ .../stdout/internal/events/KafkaEventsIT.java | 73 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/kafka/config/client.yaml create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/KafkaEventsIT.java diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/kafka/config/client.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/kafka/config/client.yaml new file mode 100644 index 0000000000..ff4c4a3aea --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/kafka/config/client.yaml @@ -0,0 +1,26 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +--- +name: test +telemetry: + exporters: + stdout0: + type: stdout +bindings: + app0: + type: kafka + kind: client + exit: net0 diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 47e588bb61..60877ec6d5 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -92,6 +92,12 @@ ${project.version} test + + ${project.groupId} + binding-kafka + ${project.version} + test + junit junit diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/KafkaEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/KafkaEventsIT.java new file mode 100644 index 0000000000..e1e8c9fda7 --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/KafkaEventsIT.java @@ -0,0 +1,73 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.events; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import java.util.regex.Pattern; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +import io.aklivity.zilla.runtime.engine.test.EngineRule; +import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; +import io.aklivity.zilla.runtime.engine.test.annotation.Configure; + +public class KafkaEventsIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/kafka/streams/network/group.f1.j5.s3.l3.h3") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/kafka/streams/application/group"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(15, SECONDS)); + + private final EngineRule engine = new EngineRule() + .directory("target/zilla-itests") + .countersBufferCapacity(8192) + .configure("zilla.binding.kafka.client.instance.id", + "io.aklivity.zilla.runtime.exporter.stdout.internal.events.KafkaEventsIT::supplyInstanceId") + .configurationRoot("io/aklivity/zilla/specs/binding/kafka/config") + .external("net0") + .clean(); + + private final StdoutOutputRule output = new StdoutOutputRule(); + + @Rule + public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); + + @Test + @Configuration("client.yaml") + @Specification({ + "${app}/invalid.describe.config/client", + "${net}/invalid.describe.config/server"}) + @Configure(name = "zilla.exporter.stdout.output", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + public void shouldHandleInvalidDescribeConfig() throws Exception + { + k3po.finish(); + output.expect(Pattern.compile("test.app0 - \\[[^\\]]+\\] API_VERSION_REJECTED 32 0\n")); + } + + public static String supplyInstanceId() + { + return "zilla"; + } +} From 18d823f6fe6eff24205ede676182b41d938d0bf0 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Mon, 26 Feb 2024 17:18:12 +0100 Subject: [PATCH 156/167] add tls test --- incubator/exporter-stdout.spec/pom.xml | 7 ++ .../specs/binding/tls/config/server.yaml | 38 +++++++++ .../binding/tls/config/stores/.gitignore | 2 + .../binding/tls/config/stores/client/keys | Bin 0 -> 3593 bytes .../binding/tls/config/stores/client/signers | Bin 0 -> 2579 bytes .../binding/tls/config/stores/client/trust | Bin 0 -> 1178 bytes .../binding/tls/config/stores/server/keys | Bin 0 -> 3701 bytes .../binding/tls/config/stores/server/signers | Bin 0 -> 2579 bytes .../binding/tls/config/stores/server/trust | Bin 0 -> 1178 bytes incubator/exporter-stdout/pom.xml | 22 ++++- .../stdout/internal/events/TlsEventsIT.java | 80 ++++++++++++++++++ .../binding/tls/internal/TlsEventContext.java | 4 +- 12 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/server.yaml create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/.gitignore create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/keys create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/signers create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/trust create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/keys create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/signers create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/trust create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TlsEventsIT.java diff --git a/incubator/exporter-stdout.spec/pom.xml b/incubator/exporter-stdout.spec/pom.xml index 5d2ed40d44..f9a5ed82a0 100644 --- a/incubator/exporter-stdout.spec/pom.xml +++ b/incubator/exporter-stdout.spec/pom.xml @@ -93,6 +93,13 @@ com.mycila license-maven-plugin + + + **/keys + **/trust + **/signers + + maven-checkstyle-plugin diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/server.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/server.yaml new file mode 100644 index 0000000000..fd7e4b90a0 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/server.yaml @@ -0,0 +1,38 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +--- +name: test +telemetry: + exporters: + stdout0: + type: stdout +vaults: + server: + type: filesystem + options: + keys: + store: stores/server/keys + type: pkcs12 + password: generated +bindings: + net0: + type: tls + kind: server + vault: server + options: + keys: + - localhost + exit: app0 diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/.gitignore b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/.gitignore new file mode 100644 index 0000000000..507484f3e9 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/.gitignore @@ -0,0 +1,2 @@ +*.crt +*.csr diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/keys b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/keys new file mode 100644 index 0000000000000000000000000000000000000000..d2fa3da9b94ead2e31bc206573eee4c36ae4e95b GIT binary patch literal 3593 zcmY+EbyO1$*T)Bp8Zdgq0O^t#-Q6Y9A)$1aLt0=6=qAVz5b;M!ry??2#QuBQo#h>gbNBhV!S*AMGX)^QSld- zzz~Gq{}mD10TG1Of3f-BdPqd}e_P}rJp4Qa@CJqeUcdy1K>v^b9)|+ymH|)fk#@&{ zpIF_%=UjaAVUcs0_ymBihd>0dpM{p`g_gD5;6WyO9bj7Vwf!Pfx4w%pDxkj=n;`x; zDDArDlB&~#<~^Xn1Gz8omT$(xPmy~zUXt#G&ayQR7Sa+ovumC`Ng;0 z>m#OpsS_h52t~t1Jl6%@#7C-NnKs6m&t0i9m(K!N>WPzBKtsHhq?T%1Mso2Zd*7#+ z=l$9lJ|={3TI0iWcRXdjWLDz5){(Cbdn<3zTA2!{r?$2r6h*DL>4owX%i@p$c6PYn zo+j5II!cG=`})ig1Laqh?((s1gF>AsN^v*N+uER5bJQE{7B5muqv${CqOKqk4!g3` z-LHQvYP=8SmTO zXG`P+bOEA!=0b!qXbcL6Y{HeBQ-$WYzJ2q{48l*rVJ&+Y!6QR=lrRw2VKLvjO7_@t_suSyHqj(ZMvFKzl&Vj66 z3DaCPA=sa8c#zGTQgY~A8Sre8g6Kta1m7!(fExf^RK*k328-^b{ijWwzXoFsOl4L^ zhj#^-?vaFLZaF=368cUwrdqCW84)nUR_cD4mcqt!exRSsonW;atKtFtz`PajA{r_Z z*;TH1@P0@Gp5V+uo86Tj*m%Ass=BT3gey3;U2)hsBAUfwci5>VewC?uhgXITq9aKj zd_onOFhKkZ{Eaakdo=K!r3YK93gIDVNY*Etwd1nZl7;TwUaB?#zoZIJ3^xupu2@dm zN?Mj1sw^7&57*r4wAneYF5;>x>dIpw%!!V}7|pT7>HKz0gS^aKS~PH~Xr%U;IVScd z)DtC(*iFYAqh!+0Y~S$UGBR;uzCSka+?!M1ovB0iRmCzc&!ZOvhFgpi_3iR7W69j3 zRGvl)MfA2X97FppRNU5wS(@`KadINH!Mm$(pt60e#m!8t=e_;au8HHDrl9%*QD&ll z+G*zLa*hEGC(-U*k=<4SG|*<|yKm>>`>|Z5B?X5luAjCqV4Z<@hp*?;eIWJ|JqvMN52bxYEa%*#rd!h}t6xV{30jGvn5hq?0E@KKp^?do` z7M0QuYlN|E%3~R*ES|L>I6z2lVL2l+dz$h>_C}pjX^KRO!@$c*7H z>a-vb;_PTq!sLEo|8%N7GU8y?`sE#g9`YCGC_H3buH3Lr;!ncb)=Q4J>WN|L_HhGq zC(E9ON@IntOV6xrC#TSNT>ZGAtvY%md#Zka{xY86*B>{YR5g<4E}SPwhjes7#nfS} z|5ha_ofs7x7~l->0eAvj0e%2DKn%w5pO{{Z4oG9}>FdfaCM_W+DJd={EhZ@@2SboZ z{(Fd+C=Wrx^A~a8;{pCQ=Kmyk|K(Vs|8eYd4!VZ~HG^E>I={ks_RA;v;W#99O;we6m)q_iU+IihSP~c(K2z5AyYG6weyyJfnpi%>$AGSVYgfKaw2mBtA6*tb%i7zn`m2y8haD3$ipU$?YpWerPk(GUoM5l z++OxBtVf;X>U)O+2s54QV%?> zo}9WTDcCJSd@s9YN_+nbT#26iErnKZ7f>=!4@CcU4_Dp>Gk(YO>_=WYH z3{RzH7$QE!AR#>Y@iR!G4Z=p_ddETtw5pu*2+?OnV=M)}Qn=gUmGq~k1 zb1D|0bV!`2dxwWch~PkwibrG$Wh2(+K4dh@{z4??-qo;LWrFHIkAa8+Y zUQ(^npzM&RQF&P03q~1Prz+fLs);!BYfn3~TsE@4**yt6L)M`gIS4ZzEwuw5%j|wf zuup8y^#E0Cz_OkeT0YN-hW_~SOTOz(L4vKu1wc$a7eb`;^5#rzo*YlZYk8UeUi3|e#RAd-HVSen+RGn(fl?1&8u9aILbSOXlDY&mKwM{;dL?$WrdTy z$9VQzKDs>6Hrd8}v>;M-of7|}AuW}|-YMKi>wk8W)Md*kKan1qWyFzJW}DmnW4aDH z-7RdoI}~Y(JsV^kdZqY!>yPi;arj{57d~V~Pl9d)cJ+Jyg zTGc2UJ>xmIuVC*mwtQ&{{I#l{>$j10edbqEW+zlpoJopGdur06c0Sw~Q5Un3mgU0a zG7?ufRpmC2H;pw;i&knH!}8Qa{lntXH-9yh4Bu@LbertwP~c0dxcwB}p>`t4VrMt> zK`D8%kU?=qW2_jP=^Uq@B=`Krt_Tny?3nBK@ZBFFt(HD8JDa1)L<6Wu;F8;Ypf_~^`&!G$^ym+oBK#n&Y@Kp8=~qP_ z)tbr`^(LN7s2-9|E7_+fr*ZTYLiO!_$B~!eqdvK_$$FisW+^r9sf_JVK?xaSjPFBY za%J;c`Nz9@3Swb`W$bu3FifycCsV(7e9GO$Ix3uptX+oCs^T8jkW-G+42+!^Kat|_ zr*2;M?uN>Hr4PDNreM?CA(~%wL~PR=7qKA^VUHTYW5Qbv0N&)00Or@bQGp>-x|e796N89v8+qn^uy; z;(2eB^j86N6I{`I+`CMHsLR2EIsak)u|p~V;B`EZ zaygQRpB)>$k9NNoC^C2$;1snUV0 zIpps}j*^D+WpI{B!eY=hU%3<}hD9HppnaB>pCn%P$!X)MICXk3-=7dYl;BJ#esrrV z|+?)n+|bAYdeaL1miT|;l}hP+hVACmX>h->+knli?mW@xP5 zP9qfg}bIEhcRT-5Ai_90kw)6Kq)VWt7pX zZ~L+xDcL5zTN}T+gWu__Aotbc;NWh6@tBBTLylg$6N{d-WERW}rVQhNkrEN!2NU2k z69RyAxo#NY44TKn{pVW!C=P*(JBw@+AYC40m}Xxg=ly2+oba+{u3Hwadjp>UFCp(= DFc+_; literal 0 HcmV?d00001 diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/signers b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/signers new file mode 100644 index 0000000000000000000000000000000000000000..58e72c446093d4363485c4e90602685f57a1a34e GIT binary patch literal 2579 zcmY+EXH*ji630VHfDl3pMZid}5rYPh-j^y(rNh#KMp|g0NDU?eQd|yHYQRNm=)EaD zbZLr!^j@VYEW&c!y}RAFALh-x-+yL4{*ZVuGc^?r63@^JVvr>25l@(?=%{k=42`sS zhT1D!iNpgv{}BNlXz@UsD{OI9<{-xZT|vN9)H!(CpGZ9I2~q+C{y)BY&Pxk>OJ5hp zA)V`N@@^E&$}h#WjcXsJrU7)C(&A}*4-@u(*N#s*Q(3!FHMywG%qce(-{FNQjbNMicMUV6Uu*TPec#?I%h@A)-ZG$aeiFv+6jTER zEr7jLHk6o&6w@xdif4RN5pYV-41@R+%;S#q&yA~%ES~Iu(sUV0W*?Mi@MC|mf-NP1 z$?(R!+0&Vg-egM}+vq0a-Kp8HSe!R>>vv_KD91XR zt^7j$`a|rTya9VP`T>qujgHj~zNWhD+D;UL%`_>r19xET_q})BgC;H@udyZp(u1Oq z7tZ`o=S4-NSad2(Vta?#jy|x$CDw+k)=A<%?GAs$3FwkiTN_32s|R`ZOv`?!jV&>r zT!jPow??gfF&(n%B{Ti6xadSbUh?e!+(|hhKFLvCMQOtFZt9@K`cR^GJ19<6ba z>pZjZMMM3mouj`O=#$Z$K$QUx;{}p`X8hvQ4nh_>w7Ln-xJgvVpeAJ_kF@CZ_SAATD5M1SZJ5Sy;9ZS~J`-qY zbd+(e9R&SKVv_x3grDcZ`+UT4FiXNciQ@pL18%vZ`8+Q-(Md|ly30z}=0+26GCoG> zY$)2oX9|&U)>IHh_!@8tgQoKjhzThPFL0GoKIW>%c%`OnOCFC&=DXX?aq?p;FcdVn%kwK%E4ix90A3hZ63^GV zgUi!M1QpNHcwls#Z7Oz;&q=Di96B=i#gIpiE&kovWObClhVrSy2GDk>ufTBu@QbZm zg@c&R=y=lQ>JaC(qs3OLS{V4n>(Tq2+++-RO=;v>!w0`x&GztwKhnREQU6MlZ?g{7 z=!KqUcp|)koCC8;=3~7*&hQZuGr_e$B)sN)QYQg+E?6C-@2ywxCZ)V7u0V{KYDD;5 z>g5ODYB!1Fm4<{@m`kT4YhBaE%EA=xrIussyw^)^E~FgeGe!zs+Iv>UVR#MgbA<;x zdE?9$AAz0MzG#2T^x23Eypiu(Cp-J5WsU1qoY|7BPBBBBMCXg8&!tkp?6ZIl6g|*s z!=Q#It*`e8v}J}k5%M21GVq*l@&XT!`|dWId5H%DuJo%Wbr%KpmbE#?3??l|i| zHB(F$)j?Jtp*F3Zhn5>wY6!O2A-%3UsdE+lt zGQecm;4AFiqwQMAwX2bF6 z>A;>CoT+0vbo+aq``^*E2Fd;PSB4X0`eBI>>p+*?;`o<|9gUOIzYV zjI)ZB+m{Uugeif0ji*_`>UCn2at``aRY&S%nJ#2;xL|^0v4vi4-J1w*zMuoosX6^v zQ@Bt#{_WYK0%Wm6Snki{>x&YX$l|QK9)dfQ{Fl0R`Y54jR2wOQ{5u4s|_ezhnbQ92^ldSKvqjrXy z=WT+X1O@RK@`T?fNt{`scesW;2Z*V`Cu?79@6>n+#xnXY(|GcLtG&$=mmlNYRnpcv z5=P|uyaK4CsygzOt{WHPBl?wElJxRA8XF(?L{~ znyY!1I!d*uI-|5WtQMzsy)2_?+db_>uC8-Gi9#L{Fxe~C3oYzc_NE8v3cg`9KUi2d z{GeRt{@dAGgo>q>^kAThB1X1BB45v3VA?&t19BOsC72U#l9oD^EG(ii~yRWl<;+vgxSy_rq5pv;leUEGw6TlJoWLxL( z0o`xuy$h?v@IFGptvX@LTnK%&ef#who1{LNWc85-_2Fh~Ij3jb)Npf_qT)`v8$F-6 zo;F~6u^A`n;G9JmzQN_kv?F5-*RW@(S~p7GwlOp5gf9H&NAF;8y2K+^gC7L^7QuElepYVL*D6 XnHL8^j^D*wb!qnbhfvc{5p(_xQmMVr literal 0 HcmV?d00001 diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/trust b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/client/trust new file mode 100644 index 0000000000000000000000000000000000000000..bb624ca8c88988584d4b0e87cd3a1a3af8104738 GIT binary patch literal 1178 zcmV;L1ZDd$f&`WV0Ru3C1WyJDDuzgg_YDCD0ic2eKm>vWJTQU;I52_)GzJMOhDe6@ z4FLxRpn?P?FoFaj0s#Opf&>}{2`Yw2hW8Bt2LUiC1_~;MNQUX zgIMAnnq*2-*ub9F1DOnX0s{cUP=JC1;G1k?NK!07S6Bey@ns7z`^bH(I>~$M;X~TY z6(};5n>n#|zp9Q{XDk__fHBqwIT(@Fp=M4{NEJMyfCyPhuFb71{3df&S15t%5L2!H z?N+4`tY6oyBUk>`*|sQak0tUb^8fVL}0a`E&5JXe0T)5#Pxfaa?v z*i=-Z2%=(u5L{=YYMyuY5HV~~82V^H=p*7l-Ijm+kU_0~5_GOxd@@4?cyq2F+^c<`pfmZvRjGh1((q_9Fre=EM^-Jx7FJ}JX74)wZqIcSJ z6RJ>KbqZvt(#eBIVUy{kQ{Y1$li|cxg4kL?+M!wErm7RWt`|f%?XELro@P&Hw3D<( z;fY1-fW9KS`@R(a6siTuZ{C=BHM_I9pjS`NRDpC&h z?j$`#dxwj#(mXRR^09zJ5UShoY+qV_+Ehyf^O@Q75QmH`h7?!slvvAqGHvLP2ppTJ z{p7kcx!Xvx0SWeuO}r~yx_vF?;FAfL*ZF6T6HlcB__#}|fffJSb`8|Lw?F(V@5iel z^h!2cT?eRnKZH1(-)=*_71d~Rf)(62bR$N4dmRoHu%T$eQNyV6Xf05qy&+qtGn(__I}gi_%lYOfcdnTUvNhk zO|USJcr*Mz;jka}Db+d$$qH`06=jQG`Cj-)@SAR5{f2?v;&Mg%fGHYiI!dKvu5qgz zNdl{7gnQU?zYb)=0K1Y~8qcMfT6^^0$xdk7Y4hV&J9a3E@99S2q|3Pwag^dA7k9x= z()}%sK{Po-fmFO^XWkQ9AFdAkr+?QN4V;3eeE^3U@#D*)$DfA{ zB@>$-eanXAChZbmfaKdl-Q=*?(XfJ|=rk{Lx*C= zDCocl*``*Ys+o%4F8~?KHc8H3wne$VnnaQr-LEF5kyQ9hMNGn3yFfQ!IoRJtuM=IC zgPGN>=Q``cs!QH?B^Xckp0=?qcFl+qR8lJR>e7lSY4O4-F*0aFBA>#~2eYi+RMRoT zU@+90QMD^sL|#L2^gyCfc+VRs>HH9c0O5XEYcM`AAutIB1uG5%0vZJX1Qcp~@iev} s%EsyJ(@eH)6}YwJoz?^tDsFeHFGU8z)D|l9S;NV|VAC9>0s{etpebc4%>V!Z literal 0 HcmV?d00001 diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/keys b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/keys new file mode 100644 index 0000000000000000000000000000000000000000..e10b65832b5594097fcedb74a5be13cbed78cfd0 GIT binary patch literal 3701 zcmY+EXE+-UyT+4hs6A`86gA7g ztx-Yr?K#&u?>X;>=enQkzMtp*_>;y#fK>fIe&_;a#`^TVa3fU_d45|>1j}56t(F}Cim$^>nwU-ogPWde3Q3TFi*~oOl-*L z@f4=-4b@w`rO=z}&icrsE<&~O+=FvMeN1r~GM~8IMAtu=f&UKh=!@j6L?2?T_jF@V z%AV6llRvH2V5!=q-NVNaJ4WjLQYqeKx=;G`PvWImqXYzIO=^k6#;;rgz7JFPohcqE zHGKL0^rjlld$Z3FLDTx=L}ART9R?zpy7l;Y5H3Sj6ln?V+JY|_9p{v=JLq&lzIVoZ z>qc{pI*X8H|2#NC4=cTHIN7re)XofWR91Wx|p9&^L;CJuTNr?JGQ)3+naJ z+~J)L^$>H(mjI6i@v$djbP!qCYWbWfW+4H(d(YYY$xf6tbpsN3PtdbJYAX_K-MG^v zs_YaVEkFHF6)HCh@A8CuMEke#W>HeP#dZkaqFP65_^5au%05c`WKWJIC^qk5A~L1@ z63rP`6VQvC#d8e`uvEBQ@TY0=PByeD9TI6N_Y#Pq9gt*k*&z=YGOLZt0yZfJZ ztnUa|g`uD=m@EZ`ClJ11Wig^}!r@HLxD7U1>_EIdao@uOXOfA2`g+3Y>C)}9n#94+ z{1g-w)ODMRo&jHyt8^!D0qkt>shx! zXv%U6DLdP>XX$1^yedao0MD}M&vUZR(moBXx!e5WzT>_JqjH)V~$hpPxRE{LlXOeH^QCgK&;=x}AxXR&bAxLLz*0TXAR)7L2 zV!x5wfh!Zk$MM3jtt-}jpYW?^p>nn3d&^O0fTQm?;?Rt4baR0K)Pz>WnoT1F3WCdC zMmgvUa^(m8=&C9J9Dvh|!0X95YSn8Wr4O?3a%#^#`GOOrRs zjbW{!uBd4CU6rUP&3!v^{6T2{vF{=ow?cZ(>TB+hlKQEQ`4RDi^{l<_NWM6 z%l;(|PBx#wAU8JP(T!BvR@hWQm;u?tr#k-9J67;b|P36l&I%wXXY;K?m>Qx1th$jZnoAa5e1aTLY> z?ja{D!%;l>YbAq#fWLzKzXbRnoF)4&&JuKKPBvq_KBVpUOSrh8J9fT+BmbMTk8l)v z+B|`ow!Ua>>iYM0iJBvi7_0i>Mb}0^%SFBNJgVKC)h?eY{9U_QwS=?RESTtbNdq%x zGY(B^9=g;yypiOvr4Cl(47YmCr@@ny<_8nc9|%un1m1D0KYBBd2(0h1yTRqVs@o#K zY0oeiK8o9GV!9TUzLkxI0h?}>u>~$(azSGC*##pMT`=Q?T(8UmORg_h3I0?DE$38M z0e=cqXi>wkCP<#p{Iiwno|E(M4y5E4DQB=$`SpcO8NAVK&AZ!cAHsrmnV)Uw26@)< ziZ$KcH%s2F;NIOyJQWV-P1_KhR&P#Iv61}cnBJ`Ps91-tq-um?J-_FT?Et|2vriKl z$3)!ffVPiffZ?b2K#7LC`ztl9adD^ANaI`0ut%hephe~fANuea7~xgzT~~?YU~8Il z?AGN5?dvxA8IV;tov^{8>~&7_lta7jx2ubJE2n(d`Md4E zau*UW+?ZsXU^`3)V}>1AiEXFFR~p!!Lp3<@B8>`_vso+1+-z5RZ7{2^tM+Fgl`b$H z0IJKNi&agnUmL8MZ-;1^%97EM5F}uEbqY|qKC&Yv@vB$@-cfZ5N)Q0L1E3%cwI#|$BsXY+zG_569yz=Ik9=l<}CF;?M0c4C+I*#(5Cmu zdbu>lo`^Q{Ps6p0a$;Fgsw-wu!%N`~bypQ#K>ioI%6VFkOn+5Qp3!DC^EKmj*@K)J z0u3ihfKnV!KE;i~QmGlum)hmB`%*dj?5hNjTdKHp(g6f7$F{#0luRwoon(e!tK;u8 z9t92s5z2fj{y1%tzEE8bMnQ@QPBqfv9>;FlOtYEpy0mAVU9{VA0aE$>PGpncKOb)D zHm$dp#}V6$naUwI+VeUhxCWowMV>&AyTr!n!`V7qvcoS08} z0a_ckCB#aaHN+++VH5$uUM@kGxEA7_()OnG9W{!_DfFHL^Ic`iD!FF0QoF$4pLx4% zMk_{sL`Wg$9dFisKM{j1w7K`BW2p4yV}$ z3A{a;*hM_)Gs(=)wT(Y9UhchFTF{6>d?6t<^*u7oJj$2hEci42VWK-te9$!1YpTW~N5hO-Y?}>jw(;d(w zqByp#S{fU11Ix13ip7vUBC+T(t19KU$o=O%M%-{2DZlbYIsUPqxYXk*`{IQ8l&kZH zQe_q>@i+k~iv@~isrpNGyB?9#y|;J}_l(uZwW~hUqKh6gvEYNs!Z!BTSZ)j?#A~kQ@cfMi7byP@@0bnt<|*F z-rsM!KJ^`xRq`^u7VhC?8}S|&thxe@I|b0(I7`dQBy*TcHKlp^{0&B{f!!IV3Mve=&q zBS7@^T;HEUf9S3??2OP)r23d?@-SAi|4boCtYVy}i2Egl_GzmOs^EIvJ6bO_Ok26$ z3#wY({DSNcN#@dOnd7-nXnH)BR7fcc=b%^%u0oPTA1J zK*Dp2`%LMBvtdI@8||X*?%jQW$qLd>{EheQL~wV6ZFzg@?DiVk|0zZ#=shiKT;1-M zjN7HET2}yESF4}GB`@f{2TbTWLt;nBUY7&a>h}2uo#PW%h1I&$6n7Z999AJ7ze)>xXkS^F3|K|zAhsyNJqKTs`T3YUWoTj;-bJ?)#fhg9Zz6(Zz-Ey6{% zdpT@kB&~Cr6||kc76SMr#`|)e&b6&pm6}MBTjb8R4k6!pRgcjbEXv#Gm=rB}{it8} z9XI9*i}j9&FdKi2BR^g4dAao}dB9@(M%(Oep&o;VR4p literal 0 HcmV?d00001 diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/signers b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/signers new file mode 100644 index 0000000000000000000000000000000000000000..0c8e698ab153438a4b54f495d8be87c334147419 GIT binary patch literal 2579 zcmY+EXE+-Q7ss=NgcymS_8u*oSVg6^^@?hY(rRl{yJ+iLH6oOXqQtC<(WaVTf=J5D<(Z!rGv)(=nG~b`U^jAe9KK zfe>Nz6Z{%OWb*!3#AFL0GTEG9tCKQ^vi|Ri4GsiRiI9B^5we4kgTnuhPo4`vxRHI@ zC9|Ajezk6Iwy`p~08;LicOWp}BLPB$wApY@Ee{vbm(MtPd9XQOf3&@7rR9<|o{&S& zpc9zJ5~*ChOTj!>CnJ})we7{DL<5q)hKu#@kg^)WgY-5l6hEKc%{d#;J-D&TwaAz0 z>Vu{Rul|W#jo#`oahdFYF%-8)Gge~z7?qJ#M$)p^eCnFt0{Q_}LOd9}G;z3i)r6yI zM^(FJA^AQsFI9wWwGs@zJ5Uj9_&I&%=z082$`|}KqhCzNoP`Gl>t@PQZdKmnjy!$W z_{jG8ioOHF-wKJyB@y(msi(!0RZ;JmoWSHGEBSIl;>bO*182E98=aprbO6(3De86x z)|PW%;OG5kJoehiIS)tg^-vdi1?<*h!eeS-oGz!=_LmAJ411j$kKDm`A5olV7y2&z zv}wS%0&$@!HgsN`VzesFF*ULBF$3F^7GZzc+jWN;DgTgFDn2qo+!wIE*kN-u+A z{(+HknO4vwwInX((@)btt1x?%w{l4#>#zql|o~D5?>CM z$WxkQS@dLQ{`|wNg>Hlh$B)go(n04#3DvyfmYa5$N$p%%;?9(?@J{`J!ioJz@8oH&(l~rzQAa&s2NDrY`BdYN9%mc;;*>yuHf?k#G zu>mFdd{S4ftPV4Ef-Z@(N9auU!iDIe`)auY^2|VjF#FfR&1ZUY_olGq7V(+O4DKfV zv527eeQyWn_wnDD9v*lF$E3EwZVSp_g{@gUvVbp`??^|Amy9X$EBLg0pk17gl%R5> zZK^N8C3TXQ3)E3JJJV}ok+Ji+1iFckCF0zqW^I033(A#aDtcBwT+O;sO(&?pJ@K7} zMcFeHqK5OZM>yEv=C6GWL+8|xT^H0(BTUa_rshwBMh(aPD!DAxE&5FZtOJ7UgLK^-l}D z_Waw4c-DqaO6nY|h3n7hCJuI!#(>u`o}&*(E1{gEscc(R3`tUbnPbMa>jjw?eBUNm zRMp;=8NCHpor6FR7_H;etJImgkZQ7wquL*`sS`gp4ZrVXeTYkQIIHC8AAaLdPIf@! zcb~6sN%##eYmT6Jg)1VXc_uVJSx2ucAq>OlsQw`@2D=lI=+k2%5|#00a#PsM30;mD zpq1zPKJd5r$g(!~C{s+s$6jcw#pp>1?rv&5#c8D1Xg)Bk3X#E*@B(C()Wt< z?P}#6<0$345zi+~COUSIBQRovSBIIl=vQTo!VrFsb%Hk|s?;N#+er9M$nZT2oQz!j zndypdki(?IWn61Q#0o`;y|R9(OmGjb%J+Qx-8x50>h`r&r?N}WBHsBeZ1wY#GTM=P zDg=U;)1S`81)_oI%!!t^>!qhJ!XPvZw!3xnz8iM%l7KBgZx0!P4qk$$;hOmo;JCEqzP$V>-zSCMcJLW|W5$JL#U|n7 z&MGe;A}vr}-aKcomkLZwVsDf)D;*jkuMTXy9S_Bpy9>#fF6bJ>ui-X}nbx$v9bAxU z)9~N5dVHtLNKOnRn!_yE#TiGtFrM(l+MHP7Rw0l{N{v!p{h%I&h~V8tHZwgz%ETe5 zFv$gh2|lS;;O_Ic<$E>^%d%JCDr4(SfHa*B$%G+XkK$RCjM@HtAtOK5isbOBgh|ce z?2NHV_Y7KStZcy%B?-d%Yd2U$we=bR@ZPlC(5`!LEn$8Zfe4nnF42d zG=QT`kgj>gvms%#+>$Y_CaTvPXFdz);r}=?ez|ejd5}&ZFX&9HBOBLDezOneB#pxE zzZ(ICQ^oa+>Z1D;9i6!2s}vJ?asws_+WVzn+6tFZd-X@{>Y!x&Mfq>3dcqzf0DTm0 zj8U5YxXm#A;SGPVy?Bc0oLuRxvn6*nMP8q)Q_#2ZW~mE%wJqZ9c1w}P+AZ?X6ZEr_ z7*2Y@if(?tQo@tu(o)t_=e;6BxV#qv)FyEMjM8LSWP`RWm+p_~eN*#f)DS$@51B&Oi8}Y@+KUG^9|a6S zkFzYA^;0-xRc!FJ9t}CAfn@`_B|Mtfbs&C{Inax^*6d1XQuOy0!5>OMcvvD=Y`i%7 z>y0mgAZLa$o232F*Tew6^sXST=qeqQalletv;1=(pU+Ef>??sDZV10y4F@ck65xc3 zi|l*R{y&u%u3_?qc}t|q@h`6iH#-k*};AN{=~CR>~GM!zT; zCiO}Go_kqf<%W^cM0!^2F8`r#eY1O-sN3C7mskQhqS7pl1#B(y`nHWp+GMpGr%aNn z=T}liR8gc7*)4AVu&@t4Tbl=RG83KFH&4KiuE_2Q)Jso*Js{FhSwMvnz!kK);x<2%#3j} zT*G;G7M}YdTx7C&ikVSqki~MZn${ePD=A;xNx%X2Qd+}e+@poTv$+~pGV-0sd_GF0 z#lc_em7zac2y+1=hJitu&ai_){7e7{H}ERACX-oyw+P#-*I=KHrdW+4VFPx# literal 0 HcmV?d00001 diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/trust b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tls/config/stores/server/trust new file mode 100644 index 0000000000000000000000000000000000000000..377ed0c4c4d7631c1f3e53c824dbfc466ae99a17 GIT binary patch literal 1178 zcmV;L1ZDd$f&`WV0Ru3C1WyJDDuzgg_YDCD0ic2eKm>vWJTQU;I52_)GzJMOhDe6@ z4FLxRpn?P?FoFaj0s#Opf&>}{2`Yw2hW8Bt2LUiC1_~;MNQU4l9){enSBfs9>1tbYml9TFJ7l>4Xb!4Z3 zhNw$M=pe4a1V7<{*z$bIk>aaXo6*ENgtde?9oX1HWEY+f%-`b=Sp^1j&OX=Nj4z;lzUv;|FOyeI~82FWud8?-r zIN&Y>F+}#CbLU4BoSG!r4?UCm>x0j;ZBKT)OK@PeaJtzjZF&orc10;Afuv-?DFBad z3->oNYexq}oZHFFUf^99YW}pIE(tLGbx_KJ)$5!wzsLoxt>ZrNVYw|0D7+?02MAp2 z$0qYS`r&tbfwui8k)B=h#l$9?WCmwdc?y>gqe4|JQKYu8pn8=)Fw!&w0ur@hV~8O1$Do=K z-!5QHRG*Rs*9GeK`s-#Vv02^4%4~>7nBgCax42JT1&|iCFM&I-hOs;M#qqCqvw2ovUmN>wG6Ia-&KI+VICFx17Js(Kb16HeX zCTx5Zyb&c})gumqqbPKA+Q5-g%(k3a`Ffp&x#^NX4bpRfle6#l-q&@$B8ce9^EPK` z_H|yMH%EumWDNRV{^(D&_0rLJaOfwfN3LNPO9d}YK-71BdZshOH5c||=9{QCn#jFM zRTjC-(QUA=!T_P_mQxtf5Av^pZxx800CXBb?CKk!{o+d#AmiD1+81X!U_`;e9TtVz zy-Cy({yG}74BrA&nzdc8Rr}M=ph(7(QkZg^*lrqOcIeMHB0cT_8PcuP8j|iTGsNBl z(V2607yLK#y3O}=?xmHT%NCDA<^*5l3d@g~^ONtZZ9}ahMyTL6~4obnQpd18sk~`)O zQNY3T)9LbEjku!G&izfivZ0Tvy}(a^XxkGQQ%%-!<1Olt>*DtSF;rK0xJSB8!ciY+ ztNF`Dm)45}^vGk>ux`;1`jD%2m2iF7vT1a8!CxG3gF3%j+OeFKum{y#fX%iSX?-!y zS4Hk*!{9-j(V<90kZnt{KJ6%ihUHvK;%-k!1N%wfi%4o%<&mEM#F(;ffTX<%mtZwt zNqAutIB1uG5%0vZJX1QaK~m2*yD s`~5+Cbw_IEe!aI70P!%3bIT)GyC;mK*x29&k|#0s{etpcIQQZU6uP literal 0 HcmV?d00001 diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 60877ec6d5..3e9fae1fd2 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,8 +26,8 @@ 11 11 - 0.05 - 10 + 0.67 + 0 @@ -79,6 +79,12 @@ ${project.version} provided + + ${project.groupId} + vault-filesystem.spec + ${project.version} + provided + ${project.groupId} engine @@ -98,6 +104,18 @@ ${project.version} test + + ${project.groupId} + binding-tls + ${project.version} + test + + + ${project.groupId} + vault-filesystem + ${project.version} + test + junit junit diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TlsEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TlsEventsIT.java new file mode 100644 index 0000000000..cb201e110c --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TlsEventsIT.java @@ -0,0 +1,80 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.events; + +import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_DRAIN_ON_CLOSE; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import java.util.regex.Pattern; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +import io.aklivity.zilla.runtime.engine.test.EngineRule; +import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; +import io.aklivity.zilla.runtime.engine.test.annotation.Configure; + +public class TlsEventsIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/tls/streams/network") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/tls/streams/application"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); + + private final EngineRule engine = new EngineRule() + .directory("target/zilla-itests") + .countersBufferCapacity(8192) + .configurationRoot("io/aklivity/zilla/specs/binding/tls/config") + .external("app0") + .configure(ENGINE_DRAIN_ON_CLOSE, false) + .clean(); + + private final StdoutOutputRule output = new StdoutOutputRule(); + + @Rule + public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); + + @Test + @Configuration("server.yaml") + @Specification({ + "${net}/client.hello.malformed/client"}) + @Configure(name = "zilla.exporter.stdout.output", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + public void shouldResetMalformedClientHello() throws Exception + { + k3po.finish(); + output.expect(Pattern.compile("test.net0 - \\[[^\\]]+\\] TLS_FAILED\n")); + } + + @Test + @Configuration("server.yaml") + @Specification({ + "${net}/server.handshake.timeout/client"}) + @Configure(name = "zilla.binding.tls.handshake.timeout", value = "1") + @Configure(name = "zilla.exporter.stdout.output", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + public void shouldTimeoutHandshake() throws Exception + { + k3po.finish(); + output.expect(Pattern.compile("test.net0 - \\[[^\\]]+\\] HANDSHAKE_FAILED\n")); + } +} diff --git a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java index b742088b8b..22722224ea 100644 --- a/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java +++ b/runtime/binding-tls/src/main/java/io/aklivity/zilla/runtime/binding/tls/internal/TlsEventContext.java @@ -94,7 +94,7 @@ public void tlsPeerNotVerified( { TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .tlsKeyRejected(e -> e + .tlsPeerNotVerified(e -> e .timestamp(clock.millis()) .traceId(traceId) .namespacedId(bindingId) @@ -109,7 +109,7 @@ public void tlsHandshakeFailed( { TlsEventFW event = tlsEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) - .tlsKeyRejected(e -> e + .tlsHandshakeFailed(e -> e .timestamp(clock.millis()) .traceId(traceId) .namespacedId(bindingId) From 814f74eddc570cd7fee456db5ef6aa4006c6f6dd Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 27 Feb 2024 09:36:24 +0100 Subject: [PATCH 157/167] add tcp test --- .../tcp/config/client.invalid.hostname.yaml | 28 ++++++++ incubator/exporter-stdout/pom.xml | 6 ++ .../stdout/internal/events/TcpEventsIT.java | 65 +++++++++++++++++++ .../tcp/internal/stream/TcpClientFactory.java | 5 +- .../tcp/internal/streams/ClientIT.java | 10 +++ .../tcp/config/client.invalid.hostname.yaml | 25 +++++++ 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java create mode 100644 specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml new file mode 100644 index 0000000000..2530d13a05 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml @@ -0,0 +1,28 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +--- +name: test +telemetry: + exporters: + stdout0: + type: stdout +bindings: + app0: + type: tcp + kind: client + options: + host: invalid-hostname + port: 8080 diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 3e9fae1fd2..5c88ead384 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -104,6 +104,12 @@ ${project.version} test + + ${project.groupId} + binding-tcp + ${project.version} + test + ${project.groupId} binding-tls diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java new file mode 100644 index 0000000000..ec8f5bcad1 --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java @@ -0,0 +1,65 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.events; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import java.util.regex.Pattern; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +import io.aklivity.zilla.runtime.engine.test.EngineRule; +import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; +import io.aklivity.zilla.runtime.engine.test.annotation.Configure; + +public class TcpEventsIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/tcp/streams/network/rfc793") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/tcp/streams/application/rfc793"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(5, SECONDS)); + + private final EngineRule engine = new EngineRule() + .directory("target/zilla-itests") + .countersBufferCapacity(4096) + .configurationRoot("io/aklivity/zilla/specs/binding/tcp/config") + .clean(); + + private final StdoutOutputRule output = new StdoutOutputRule(); + + @Rule + public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); + + @Test + @Configuration("client.invalid.hostname.yaml") + @Specification({ + "${app}/connection.failed/client" + }) + @Configure(name = "zilla.exporter.stdout.output", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + public void dnsResolutionFailed() throws Exception + { + k3po.finish(); + output.expect(Pattern.compile("test.app0 - \\[[^\\]]+\\] DNS_FAILED invalid-hostname\n")); + } +} diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index f27fad9f08..acdb8abad6 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -480,7 +480,10 @@ private void doNetShutdownOutput( } else { - networkKey.clear(OP_WRITE); + if (networkKey != null) + { + networkKey.clear(OP_WRITE); + } net.shutdownOutput(); if (net.socket().isInputShutdown()) diff --git a/runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java b/runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java index cd69d87413..87da64365f 100644 --- a/runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java +++ b/runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java @@ -215,6 +215,16 @@ public void connnectionFailed() throws Exception k3po.finish(); } + @Test + @Configuration("client.invalid.hostname.yaml") + @Specification({ + "${app}/connection.failed/client" + }) + public void dnsResolutionFailed() throws Exception + { + k3po.finish(); + } + @Test @Configuration("client.host.yaml") @Specification({ diff --git a/specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml b/specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml new file mode 100644 index 0000000000..ec005a92c9 --- /dev/null +++ b/specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml @@ -0,0 +1,25 @@ +# +# Copyright 2021-2023 Aklivity Inc. +# +# Aklivity licenses this file to you 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. +# + +--- +name: test +bindings: + app0: + type: tcp + kind: client + options: + host: invalid-hostname + port: 8080 From 3922e1590e83050a9a0e51bd7e41da09cf9b958e Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 27 Feb 2024 13:01:04 +0100 Subject: [PATCH 158/167] add jwt test --- .../server.authorization.credentials.yaml | 53 +++++++++++++++ .../reject.credentials.header/client.rpt | 46 +++++++++++++ incubator/exporter-stdout/pom.xml | 6 ++ .../stdout/internal/events/JwtEventsIT.java | 68 +++++++++++++++++++ .../guard/jwt/internal/JwtGuardHandler.java | 2 +- 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.authorization.credentials.yaml create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/JwtEventsIT.java diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.authorization.credentials.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.authorization.credentials.yaml new file mode 100644 index 0000000000..a6daa035f9 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.authorization.credentials.yaml @@ -0,0 +1,53 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +--- +name: test +telemetry: + exporters: + stdout0: + type: stdout +guards: + jwt0: + type: jwt + options: + issuer: https://auth.example.com + audience: https://api.example.com + keys: + - kty: RSA + n: qqEu50hX+43Bx4W1UYWnAVKwFm+vDbP0kuIOSLVNa+HKQdHTf+3Sei5UCnkskn796izA29D0DdCy3ET9oaKRHIJyKbqFl0rv6f516QzOoXKC6N01sXBHBE/ovs0wwDvlaW+gFGPgkzdcfUlyrWLDnLV7LcuQymhTND2uH0oR3wJnNENN/OFgM1KGPPDOe19YsIKdLqARgxrhZVsh06OurEviZTXOBFI5r+yac7haDwOQhLHXNv+Y9MNvxs5QLWPFIM3bNUWfYrJnLrs4hGJS+y/KDM9Si+HL30QAFXy4YNO33J8DHjZ7ddG5n8/FqplOKvRtUgjcKWlxoGY4VdVaDQ== + e: AQAB + alg: RS256 + kid: example +bindings: + net0: + type: http + kind: server + options: + versions: + - http/1.1 + authorization: + jwt0: + credentials: + cookies: + access_token: "{credentials}" + headers: + authorization: Bearer {credentials} + query: + access_token: "{credentials}" + routes: + - exit: app0 + guarded: + jwt0: [] diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt new file mode 100644 index 0000000000..28ef313832 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt @@ -0,0 +1,46 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +connect "zilla://streams/net0" + option zilla:window 8192 + option zilla:transmission "duplex" + +write zilla:begin.ext ${proxy:beginEx() + .typeId(zilla:id("proxy")) + .addressNone() + .build() + .info() + .secure() + .version("TLSv1.3") + .build() + .build() + .build()} + +connected + +write "GET / HTTP/1.1" "\r\n" + "Host: example.com:9090" "\r\n" + "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImV4YW1wbGUifQ.eyJhdWQiOiJodHRwczovL2FwaS5leGFtcGxlLmNvbSIsImV4cCI6MTcwODk0MDQ0MCwiaXNzIjoiaHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIiwic3ViIjoidXNlciJ9.KwZt_rDTDEOQ33URwZ8Gd1WqQjAIJESbt5Et309Yz7AJm1wWWyFhWm7AV6lt1rkX-eD-jVh0wHAsy7L4kdzBOErCdwFcdaB4u2jFDGn_9IK28lCedxIYmYtI4qn6eY916IIqRpwZcqzw08OEljfYUKo4UeX7JPAtha0GQmfZY1-NNcncg06xw3xkKSZ1SnIh9MZM1FNH_5QPZPL4NHP7DRXtaMn2w6YpO7n695Sc_3LuSDlfDDMVIUWuEreOzOXem6jheGIbJ-eDKhIXXPrOz1NBAJmvizbugMR7m_bodiEzzqt5ttKDs1974alrR_sYP8OYmR_rCqXc5N3lp_SW3A" "\r\n" + "\r\n" +write flush + +write close + +read "HTTP/1.1 404 Not Found" "\r\n" + "Server: Zilla" "\r\n" + "Connection: close" "\r\n" + "\r\n" + +read closed diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 5c88ead384..3c05776425 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -116,6 +116,12 @@ ${project.version} test + + ${project.groupId} + guard-jwt + ${project.version} + test + ${project.groupId} vault-filesystem diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/JwtEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/JwtEventsIT.java new file mode 100644 index 0000000000..da9ff69913 --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/JwtEventsIT.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.events; + +import static io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration.HTTP_SERVER_HEADER; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import java.util.regex.Pattern; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +import io.aklivity.zilla.runtime.engine.test.EngineRule; +import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; +import io.aklivity.zilla.runtime.engine.test.annotation.Configure; + +public class JwtEventsIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/authorization"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); + + private final EngineRule engine = new EngineRule() + .directory("target/zilla-itests") + .countersBufferCapacity(8192) + .configure(HTTP_SERVER_HEADER, "Zilla") + .configurationRoot("io/aklivity/zilla/specs/binding/http/config/v1.1") + .external("app0") + .clean(); + + private final StdoutOutputRule output = new StdoutOutputRule(); + + @Rule + public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); + + @Test + @Configuration("server.authorization.credentials.yaml") + @Specification({ + "${net}/reject.credentials.header/client", + }) + @Configure(name = "zilla.exporter.stdout.output", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + public void shouldRejectCredentialsHeader() throws Exception + { + k3po.finish(); + output.expect(Pattern.compile("test.net0 user \\[[^\\]]+\\] AUTHORIZATION_FAILED\n")); + } +} diff --git a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java index 3d5cede109..b34a2edd36 100644 --- a/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java +++ b/runtime/guard-jwt/src/main/java/io/aklivity/zilla/runtime/guard/jwt/internal/JwtGuardHandler.java @@ -154,6 +154,7 @@ public long reauthorize( String payload = signature.getPayload(); JwtClaims claims = JwtClaims.parse(payload); + subject = claims.getSubject(); NumericDate notBefore = claims.getNotBefore(); NumericDate notAfter = claims.getExpirationTime(); String issuer = claims.getIssuer(); @@ -168,7 +169,6 @@ public long reauthorize( break authorize; } - subject = claims.getSubject(); List roles = Optional.ofNullable(claims.getClaimValue("scope")) .map(s -> s.toString().intern()) .map(s -> s.split("\\s+")) From 15711a1a1928e641fd8558ea70fe5669029ffe6d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 27 Feb 2024 15:44:23 +0100 Subject: [PATCH 159/167] add sch-reg test --- .../http/config/v1.1/server.model.yaml | 71 ++++++++++++++++++ .../validation/valid.request/client.rpt | 41 ++++++++++ .../validation/valid.request/server.rpt | 43 +++++++++++ .../validation/valid.request/client.rpt | 33 ++++++++ .../validation/valid.request/server.rpt | 36 +++++++++ .../application/rfc7230/ValidationIT.java | 46 ++++++++++++ .../streams/network/rfc7230/ValidationIT.java | 47 ++++++++++++ incubator/exporter-stdout/pom.xml | 14 +++- .../events/SchemaRegistryEventsIT.java | 75 +++++++++++++++++++ .../json/internal/JsonValidatorHandler.java | 9 ++- 10 files changed, 411 insertions(+), 4 deletions(-) create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.model.yaml create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/client.rpt create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/server.rpt create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/client.rpt create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/server.rpt create mode 100644 incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/ValidationIT.java create mode 100644 incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/ValidationIT.java create mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/SchemaRegistryEventsIT.java diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.model.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.model.yaml new file mode 100644 index 0000000000..aa504aeba1 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.model.yaml @@ -0,0 +1,71 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +--- +name: test +telemetry: + exporters: + stdout0: + type: stdout +catalogs: + catalog0: + type: schema-registry + options: + url: http://localhost:8081 + context: default + max-age: 30 +bindings: + net0: + type: http + kind: server + options: + requests: + - path: /hello + method: GET + content: + model: test + length: 13 + - path: /valid/{category}/{id} + method: POST + content-type: + - text/plain + headers: + code: + model: test + length: 13 + params: + path: + category: + model: test + length: 13 + id: + model: test + length: 13 + query: + page: + model: test + length: 13 + content: + model: json + catalog: + catalog0: + - subject: item + versions: + - http/1.1 + routes: + - exit: app0 + when: + - headers: + :authority: localhost:8080 diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/client.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/client.rpt new file mode 100644 index 0000000000..6216b71c7c --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/client.rpt @@ -0,0 +1,41 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +# Request 5 - valid path params, query param, header field, valid content +connect "zilla://streams/app0" + option zilla:window 8192 + option zilla:transmission "half-duplex" + +write zilla:begin.ext ${http:beginEx() + .typeId(zilla:id("http")) + .header(":scheme", "http") + .header(":method", "POST") + .header(":path", "/valid/1234567890123/1234567890123?page=1234567890123") + .header(":authority", "localhost:8080") + .header("code", "1234567890123") + .build()} +connected + +write "1234567890123" +write close + +read zilla:begin.ext ${http:beginEx() + .typeId(zilla:id("http")) + .header(":status", "200") + .header("content-length", "9") + .build()} + +read "response5" +read closed diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/server.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/server.rpt new file mode 100644 index 0000000000..848daa9fb5 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/server.rpt @@ -0,0 +1,43 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +accept "zilla://streams/app0" + option zilla:window 8192 + option zilla:transmission "half-duplex" + +# Request 5 - valid path params, query param, header field, valid content +accepted +read zilla:begin.ext ${http:matchBeginEx() + .typeId(zilla:id("http")) + .header(":scheme", "http") + .header(":method", "POST") + .header(":path", "/valid/1234567890123/1234567890123?page=1234567890123") + .header(":authority", "localhost:8080") + .header("code", "1234567890123") + .build()} +connected + +read "1234567890123" +read closed + +write zilla:begin.ext ${http:beginEx() + .typeId(zilla:id("http")) + .header(":status", "200") + .header("content-length", "9") + .build()} +write flush + +write "response5" +write close diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/client.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/client.rpt new file mode 100644 index 0000000000..0875dc9e0b --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/client.rpt @@ -0,0 +1,33 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +connect "zilla://streams/net0" + option zilla:window 8192 + option zilla:transmission "duplex" +connected + +# Request 5 - valid path params, query param, header field, valid content +write "POST /valid/1234567890123/1234567890123?page=1234567890123 HTTP/1.1" "\r\n" +write "Host: localhost:8080" "\r\n" +write "Code: 1234567890123" "\r\n" +write "Content-Length: 13" "\r\n" +write "Content-Type: text/plain" "\r\n" +write "\r\n" +write "1234567890123" + +read "HTTP/1.1 200 OK\r\n" +read "Content-Length: 9" "\r\n" +read "\r\n" +read "response5" diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/server.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/server.rpt new file mode 100644 index 0000000000..4f9e49381b --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/server.rpt @@ -0,0 +1,36 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +property serverInitialWindow 8192 + +accept "zilla://streams/net0" + option zilla:window ${serverInitialWindow} + option zilla:transmission "duplex" +accepted +connected + +# Request 5 - valid path params, query param, header field, valid content +read "POST /valid/1234567890123/1234567890123?page=1234567890123 HTTP/1.1" "\r\n" +read "Host: localhost:8080" "\r\n" +read "Code: 1234567890123" "\r\n" +read "Content-Length: 13" "\r\n" +read "Content-Type: text/plain" "\r\n" +read "\r\n" +read "1234567890123" + +write "HTTP/1.1 200 OK\r\n" +write "Content-Length: 9" "\r\n" +write "\r\n" +write "response5" diff --git a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/ValidationIT.java b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/ValidationIT.java new file mode 100644 index 0000000000..b3eb3abafb --- /dev/null +++ b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/ValidationIT.java @@ -0,0 +1,46 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.specs.binding.http.streams.application.rfc7230; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +public class ValidationIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(5, SECONDS)); + + @Rule + public final TestRule chain = outerRule(k3po).around(timeout); + + @Test + @Specification({ + "${app}/valid.request/client", + "${app}/valid.request/server" }) + public void shouldProcessValidRequests() throws Exception + { + k3po.finish(); + } +} diff --git a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/ValidationIT.java b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/ValidationIT.java new file mode 100644 index 0000000000..fa7c1c79d6 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/ValidationIT.java @@ -0,0 +1,47 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.specs.binding.http.streams.network.rfc7230; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +public class ValidationIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); + + @Rule + public final TestRule chain = outerRule(k3po).around(timeout); + + @Test + @Specification({ + "${net}/valid.request/client", + "${net}/valid.request/server" }) + public void shouldProcessValidRequests() throws Exception + { + k3po.start(); + k3po.finish(); + } +} diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index 3c05776425..c3e2add4ac 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,7 +26,7 @@ 11 11 - 0.67 + 0.85 0 @@ -116,12 +116,24 @@ ${project.version} test + + ${project.groupId} + catalog-schema-registry + ${project.version} + test + ${project.groupId} guard-jwt ${project.version} test + + ${project.groupId} + model-json + ${project.version} + test + ${project.groupId} vault-filesystem diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/SchemaRegistryEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/SchemaRegistryEventsIT.java new file mode 100644 index 0000000000..8e455b9cc5 --- /dev/null +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/SchemaRegistryEventsIT.java @@ -0,0 +1,75 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.runtime.exporter.stdout.internal.events; + +import static io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration.HTTP_CONCURRENT_STREAMS; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import java.util.regex.Pattern; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +import io.aklivity.zilla.runtime.engine.test.EngineRule; +import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; +import io.aklivity.zilla.runtime.engine.test.annotation.Configure; + +public class SchemaRegistryEventsIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); + + private final EngineRule engine = new EngineRule() + .directory("target/zilla-itests") + .countersBufferCapacity(8192) + .configurationRoot("io/aklivity/zilla/specs/binding/http/config/v1.1") + .configure(HTTP_CONCURRENT_STREAMS, 100) + .external("app0") + .clean(); + + private final StdoutOutputRule output = new StdoutOutputRule(); + + @Rule + public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); + + @Test + @Configuration("server.model.yaml") + @Specification({ + "${net}/valid.request/client", + "${app}/valid.request/server" }) + @Configure(name = "zilla.exporter.stdout.output", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + public void shouldProcessValidRequests() throws Exception + { + k3po.finish(); + output.expect(Pattern.compile( + "test.app0 - \\[[^\\]]+\\] REQUEST_ACCEPTED " + + "http POST localhost:8080 /valid/1234567890123/1234567890123\\?page=1234567890123\n" + + "test.catalog0 - \\[[^\\]]+\\] REMOTE_ACCESS_REJECTED GET http://localhost:8081/subjects/item/versions/latest 0\n" + + "test.catalog0 - \\[[^\\]]+\\] REMOTE_ACCESS_REJECTED GET http://localhost:8081/schemas/ids/0 0\n" + + "test.catalog0 - \\[[^\\]]+\\] REMOTE_ACCESS_REJECTED GET http://localhost:8081/subjects/item/versions/latest 0\n" + + "test.catalog0 - \\[[^\\]]+\\] REMOTE_ACCESS_REJECTED GET http://localhost:8081/schemas/ids/0 0\n" + )); + } +} diff --git a/incubator/model-json/src/main/java/io/aklivity/zilla/runtime/model/json/internal/JsonValidatorHandler.java b/incubator/model-json/src/main/java/io/aklivity/zilla/runtime/model/json/internal/JsonValidatorHandler.java index 994601abc4..bd2e73dbc5 100644 --- a/incubator/model-json/src/main/java/io/aklivity/zilla/runtime/model/json/internal/JsonValidatorHandler.java +++ b/incubator/model-json/src/main/java/io/aklivity/zilla/runtime/model/json/internal/JsonValidatorHandler.java @@ -75,10 +75,13 @@ public boolean validate( : handler.resolve(subject, catalog.version); JsonProvider provider = supplyProvider(schemaId); - parser = provider.createParser(in); - while (parser.hasNext()) + if (provider != null) { - parser.next(); + parser = provider.createParser(in); + while (parser.hasNext()) + { + parser.next(); + } } } } From 1cc1e1b81318af2a2c3b88eac38c9237a64ded3c Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 27 Feb 2024 17:18:09 +0100 Subject: [PATCH 160/167] fix --- incubator/exporter-stdout.spec/pom.xml | 12 +++++ .../reject.credentials.header/server.rpt | 45 ++++++++++++++++++ .../network/rfc7230/AuthorizationIT.java | 47 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt create mode 100644 incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/AuthorizationIT.java diff --git a/incubator/exporter-stdout.spec/pom.xml b/incubator/exporter-stdout.spec/pom.xml index f9a5ed82a0..1b07db88bf 100644 --- a/incubator/exporter-stdout.spec/pom.xml +++ b/incubator/exporter-stdout.spec/pom.xml @@ -41,6 +41,18 @@ engine.spec ${project.version} + + ${project.groupId} + binding-http.spec + ${project.version} + test + + + ${project.groupId} + binding-proxy.spec + ${project.version} + test + junit junit diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt new file mode 100644 index 0000000000..07b06ab18f --- /dev/null +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt @@ -0,0 +1,45 @@ +# +# Copyright 2021-2023 Aklivity Inc +# +# Licensed under the Aklivity Community License (the "License"); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at +# +# https://www.aklivity.io/aklivity-community-license/ +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# + +accept "zilla://streams/net0" + option zilla:window 8192 + option zilla:transmission "duplex" +accepted + +read zilla:begin.ext ${proxy:matchBeginEx() + .typeId(zilla:id("proxy")) + .info() + .secure() + .version("TLSv1.3") + .build() + .build() + .build()} + +connected + +read "GET / HTTP/1.1" "\r\n" + "Host: example.com:9090" "\r\n" + "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImV4YW1wbGUifQ.eyJhdWQiOiJodHRwczovL2FwaS5leGFtcGxlLmNvbSIsImV4cCI6MTcwODk0MDQ0MCwiaXNzIjoiaHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIiwic3ViIjoidXNlciJ9.KwZt_rDTDEOQ33URwZ8Gd1WqQjAIJESbt5Et309Yz7AJm1wWWyFhWm7AV6lt1rkX-eD-jVh0wHAsy7L4kdzBOErCdwFcdaB4u2jFDGn_9IK28lCedxIYmYtI4qn6eY916IIqRpwZcqzw08OEljfYUKo4UeX7JPAtha0GQmfZY1-NNcncg06xw3xkKSZ1SnIh9MZM1FNH_5QPZPL4NHP7DRXtaMn2w6YpO7n695Sc_3LuSDlfDDMVIUWuEreOzOXem6jheGIbJ-eDKhIXXPrOz1NBAJmvizbugMR7m_bodiEzzqt5ttKDs1974alrR_sYP8OYmR_rCqXc5N3lp_SW3A" "\r\n" + "\r\n" + +read closed + +write "HTTP/1.1 404 Not Found" "\r\n" + "Server: Zilla" "\r\n" + "Connection: close" "\r\n" + "\r\n" +write flush + +write close diff --git a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/AuthorizationIT.java b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/AuthorizationIT.java new file mode 100644 index 0000000000..7e5d71cef8 --- /dev/null +++ b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/AuthorizationIT.java @@ -0,0 +1,47 @@ +/* + * Copyright 2021-2023 Aklivity Inc + * + * Licensed under the Aklivity Community License (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at + * + * https://www.aklivity.io/aklivity-community-license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.aklivity.zilla.specs.binding.http.streams.network.rfc7230; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.junit.rules.RuleChain.outerRule; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.DisableOnDebug; +import org.junit.rules.TestRule; +import org.junit.rules.Timeout; +import org.kaazing.k3po.junit.annotation.Specification; +import org.kaazing.k3po.junit.rules.K3poRule; + +public class AuthorizationIT +{ + private final K3poRule k3po = new K3poRule() + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization"); + + private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); + + @Rule + public final TestRule chain = outerRule(k3po).around(timeout); + + @Test + @Specification({ + "${net}/reject.credentials.header/client", + "${net}/reject.credentials.header/server", + }) + public void shouldRejectCredentialsHeader() throws Exception + { + k3po.finish(); + } +} From 9c4f1f38353b676f2ca5b72470b014e1e69a9a3f Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 27 Feb 2024 20:08:12 +0100 Subject: [PATCH 161/167] fix tcp 1 --- .../binding/tcp/internal/stream/TcpClientFactory.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index acdb8abad6..69ccd20847 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -264,13 +264,14 @@ private void doNetConnect( state = TcpState.openingInitial(state); net.setOption(SO_KEEPALIVE, options != null && options.keepalive); + networkKey = supplyPollerKey.apply(net); + if (net.connect(remoteAddress)) { onNetConnected(); } else { - networkKey = supplyPollerKey.apply(net); networkKey.handler(OP_CONNECT, this::onNetConnect); networkKey.register(OP_CONNECT); } @@ -480,10 +481,7 @@ private void doNetShutdownOutput( } else { - if (networkKey != null) - { - networkKey.clear(OP_WRITE); - } + networkKey.clear(OP_WRITE); net.shutdownOutput(); if (net.socket().isInputShutdown()) From 7f9d7a691f53239662d6154186304f53c18348b9 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 27 Feb 2024 21:32:04 +0100 Subject: [PATCH 162/167] fix tcp 2 --- .../binding/tcp/internal/TcpEventContext.java | 4 +- .../tcp/internal/stream/TcpClientFactory.java | 34 ++-- .../tcp/internal/stream/TcpClientRouter.java | 149 +++++++++++------- .../tcp/internal/streams/ClientIT.java | 13 +- .../tcp/config/client.invalid.hostname.yaml | 25 --- 5 files changed, 117 insertions(+), 108 deletions(-) delete mode 100644 specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java index ff9edf4e43..7159725444 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/TcpEventContext.java @@ -15,7 +15,6 @@ */ package io.aklivity.zilla.runtime.binding.tcp.internal; -import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.time.Clock; @@ -47,9 +46,8 @@ public TcpEventContext( public void dnsResolutionFailed( long traceId, long bindingId, - InetSocketAddress remoteAddress) + String address) { - String address = remoteAddress == null ? "" : remoteAddress.getHostString(); TcpEventFW event = tcpEventRW .wrap(eventBuffer, 0, eventBuffer.capacity()) .dnsFailed(e -> e diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java index 69ccd20847..cc3d8645f9 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientFactory.java @@ -44,7 +44,6 @@ import io.aklivity.zilla.runtime.binding.tcp.config.TcpOptionsConfig; import io.aklivity.zilla.runtime.binding.tcp.internal.TcpConfiguration; -import io.aklivity.zilla.runtime.binding.tcp.internal.TcpEventContext; import io.aklivity.zilla.runtime.binding.tcp.internal.config.TcpBindingConfig; import io.aklivity.zilla.runtime.binding.tcp.internal.types.Flyweight; import io.aklivity.zilla.runtime.binding.tcp.internal.types.OctetsFW; @@ -96,7 +95,6 @@ public class TcpClientFactory implements TcpStreamFactory private final int proxyTypeId; private final int windowThreshold; private final int initialMax; - private final TcpEventContext event; public TcpClientFactory( TcpConfiguration config, @@ -117,7 +115,6 @@ public TcpClientFactory( this.initialMax = bufferPool.slotCapacity(); this.windowThreshold = (bufferPool.slotCapacity() * config.windowThreshold()) / 100; - this.event = new TcpEventContext(context); } @Override @@ -155,7 +152,7 @@ public MessageConsumer newStream( TcpBindingConfig binding = router.lookup(routedId); if (binding != null) { - route = router.resolve(binding, authorization, beginEx); + route = router.resolve(binding, traceId, authorization, beginEx); } MessageConsumer newStream = null; @@ -166,7 +163,7 @@ public MessageConsumer newStream( final SocketChannel channel = newSocketChannel(); final TcpClient client = new TcpClient(application, originId, routedId, initialId, channel); - client.doNetConnect(traceId, route, binding.options); + client.doNetConnect(route, binding.options); newStream = client::onAppMessage; } @@ -253,33 +250,24 @@ private TcpClient( } private void doNetConnect( - long traceId, InetSocketAddress remoteAddress, TcpOptionsConfig options) { try { - try - { - state = TcpState.openingInitial(state); - net.setOption(SO_KEEPALIVE, options != null && options.keepalive); + state = TcpState.openingInitial(state); + net.setOption(SO_KEEPALIVE, options != null && options.keepalive); - networkKey = supplyPollerKey.apply(net); + networkKey = supplyPollerKey.apply(net); - if (net.connect(remoteAddress)) - { - onNetConnected(); - } - else - { - networkKey.handler(OP_CONNECT, this::onNetConnect); - networkKey.register(OP_CONNECT); - } + if (net.connect(remoteAddress)) + { + onNetConnected(); } - catch (UnresolvedAddressException ex) + else { - event.dnsResolutionFailed(traceId, routedId, remoteAddress); - throw ex; + networkKey.handler(OP_CONNECT, this::onNetConnect); + networkKey.register(OP_CONNECT); } } catch (UnresolvedAddressException | IOException ex) diff --git a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientRouter.java b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientRouter.java index ecfb709157..fc343d4e2b 100644 --- a/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientRouter.java +++ b/runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientRouter.java @@ -30,6 +30,7 @@ import org.agrona.collections.Long2ObjectHashMap; import io.aklivity.zilla.runtime.binding.tcp.config.TcpOptionsConfig; +import io.aklivity.zilla.runtime.binding.tcp.internal.TcpEventContext; import io.aklivity.zilla.runtime.binding.tcp.internal.config.TcpBindingConfig; import io.aklivity.zilla.runtime.binding.tcp.internal.config.TcpRouteConfig; import io.aklivity.zilla.runtime.binding.tcp.internal.types.Array32FW; @@ -49,12 +50,14 @@ public final class TcpClientRouter private final Function resolveHost; private final Long2ObjectHashMap bindings; + private final TcpEventContext event; public TcpClientRouter( EngineContext context) { this.resolveHost = context::resolveHost; this.bindings = new Long2ObjectHashMap<>(); + this.event = new TcpEventContext(context); } public void attach( @@ -71,6 +74,7 @@ public TcpBindingConfig lookup( public InetSocketAddress resolve( TcpBindingConfig binding, + long traceId, long authorization, ProxyBeginExFW beginEx) { @@ -79,86 +83,106 @@ public InetSocketAddress resolve( InetSocketAddress resolved = null; - if (beginEx == null) - { - resolved = options != null ? new InetSocketAddress(options.host, port) : null; - } - else if (binding.routes == TcpBindingConfig.DEFAULT_CLIENT_ROUTES) - { - ProxyAddressFW address = beginEx.address(); - resolved = resolveInetSocketAddress(address); - } - else + try { - final ProxyAddressFW address = beginEx.address(); - - for (TcpRouteConfig route : binding.routes) + if (beginEx == null) { - if (!route.authorized(authorization)) - { - continue; - } + InetAddress[] addresses = options != null ? resolveHost(options.host) : null; + resolved = addresses != null ? new InetSocketAddress(addresses[0], port) : null; + } + else if (binding.routes == TcpBindingConfig.DEFAULT_CLIENT_ROUTES) + { + ProxyAddressFW address = beginEx.address(); + resolved = resolveInetSocketAddress(address); + } + else + { + final ProxyAddressFW address = beginEx.address(); - Array32FW infos = beginEx.infos(); - ProxyInfoFW authorityInfo = infos.matchFirst(i -> i.kind() == AUTHORITY); - if (authorityInfo != null && route.matchesExplicit(r -> r.authority != null)) + for (TcpRouteConfig route : binding.routes) { - final List authorities = Arrays - .stream(resolveHost.apply(authorityInfo.authority().asString())) - .map(a -> new InetSocketAddress(a, port)) - .collect(Collectors.toList()); + if (!route.authorized(authorization)) + { + continue; + } - for (InetSocketAddress authority : authorities) + Array32FW infos = beginEx.infos(); + ProxyInfoFW authorityInfo = infos.matchFirst(i -> i.kind() == AUTHORITY); + if (authorityInfo != null && route.matchesExplicit(r -> r.authority != null)) { - if (route.matchesExplicit(authority)) + final List authorities = Arrays + .stream(resolveHost(authorityInfo.authority().asString())) + .map(a -> new InetSocketAddress(a, port)) + .collect(Collectors.toList()); + + for (InetSocketAddress authority : authorities) { - resolved = authority; - break; + if (route.matchesExplicit(authority)) + { + resolved = authority; + break; + } } } - } - if (resolved == null) - { - resolved = resolve(address, authorization, route::matchesExplicit); - } + if (resolved == null) + { + resolved = resolve(address, authorization, route::matchesExplicit); + } - if (resolved != null) - { - break; + if (resolved != null) + { + break; + } } - } - - if (resolved == null && - options != null && - options.host != null && - !"*".equals(options.host)) - { - final List host = Arrays - .stream(resolveHost.apply(options.host)) - .map(a -> new InetSocketAddress(a, port)) - .collect(Collectors.toList()); - for (TcpRouteConfig route : binding.routes) + if (resolved == null && + options != null && + options.host != null && + !"*".equals(options.host)) { - if (!route.authorized(authorization)) + final List host = Arrays + .stream(resolveHost(options.host)) + .map(a -> new InetSocketAddress(a, port)) + .collect(Collectors.toList()); + + for (TcpRouteConfig route : binding.routes) { - continue; - } + if (!route.authorized(authorization)) + { + continue; + } - resolved = resolve(address, authorization, host::contains); + resolved = resolve(address, authorization, host::contains); - if (resolved != null) - { - break; + if (resolved != null) + { + break; + } } } } } - + catch (TcpDnsFailedException ex) + { + event.dnsResolutionFailed(traceId, binding.id, ex.hostname); + } return resolved; } + private InetAddress[] resolveHost( + String hostname) + { + try + { + return resolveHost.apply(hostname); + } + catch (Throwable ex) + { + throw new TcpDnsFailedException(ex, hostname); + } + } + public void detach( long bindingId) { @@ -291,4 +315,17 @@ private InetSocketAddress resolveInetSocketAddress( return resolved; } + + private static final class TcpDnsFailedException extends RuntimeException + { + private final String hostname; + + TcpDnsFailedException( + Throwable cause, + String hostname) + { + super(cause); + this.hostname = hostname; + } + } } diff --git a/runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java b/runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java index 87da64365f..5373187431 100644 --- a/runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java +++ b/runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java @@ -21,7 +21,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.rules.RuleChain.outerRule; +import java.net.InetAddress; import java.net.InetSocketAddress; +import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; @@ -37,6 +39,7 @@ import io.aklivity.zilla.runtime.engine.test.EngineRule; import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; +import io.aklivity.zilla.runtime.engine.test.annotation.Configure; public class ClientIT { @@ -216,10 +219,12 @@ public void connnectionFailed() throws Exception } @Test - @Configuration("client.invalid.hostname.yaml") + @Configuration("client.host.yaml") @Specification({ "${app}/connection.failed/client" }) + @Configure(name = "zilla.engine.host.resolver", + value = "io.aklivity.zilla.runtime.binding.tcp.internal.streams.ClientIT::resolveHost") public void dnsResolutionFailed() throws Exception { k3po.finish(); @@ -336,4 +341,10 @@ public void shouldWriteDataAfterReceiveEnd() throws Exception } } } + + public static InetAddress[] resolveHost( + String host) throws UnknownHostException + { + throw new UnknownHostException(); + } } diff --git a/specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml b/specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml deleted file mode 100644 index ec005a92c9..0000000000 --- a/specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# -# Copyright 2021-2023 Aklivity Inc. -# -# Aklivity licenses this file to you 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. -# - ---- -name: test -bindings: - app0: - type: tcp - kind: client - options: - host: invalid-hostname - port: 8080 From e30ec02037af09e28cf9ccd1509507332bd91f0f Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Tue, 27 Feb 2024 21:32:14 +0100 Subject: [PATCH 163/167] fix tcp 3 --- .../binding/tcp/config/client.invalid.hostname.yaml | 2 +- .../exporter/stdout/internal/events/TcpEventsIT.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml index 2530d13a05..04191ddc52 100644 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml +++ b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml @@ -24,5 +24,5 @@ bindings: type: tcp kind: client options: - host: invalid-hostname + host: localhost port: 8080 diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java index ec8f5bcad1..2f69533e36 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java @@ -17,6 +17,8 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.rules.RuleChain.outerRule; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.regex.Pattern; import org.junit.Rule; @@ -57,9 +59,17 @@ public class TcpEventsIT }) @Configure(name = "zilla.exporter.stdout.output", value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") + @Configure(name = "zilla.engine.host.resolver", + value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.TcpEventsIT::resolveHost") public void dnsResolutionFailed() throws Exception { k3po.finish(); - output.expect(Pattern.compile("test.app0 - \\[[^\\]]+\\] DNS_FAILED invalid-hostname\n")); + output.expect(Pattern.compile("test.app0 - \\[[^\\]]+\\] DNS_FAILED localhost\n")); + } + + public static InetAddress[] resolveHost( + String host) throws UnknownHostException + { + throw new UnknownHostException(); } } From 0a0d97d76453d356575c18c906405d0fffb6994d Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 28 Feb 2024 09:35:11 +0100 Subject: [PATCH 164/167] rm sch-reg test --- .../http/config/v1.1/server.model.yaml | 71 ------------------ .../validation/valid.request/client.rpt | 41 ---------- .../validation/valid.request/server.rpt | 43 ----------- .../validation/valid.request/client.rpt | 33 -------- .../validation/valid.request/server.rpt | 36 --------- .../application/rfc7230/ValidationIT.java | 46 ------------ .../streams/network/rfc7230/ValidationIT.java | 47 ------------ incubator/exporter-stdout/pom.xml | 2 +- .../events/SchemaRegistryEventsIT.java | 75 ------------------- 9 files changed, 1 insertion(+), 393 deletions(-) delete mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.model.yaml delete mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/client.rpt delete mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/server.rpt delete mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/client.rpt delete mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/server.rpt delete mode 100644 incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/ValidationIT.java delete mode 100644 incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/ValidationIT.java delete mode 100644 incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/SchemaRegistryEventsIT.java diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.model.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.model.yaml deleted file mode 100644 index aa504aeba1..0000000000 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/config/v1.1/server.model.yaml +++ /dev/null @@ -1,71 +0,0 @@ -# -# Copyright 2021-2023 Aklivity Inc -# -# Licensed under the Aklivity Community License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at -# -# https://www.aklivity.io/aklivity-community-license/ -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# - ---- -name: test -telemetry: - exporters: - stdout0: - type: stdout -catalogs: - catalog0: - type: schema-registry - options: - url: http://localhost:8081 - context: default - max-age: 30 -bindings: - net0: - type: http - kind: server - options: - requests: - - path: /hello - method: GET - content: - model: test - length: 13 - - path: /valid/{category}/{id} - method: POST - content-type: - - text/plain - headers: - code: - model: test - length: 13 - params: - path: - category: - model: test - length: 13 - id: - model: test - length: 13 - query: - page: - model: test - length: 13 - content: - model: json - catalog: - catalog0: - - subject: item - versions: - - http/1.1 - routes: - - exit: app0 - when: - - headers: - :authority: localhost:8080 diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/client.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/client.rpt deleted file mode 100644 index 6216b71c7c..0000000000 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/client.rpt +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright 2021-2023 Aklivity Inc -# -# Licensed under the Aklivity Community License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at -# -# https://www.aklivity.io/aklivity-community-license/ -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# - -# Request 5 - valid path params, query param, header field, valid content -connect "zilla://streams/app0" - option zilla:window 8192 - option zilla:transmission "half-duplex" - -write zilla:begin.ext ${http:beginEx() - .typeId(zilla:id("http")) - .header(":scheme", "http") - .header(":method", "POST") - .header(":path", "/valid/1234567890123/1234567890123?page=1234567890123") - .header(":authority", "localhost:8080") - .header("code", "1234567890123") - .build()} -connected - -write "1234567890123" -write close - -read zilla:begin.ext ${http:beginEx() - .typeId(zilla:id("http")) - .header(":status", "200") - .header("content-length", "9") - .build()} - -read "response5" -read closed diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/server.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/server.rpt deleted file mode 100644 index 848daa9fb5..0000000000 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation/valid.request/server.rpt +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright 2021-2023 Aklivity Inc -# -# Licensed under the Aklivity Community License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at -# -# https://www.aklivity.io/aklivity-community-license/ -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# - -accept "zilla://streams/app0" - option zilla:window 8192 - option zilla:transmission "half-duplex" - -# Request 5 - valid path params, query param, header field, valid content -accepted -read zilla:begin.ext ${http:matchBeginEx() - .typeId(zilla:id("http")) - .header(":scheme", "http") - .header(":method", "POST") - .header(":path", "/valid/1234567890123/1234567890123?page=1234567890123") - .header(":authority", "localhost:8080") - .header("code", "1234567890123") - .build()} -connected - -read "1234567890123" -read closed - -write zilla:begin.ext ${http:beginEx() - .typeId(zilla:id("http")) - .header(":status", "200") - .header("content-length", "9") - .build()} -write flush - -write "response5" -write close diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/client.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/client.rpt deleted file mode 100644 index 0875dc9e0b..0000000000 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/client.rpt +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright 2021-2023 Aklivity Inc -# -# Licensed under the Aklivity Community License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at -# -# https://www.aklivity.io/aklivity-community-license/ -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# - -connect "zilla://streams/net0" - option zilla:window 8192 - option zilla:transmission "duplex" -connected - -# Request 5 - valid path params, query param, header field, valid content -write "POST /valid/1234567890123/1234567890123?page=1234567890123 HTTP/1.1" "\r\n" -write "Host: localhost:8080" "\r\n" -write "Code: 1234567890123" "\r\n" -write "Content-Length: 13" "\r\n" -write "Content-Type: text/plain" "\r\n" -write "\r\n" -write "1234567890123" - -read "HTTP/1.1 200 OK\r\n" -read "Content-Length: 9" "\r\n" -read "\r\n" -read "response5" diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/server.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/server.rpt deleted file mode 100644 index 4f9e49381b..0000000000 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation/valid.request/server.rpt +++ /dev/null @@ -1,36 +0,0 @@ -# -# Copyright 2021-2023 Aklivity Inc -# -# Licensed under the Aklivity Community License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at -# -# https://www.aklivity.io/aklivity-community-license/ -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# - -property serverInitialWindow 8192 - -accept "zilla://streams/net0" - option zilla:window ${serverInitialWindow} - option zilla:transmission "duplex" -accepted -connected - -# Request 5 - valid path params, query param, header field, valid content -read "POST /valid/1234567890123/1234567890123?page=1234567890123 HTTP/1.1" "\r\n" -read "Host: localhost:8080" "\r\n" -read "Code: 1234567890123" "\r\n" -read "Content-Length: 13" "\r\n" -read "Content-Type: text/plain" "\r\n" -read "\r\n" -read "1234567890123" - -write "HTTP/1.1 200 OK\r\n" -write "Content-Length: 9" "\r\n" -write "\r\n" -write "response5" diff --git a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/ValidationIT.java b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/ValidationIT.java deleted file mode 100644 index b3eb3abafb..0000000000 --- a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/ValidationIT.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc - * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at - * - * https://www.aklivity.io/aklivity-community-license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package io.aklivity.zilla.specs.binding.http.streams.application.rfc7230; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.junit.rules.RuleChain.outerRule; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.DisableOnDebug; -import org.junit.rules.TestRule; -import org.junit.rules.Timeout; -import org.kaazing.k3po.junit.annotation.Specification; -import org.kaazing.k3po.junit.rules.K3poRule; - -public class ValidationIT -{ - private final K3poRule k3po = new K3poRule() - .addScriptRoot("app", "io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation"); - - private final TestRule timeout = new DisableOnDebug(new Timeout(5, SECONDS)); - - @Rule - public final TestRule chain = outerRule(k3po).around(timeout); - - @Test - @Specification({ - "${app}/valid.request/client", - "${app}/valid.request/server" }) - public void shouldProcessValidRequests() throws Exception - { - k3po.finish(); - } -} diff --git a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/ValidationIT.java b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/ValidationIT.java deleted file mode 100644 index fa7c1c79d6..0000000000 --- a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/ValidationIT.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc - * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at - * - * https://www.aklivity.io/aklivity-community-license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package io.aklivity.zilla.specs.binding.http.streams.network.rfc7230; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.junit.rules.RuleChain.outerRule; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.DisableOnDebug; -import org.junit.rules.TestRule; -import org.junit.rules.Timeout; -import org.kaazing.k3po.junit.annotation.Specification; -import org.kaazing.k3po.junit.rules.K3poRule; - -public class ValidationIT -{ - private final K3poRule k3po = new K3poRule() - .addScriptRoot("net", "io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation"); - - private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); - - @Rule - public final TestRule chain = outerRule(k3po).around(timeout); - - @Test - @Specification({ - "${net}/valid.request/client", - "${net}/valid.request/server" }) - public void shouldProcessValidRequests() throws Exception - { - k3po.start(); - k3po.finish(); - } -} diff --git a/incubator/exporter-stdout/pom.xml b/incubator/exporter-stdout/pom.xml index c3e2add4ac..58bf155c90 100644 --- a/incubator/exporter-stdout/pom.xml +++ b/incubator/exporter-stdout/pom.xml @@ -26,7 +26,7 @@ 11 11 - 0.85 + 0.75 0 diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/SchemaRegistryEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/SchemaRegistryEventsIT.java deleted file mode 100644 index 8e455b9cc5..0000000000 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/SchemaRegistryEventsIT.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc - * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at - * - * https://www.aklivity.io/aklivity-community-license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package io.aklivity.zilla.runtime.exporter.stdout.internal.events; - -import static io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration.HTTP_CONCURRENT_STREAMS; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.junit.rules.RuleChain.outerRule; - -import java.util.regex.Pattern; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.DisableOnDebug; -import org.junit.rules.TestRule; -import org.junit.rules.Timeout; -import org.kaazing.k3po.junit.annotation.Specification; -import org.kaazing.k3po.junit.rules.K3poRule; - -import io.aklivity.zilla.runtime.engine.test.EngineRule; -import io.aklivity.zilla.runtime.engine.test.annotation.Configuration; -import io.aklivity.zilla.runtime.engine.test.annotation.Configure; - -public class SchemaRegistryEventsIT -{ - private final K3poRule k3po = new K3poRule() - .addScriptRoot("net", "io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/validation") - .addScriptRoot("app", "io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/validation"); - - private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); - - private final EngineRule engine = new EngineRule() - .directory("target/zilla-itests") - .countersBufferCapacity(8192) - .configurationRoot("io/aklivity/zilla/specs/binding/http/config/v1.1") - .configure(HTTP_CONCURRENT_STREAMS, 100) - .external("app0") - .clean(); - - private final StdoutOutputRule output = new StdoutOutputRule(); - - @Rule - public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); - - @Test - @Configuration("server.model.yaml") - @Specification({ - "${net}/valid.request/client", - "${app}/valid.request/server" }) - @Configure(name = "zilla.exporter.stdout.output", - value = "io.aklivity.zilla.runtime.exporter.stdout.internal.events.StdoutOutputRule.OUT") - public void shouldProcessValidRequests() throws Exception - { - k3po.finish(); - output.expect(Pattern.compile( - "test.app0 - \\[[^\\]]+\\] REQUEST_ACCEPTED " + - "http POST localhost:8080 /valid/1234567890123/1234567890123\\?page=1234567890123\n" + - "test.catalog0 - \\[[^\\]]+\\] REMOTE_ACCESS_REJECTED GET http://localhost:8081/subjects/item/versions/latest 0\n" + - "test.catalog0 - \\[[^\\]]+\\] REMOTE_ACCESS_REJECTED GET http://localhost:8081/schemas/ids/0 0\n" + - "test.catalog0 - \\[[^\\]]+\\] REMOTE_ACCESS_REJECTED GET http://localhost:8081/subjects/item/versions/latest 0\n" + - "test.catalog0 - \\[[^\\]]+\\] REMOTE_ACCESS_REJECTED GET http://localhost:8081/schemas/ids/0 0\n" - )); - } -} From 9748627e874599dd84c58175344221befd9893f5 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 28 Feb 2024 09:41:14 +0100 Subject: [PATCH 165/167] ref jwt test --- .../reject.credentials.header/client.rpt | 46 ------------------ .../reject.credentials.header/server.rpt | 45 ------------------ .../network/rfc7230/AuthorizationIT.java | 47 ------------------- .../stdout/internal/events/JwtEventsIT.java | 4 +- .../reject.credentials.header/client.rpt | 2 +- .../reject.credentials.header/server.rpt | 2 +- 6 files changed, 4 insertions(+), 142 deletions(-) delete mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt delete mode 100644 incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt delete mode 100644 incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/AuthorizationIT.java diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt deleted file mode 100644 index 28ef313832..0000000000 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt +++ /dev/null @@ -1,46 +0,0 @@ -# -# Copyright 2021-2023 Aklivity Inc -# -# Licensed under the Aklivity Community License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at -# -# https://www.aklivity.io/aklivity-community-license/ -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# - -connect "zilla://streams/net0" - option zilla:window 8192 - option zilla:transmission "duplex" - -write zilla:begin.ext ${proxy:beginEx() - .typeId(zilla:id("proxy")) - .addressNone() - .build() - .info() - .secure() - .version("TLSv1.3") - .build() - .build() - .build()} - -connected - -write "GET / HTTP/1.1" "\r\n" - "Host: example.com:9090" "\r\n" - "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImV4YW1wbGUifQ.eyJhdWQiOiJodHRwczovL2FwaS5leGFtcGxlLmNvbSIsImV4cCI6MTcwODk0MDQ0MCwiaXNzIjoiaHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIiwic3ViIjoidXNlciJ9.KwZt_rDTDEOQ33URwZ8Gd1WqQjAIJESbt5Et309Yz7AJm1wWWyFhWm7AV6lt1rkX-eD-jVh0wHAsy7L4kdzBOErCdwFcdaB4u2jFDGn_9IK28lCedxIYmYtI4qn6eY916IIqRpwZcqzw08OEljfYUKo4UeX7JPAtha0GQmfZY1-NNcncg06xw3xkKSZ1SnIh9MZM1FNH_5QPZPL4NHP7DRXtaMn2w6YpO7n695Sc_3LuSDlfDDMVIUWuEreOzOXem6jheGIbJ-eDKhIXXPrOz1NBAJmvizbugMR7m_bodiEzzqt5ttKDs1974alrR_sYP8OYmR_rCqXc5N3lp_SW3A" "\r\n" - "\r\n" -write flush - -write close - -read "HTTP/1.1 404 Not Found" "\r\n" - "Server: Zilla" "\r\n" - "Connection: close" "\r\n" - "\r\n" - -read closed diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt deleted file mode 100644 index 07b06ab18f..0000000000 --- a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright 2021-2023 Aklivity Inc -# -# Licensed under the Aklivity Community License (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at -# -# https://www.aklivity.io/aklivity-community-license/ -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. -# - -accept "zilla://streams/net0" - option zilla:window 8192 - option zilla:transmission "duplex" -accepted - -read zilla:begin.ext ${proxy:matchBeginEx() - .typeId(zilla:id("proxy")) - .info() - .secure() - .version("TLSv1.3") - .build() - .build() - .build()} - -connected - -read "GET / HTTP/1.1" "\r\n" - "Host: example.com:9090" "\r\n" - "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImV4YW1wbGUifQ.eyJhdWQiOiJodHRwczovL2FwaS5leGFtcGxlLmNvbSIsImV4cCI6MTcwODk0MDQ0MCwiaXNzIjoiaHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIiwic3ViIjoidXNlciJ9.KwZt_rDTDEOQ33URwZ8Gd1WqQjAIJESbt5Et309Yz7AJm1wWWyFhWm7AV6lt1rkX-eD-jVh0wHAsy7L4kdzBOErCdwFcdaB4u2jFDGn_9IK28lCedxIYmYtI4qn6eY916IIqRpwZcqzw08OEljfYUKo4UeX7JPAtha0GQmfZY1-NNcncg06xw3xkKSZ1SnIh9MZM1FNH_5QPZPL4NHP7DRXtaMn2w6YpO7n695Sc_3LuSDlfDDMVIUWuEreOzOXem6jheGIbJ-eDKhIXXPrOz1NBAJmvizbugMR7m_bodiEzzqt5ttKDs1974alrR_sYP8OYmR_rCqXc5N3lp_SW3A" "\r\n" - "\r\n" - -read closed - -write "HTTP/1.1 404 Not Found" "\r\n" - "Server: Zilla" "\r\n" - "Connection: close" "\r\n" - "\r\n" -write flush - -write close diff --git a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/AuthorizationIT.java b/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/AuthorizationIT.java deleted file mode 100644 index 7e5d71cef8..0000000000 --- a/incubator/exporter-stdout.spec/src/test/java/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/AuthorizationIT.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2021-2023 Aklivity Inc - * - * Licensed under the Aklivity Community License (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at - * - * https://www.aklivity.io/aklivity-community-license/ - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package io.aklivity.zilla.specs.binding.http.streams.network.rfc7230; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.junit.rules.RuleChain.outerRule; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.DisableOnDebug; -import org.junit.rules.TestRule; -import org.junit.rules.Timeout; -import org.kaazing.k3po.junit.annotation.Specification; -import org.kaazing.k3po.junit.rules.K3poRule; - -public class AuthorizationIT -{ - private final K3poRule k3po = new K3poRule() - .addScriptRoot("net", "io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization"); - - private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); - - @Rule - public final TestRule chain = outerRule(k3po).around(timeout); - - @Test - @Specification({ - "${net}/reject.credentials.header/client", - "${net}/reject.credentials.header/server", - }) - public void shouldRejectCredentialsHeader() throws Exception - { - k3po.finish(); - } -} diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/JwtEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/JwtEventsIT.java index da9ff69913..41fa36d119 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/JwtEventsIT.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/JwtEventsIT.java @@ -35,8 +35,8 @@ public class JwtEventsIT { private final K3poRule k3po = new K3poRule() - .addScriptRoot("net", "io/aklivity/zilla/specs/binding/override/http/streams/network/rfc7230/authorization") - .addScriptRoot("app", "io/aklivity/zilla/specs/binding/override/http/streams/application/rfc7230/authorization"); + .addScriptRoot("net", "io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization") + .addScriptRoot("app", "io/aklivity/zilla/specs/binding/http/streams/application/rfc7230/authorization"); private final TestRule timeout = new DisableOnDebug(new Timeout(10, SECONDS)); diff --git a/specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt b/specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt index 90377a5931..2369372d0d 100644 --- a/specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt +++ b/specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization/reject.credentials.header/client.rpt @@ -33,7 +33,7 @@ connected write "GET / HTTP/1.1" "\r\n" "Host: example.com:9090" "\r\n" - "Authorization: Bearer EXPIRED" "\r\n" + "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImV4YW1wbGUifQ.eyJhdWQiOiJodHRwczovL2FwaS5leGFtcGxlLmNvbSIsImV4cCI6MTcwODk0MDQ0MCwiaXNzIjoiaHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIiwic3ViIjoidXNlciJ9.KwZt_rDTDEOQ33URwZ8Gd1WqQjAIJESbt5Et309Yz7AJm1wWWyFhWm7AV6lt1rkX-eD-jVh0wHAsy7L4kdzBOErCdwFcdaB4u2jFDGn_9IK28lCedxIYmYtI4qn6eY916IIqRpwZcqzw08OEljfYUKo4UeX7JPAtha0GQmfZY1-NNcncg06xw3xkKSZ1SnIh9MZM1FNH_5QPZPL4NHP7DRXtaMn2w6YpO7n695Sc_3LuSDlfDDMVIUWuEreOzOXem6jheGIbJ-eDKhIXXPrOz1NBAJmvizbugMR7m_bodiEzzqt5ttKDs1974alrR_sYP8OYmR_rCqXc5N3lp_SW3A" "\r\n" "\r\n" write flush diff --git a/specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt b/specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt index 5761cef887..f091a35b5d 100644 --- a/specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt +++ b/specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/streams/network/rfc7230/authorization/reject.credentials.header/server.rpt @@ -32,7 +32,7 @@ connected read "GET / HTTP/1.1" "\r\n" "Host: example.com:9090" "\r\n" - "Authorization: Bearer EXPIRED" "\r\n" + "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImV4YW1wbGUifQ.eyJhdWQiOiJodHRwczovL2FwaS5leGFtcGxlLmNvbSIsImV4cCI6MTcwODk0MDQ0MCwiaXNzIjoiaHR0cHM6Ly9hdXRoLmV4YW1wbGUuY29tIiwic3ViIjoidXNlciJ9.KwZt_rDTDEOQ33URwZ8Gd1WqQjAIJESbt5Et309Yz7AJm1wWWyFhWm7AV6lt1rkX-eD-jVh0wHAsy7L4kdzBOErCdwFcdaB4u2jFDGn_9IK28lCedxIYmYtI4qn6eY916IIqRpwZcqzw08OEljfYUKo4UeX7JPAtha0GQmfZY1-NNcncg06xw3xkKSZ1SnIh9MZM1FNH_5QPZPL4NHP7DRXtaMn2w6YpO7n695Sc_3LuSDlfDDMVIUWuEreOzOXem6jheGIbJ-eDKhIXXPrOz1NBAJmvizbugMR7m_bodiEzzqt5ttKDs1974alrR_sYP8OYmR_rCqXc5N3lp_SW3A" "\r\n" "\r\n" read closed From b14955787b68f293522fb7e37d825c252bf65268 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 28 Feb 2024 09:43:23 +0100 Subject: [PATCH 166/167] fix --- .../config/{client.invalid.hostname.yaml => client.host.yaml} | 0 .../runtime/exporter/stdout/internal/events/TcpEventsIT.java | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/{client.invalid.hostname.yaml => client.host.yaml} (100%) diff --git a/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml b/incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.host.yaml similarity index 100% rename from incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.invalid.hostname.yaml rename to incubator/exporter-stdout.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/config/client.host.yaml diff --git a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java index 2f69533e36..989f89eb83 100644 --- a/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java +++ b/incubator/exporter-stdout/src/test/java/io/aklivity/zilla/runtime/exporter/stdout/internal/events/TcpEventsIT.java @@ -53,7 +53,7 @@ public class TcpEventsIT public final TestRule chain = outerRule(output).around(engine).around(k3po).around(timeout); @Test - @Configuration("client.invalid.hostname.yaml") + @Configuration("client.host.yaml") @Specification({ "${app}/connection.failed/client" }) From 3076f6f41e3498a12f143e57be6d988f569e33d3 Mon Sep 17 00:00:00 2001 From: Attila Kreiner Date: Wed, 28 Feb 2024 09:47:50 +0100 Subject: [PATCH 167/167] revert model-json chg --- .../model/json/internal/JsonValidatorHandler.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/incubator/model-json/src/main/java/io/aklivity/zilla/runtime/model/json/internal/JsonValidatorHandler.java b/incubator/model-json/src/main/java/io/aklivity/zilla/runtime/model/json/internal/JsonValidatorHandler.java index bd2e73dbc5..994601abc4 100644 --- a/incubator/model-json/src/main/java/io/aklivity/zilla/runtime/model/json/internal/JsonValidatorHandler.java +++ b/incubator/model-json/src/main/java/io/aklivity/zilla/runtime/model/json/internal/JsonValidatorHandler.java @@ -75,13 +75,10 @@ public boolean validate( : handler.resolve(subject, catalog.version); JsonProvider provider = supplyProvider(schemaId); - if (provider != null) + parser = provider.createParser(in); + while (parser.hasNext()) { - parser = provider.createParser(in); - while (parser.hasNext()) - { - parser.next(); - } + parser.next(); } } }