Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

final_intel: adding response flags #2009

Merged
merged 3 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
========================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions library/common/http/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ class Client : public Logger::Loggable<Logger::Id::http> {
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_;
};

Expand Down
3 changes: 2 additions & 1 deletion library/common/jni/jni_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<jlong*>(env->GetPrimitiveArrayCritical(j_array, nullptr));
RELEASE_ASSERT(critical_array != nullptr, "unable to allocate memory in jni_utility");

Expand All @@ -117,6 +117,7 @@ jlongArray native_final_stream_intel_to_array(JNIEnv* env,
critical_array[11] = static_cast<jlong>(final_stream_intel.socket_reused);
critical_array[12] = static_cast<jlong>(final_stream_intel.sent_byte_count);
critical_array[13] = static_cast<jlong>(final_stream_intel.received_byte_count);
critical_array[14] = static_cast<jlong>(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.
Expand Down
1 change: 1 addition & 0 deletions library/common/stream_info/extra_stream_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions library/common/types/c_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -33,6 +34,7 @@ class EnvoyFinalStreamIntelImpl implements EnvoyFinalStreamIntel {
socketReused = values[11] != 0;
sentByteCount = values[12];
receivedByteCount = values[13];
responseFlags = values[14];
}

@Override
Expand Down Expand Up @@ -91,4 +93,8 @@ public long getSentByteCount() {
public long getReceivedByteCount() {
return receivedByteCount;
}
@Override
public long getResponseFlags() {
return responseFlags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
6 changes: 4 additions & 2 deletions library/kotlin/io/envoyproxy/envoymobile/FinalStreamIntel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -57,6 +59,6 @@ class FinalStreamIntel constructor(
base.sendingEndMs,
base.responseStartMs, base.requestEndMs,
base.socketReused, base.sentByteCount,
base.receivedByteCount
base.receivedByteCount, base.responseFlags
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions library/swift/FinalStreamIntel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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)
}
}
Expand All @@ -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
)
}
}