diff --git a/docs/root/intro/version_history.rst b/docs/root/intro/version_history.rst index 0547e8bc7b..bbfbe8a55d 100644 --- a/docs/root/intro/version_history.rst +++ b/docs/root/intro/version_history.rst @@ -7,6 +7,7 @@ Pending Release Bugfixes: Features: +- API: added Envoy's response flags to final stream intel (:issue:`#2009 <2009>`) 0.4.5 (January 13, 2022) ======================== diff --git a/library/common/extensions/filters/http/platform_bridge/filter.cc b/library/common/extensions/filters/http/platform_bridge/filter.cc index 24cc048b14..3a0742a26d 100644 --- a/library/common/extensions/filters/http/platform_bridge/filter.cc +++ b/library/common/extensions/filters/http/platform_bridge/filter.cc @@ -192,7 +192,8 @@ Http::LocalErrorStatus PlatformBridgeFilter::onLocalReply(const LocalReplyData& envoy_final_stream_intel PlatformBridgeFilter::finalStreamIntel() { RELEASE_ASSERT(decoder_callbacks_, "StreamInfo accessed before filter callbacks are set"); // FIXME: Stream handle cannot currently be set from the filter context. - envoy_final_stream_intel final_stream_intel{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0}; + envoy_final_stream_intel final_stream_intel{-1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 0, 0, 0, 0}; setFinalStreamIntel(decoder_callbacks_->streamInfo(), final_stream_intel); return final_stream_intel; } diff --git a/library/common/http/client.h b/library/common/http/client.h index b07ad397df..0246333a10 100644 --- a/library/common/http/client.h +++ b/library/common/http/client.h @@ -280,8 +280,8 @@ class Client : public Logger::Loggable { bool explicit_flow_control_ = false; // Latest intel data retrieved from the StreamInfo. envoy_stream_intel stream_intel_{-1, -1, 0}; - envoy_final_stream_intel envoy_final_stream_intel_{-1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 0, 0, 0}; + envoy_final_stream_intel envoy_final_stream_intel_{-1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 0, 0, 0, 0}; StreamInfo::BytesMeterSharedPtr bytes_meter_; }; diff --git a/library/common/jni/jni_utility.cc b/library/common/jni/jni_utility.cc index 7362673d59..1cd4eaba0c 100644 --- a/library/common/jni/jni_utility.cc +++ b/library/common/jni/jni_utility.cc @@ -99,7 +99,7 @@ jlongArray native_stream_intel_to_array(JNIEnv* env, envoy_stream_intel stream_i jlongArray native_final_stream_intel_to_array(JNIEnv* env, envoy_final_stream_intel final_stream_intel) { - jlongArray j_array = env->NewLongArray(14); + jlongArray j_array = env->NewLongArray(15); jlong* critical_array = static_cast(env->GetPrimitiveArrayCritical(j_array, nullptr)); RELEASE_ASSERT(critical_array != nullptr, "unable to allocate memory in jni_utility"); @@ -117,6 +117,7 @@ jlongArray native_final_stream_intel_to_array(JNIEnv* env, critical_array[11] = static_cast(final_stream_intel.socket_reused); critical_array[12] = static_cast(final_stream_intel.sent_byte_count); critical_array[13] = static_cast(final_stream_intel.received_byte_count); + critical_array[14] = static_cast(final_stream_intel.response_flags); // Here '0' (for which there is no named constant) indicates we want to commit the changes back // to the JVM and free the c array, where applicable. diff --git a/library/common/stream_info/extra_stream_info.cc b/library/common/stream_info/extra_stream_info.cc index 0bd2f05ec7..7404b47910 100644 --- a/library/common/stream_info/extra_stream_info.cc +++ b/library/common/stream_info/extra_stream_info.cc @@ -52,6 +52,7 @@ void setFinalStreamIntel(StreamInfo& stream_info, envoy_final_stream_intel& fina final_intel.sent_byte_count = stream_info.getUpstreamBytesMeter()->wireBytesSent(); final_intel.received_byte_count = stream_info.getUpstreamBytesMeter()->wireBytesReceived(); } + final_intel.response_flags = stream_info.responseFlags(); } } // namespace StreamInfo diff --git a/library/common/types/c_types.h b/library/common/types/c_types.h index 72fac8dbca..d664795885 100644 --- a/library/common/types/c_types.h +++ b/library/common/types/c_types.h @@ -193,6 +193,10 @@ typedef struct { uint64_t sent_byte_count; // The number of bytes received from upstream. uint64_t received_byte_count; + // The final response flags for the stream. See + // https://github.com/envoyproxy/envoy/blob/main/envoy/stream_info/stream_info.h + // for the ResponseFlag enum. + uint64_t response_flags; } envoy_final_stream_intel; #ifdef __cplusplus diff --git a/library/java/io/envoyproxy/envoymobile/engine/EnvoyFinalStreamIntelImpl.java b/library/java/io/envoyproxy/envoymobile/engine/EnvoyFinalStreamIntelImpl.java index 050cede043..f10f67a6ed 100644 --- a/library/java/io/envoyproxy/envoymobile/engine/EnvoyFinalStreamIntelImpl.java +++ b/library/java/io/envoyproxy/envoymobile/engine/EnvoyFinalStreamIntelImpl.java @@ -17,6 +17,7 @@ class EnvoyFinalStreamIntelImpl implements EnvoyFinalStreamIntel { private boolean socketReused; private long sentByteCount; private long receivedByteCount; + private long responseFlags; EnvoyFinalStreamIntelImpl(long[] values) { requestStartMs = values[0]; @@ -33,6 +34,7 @@ class EnvoyFinalStreamIntelImpl implements EnvoyFinalStreamIntel { socketReused = values[11] != 0; sentByteCount = values[12]; receivedByteCount = values[13]; + responseFlags = values[14]; } @Override @@ -91,4 +93,8 @@ public long getSentByteCount() { public long getReceivedByteCount() { return receivedByteCount; } + @Override + public long getResponseFlags() { + return responseFlags; + } } diff --git a/library/java/io/envoyproxy/envoymobile/engine/types/EnvoyFinalStreamIntel.java b/library/java/io/envoyproxy/envoymobile/engine/types/EnvoyFinalStreamIntel.java index 4936176a56..15c9f8795c 100644 --- a/library/java/io/envoyproxy/envoymobile/engine/types/EnvoyFinalStreamIntel.java +++ b/library/java/io/envoyproxy/envoymobile/engine/types/EnvoyFinalStreamIntel.java @@ -64,4 +64,10 @@ public interface EnvoyFinalStreamIntel { * The number of bytes received from upstream. */ public long getReceivedByteCount(); + /* + * The response flags for the stream. See + * https://github.com/envoyproxy/envoy/blob/main/envoy/stream_info/stream_info.h#L39 + * for values. + */ + public long getResponseFlags(); } diff --git a/library/kotlin/io/envoyproxy/envoymobile/FinalStreamIntel.kt b/library/kotlin/io/envoyproxy/envoymobile/FinalStreamIntel.kt index 9ceb9db423..deb9c7cffb 100644 --- a/library/kotlin/io/envoyproxy/envoymobile/FinalStreamIntel.kt +++ b/library/kotlin/io/envoyproxy/envoymobile/FinalStreamIntel.kt @@ -27,6 +27,7 @@ import io.envoyproxy.envoymobile.engine.types.EnvoyStreamIntel * @param socket_reused True if the upstream socket had been used previously. * @param sentByteCount The number of bytes sent upstream. * @param receivedByteCount The number of bytes received from upstream. + * @param responseFlags The response flags for the stream. */ @Suppress("LongParameterList") class FinalStreamIntel constructor( @@ -46,7 +47,8 @@ class FinalStreamIntel constructor( val requestEndMs: Long, val socketReused: Boolean, val sentByteCount: Long, - val receivedByteCount: Long + val receivedByteCount: Long, + val responseFlags: Long ) : StreamIntel(streamId, connectionId, attemptCount) { constructor(superBase: EnvoyStreamIntel, base: EnvoyFinalStreamIntel) : this( superBase.streamId, superBase.connectionId, superBase.attemptCount, @@ -57,6 +59,6 @@ class FinalStreamIntel constructor( base.sendingEndMs, base.responseStartMs, base.requestEndMs, base.socketReused, base.sentByteCount, - base.receivedByteCount + base.receivedByteCount, base.responseFlags ) } diff --git a/library/kotlin/io/envoyproxy/envoymobile/mocks/MockStream.kt b/library/kotlin/io/envoyproxy/envoymobile/mocks/MockStream.kt index 7f326d22ab..67cf7990bb 100644 --- a/library/kotlin/io/envoyproxy/envoymobile/mocks/MockStream.kt +++ b/library/kotlin/io/envoyproxy/envoymobile/mocks/MockStream.kt @@ -32,6 +32,7 @@ class MockStream internal constructor(underlyingStream: MockEnvoyHTTPStream) : S override fun getSocketReused(): Boolean { return false } override fun getSentByteCount(): Long { return 0 } override fun getReceivedByteCount(): Long { return 0 } + override fun getResponseFlags(): Long { return 0 } } /** * Closure that will be called when request headers are sent. diff --git a/library/swift/FinalStreamIntel.swift b/library/swift/FinalStreamIntel.swift index 970a919e28..bcf3fdf354 100644 --- a/library/swift/FinalStreamIntel.swift +++ b/library/swift/FinalStreamIntel.swift @@ -33,6 +33,8 @@ public final class FinalStreamIntel: StreamIntel { public let sentByteCount: UInt64 /// The number of bytes received from upstream. public let receivedByteCount: UInt64 + /// The response flags for the upstream stream. + public let responseFlags: UInt64 // NOTE(1): These fields may not be set if socket_reused is false. @@ -53,7 +55,8 @@ public final class FinalStreamIntel: StreamIntel { requestEndMs: Int64, socketReused: Bool, sentByteCount: UInt64, - receivedByteCount: UInt64 + receivedByteCount: UInt64, + responseFlags: UInt64 ) { self.requestStartMs = requestStartMs self.dnsStartMs = dnsStartMs @@ -69,6 +72,7 @@ public final class FinalStreamIntel: StreamIntel { self.socketReused = socketReused self.sentByteCount = sentByteCount self.receivedByteCount = receivedByteCount + self.responseFlags = responseFlags super.init(streamId: streamId, connectionId: connectionId, attemptCount: attemptCount) } } @@ -92,7 +96,8 @@ extension FinalStreamIntel { requestEndMs: cFinalIntel.request_end_ms, socketReused: cFinalIntel.socket_reused != 0, sentByteCount: cFinalIntel.sent_byte_count, - receivedByteCount: cFinalIntel.received_byte_count + receivedByteCount: cFinalIntel.received_byte_count, + responseFlags: cFinalIntel.response_flags ) } }