Skip to content

Commit 5e2fc7a

Browse files
committed
Merge branch 'master' of https://github.com/grpc/grpc-java into trace-new-line
2 parents 9d262a8 + 11a1f9e commit 5e2fc7a

File tree

16 files changed

+199
-525
lines changed

16 files changed

+199
-525
lines changed

alts/src/main/java/io/grpc/alts/internal/AltsProtocolNegotiator.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@
5454
// TODO(carl-mastrangelo): rename this AltsProtocolNegotiators.
5555
public final class AltsProtocolNegotiator {
5656
private static final Logger logger = Logger.getLogger(AltsProtocolNegotiator.class.getName());
57-
// Avoid performing too many handshakes in parallel, as it may cause queuing in the handshake
58-
// server and cause unbounded blocking on the event loop (b/168808426). This is a workaround until
59-
// there is an async TSI handshaking API to avoid the blocking.
60-
private static final AsyncSemaphore handshakeSemaphore = new AsyncSemaphore(32);
57+
58+
static final String ALTS_MAX_CONCURRENT_HANDSHAKES_ENV_VARIABLE =
59+
"GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES";
60+
@VisibleForTesting static final int DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES = 32;
61+
private static final AsyncSemaphore handshakeSemaphore =
62+
new AsyncSemaphore(getAltsMaxConcurrentHandshakes());
6163

6264
@Grpc.TransportAttr
6365
public static final Attributes.Key<TsiPeer> TSI_PEER_KEY =
@@ -424,5 +426,30 @@ public SecurityDetails validatePeerObject(Object peerObject) throws GeneralSecur
424426
}
425427
}
426428

429+
@VisibleForTesting
430+
static int getAltsMaxConcurrentHandshakes(String altsMaxConcurrentHandshakes) {
431+
if (altsMaxConcurrentHandshakes == null) {
432+
return DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES;
433+
}
434+
try {
435+
int effectiveMaxConcurrentHandshakes = Integer.parseInt(altsMaxConcurrentHandshakes);
436+
if (effectiveMaxConcurrentHandshakes < 0) {
437+
logger.warning(
438+
"GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES environment variable set to invalid value.");
439+
return DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES;
440+
}
441+
return effectiveMaxConcurrentHandshakes;
442+
} catch (NumberFormatException e) {
443+
logger.warning(
444+
"GRPC_ALTS_MAX_CONCURRENT_HANDSHAKES environment variable set to invalid value.");
445+
return DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES;
446+
}
447+
}
448+
449+
private static int getAltsMaxConcurrentHandshakes() {
450+
return getAltsMaxConcurrentHandshakes(
451+
System.getenv(ALTS_MAX_CONCURRENT_HANDSHAKES_ENV_VARIABLE));
452+
}
453+
427454
private AltsProtocolNegotiator() {}
428455
}

alts/src/test/java/io/grpc/alts/internal/AltsProtocolNegotiatorTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,29 @@ public void peerPropagated() throws Exception {
354354
.isEqualTo(SecurityLevel.PRIVACY_AND_INTEGRITY);
355355
}
356356

357+
@Test
358+
public void getAltsMaxConcurrentHandshakes_success() throws Exception {
359+
assertThat(AltsProtocolNegotiator.getAltsMaxConcurrentHandshakes("10")).isEqualTo(10);
360+
}
361+
362+
@Test
363+
public void getAltsMaxConcurrentHandshakes_envVariableNotSet() throws Exception {
364+
assertThat(AltsProtocolNegotiator.getAltsMaxConcurrentHandshakes(null))
365+
.isEqualTo(AltsProtocolNegotiator.DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES);
366+
}
367+
368+
@Test
369+
public void getAltsMaxConcurrentHandshakes_envVariableNotANumber() throws Exception {
370+
assertThat(AltsProtocolNegotiator.getAltsMaxConcurrentHandshakes("not-a-number"))
371+
.isEqualTo(AltsProtocolNegotiator.DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES);
372+
}
373+
374+
@Test
375+
public void getAltsMaxConcurrentHandshakes_envVariableNegative() throws Exception {
376+
assertThat(AltsProtocolNegotiator.getAltsMaxConcurrentHandshakes("-10"))
377+
.isEqualTo(AltsProtocolNegotiator.DEFAULT_ALTS_MAX_CONCURRENT_HANDSHAKES);
378+
}
379+
357380
private void doHandshake() throws Exception {
358381
// Capture the client frame and add to the server.
359382
assertEquals(1, channel.outboundMessages().size());

gcp-observability/src/main/java/io/grpc/gcp/observability/GcpObservability.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.annotations.VisibleForTesting;
2222
import com.google.common.collect.ImmutableSet;
2323
import io.grpc.ClientInterceptor;
24-
import io.grpc.ExperimentalApi;
2524
import io.grpc.InternalGlobalInterceptors;
2625
import io.grpc.ManagedChannelProvider.ProviderNotFoundException;
2726
import io.grpc.ServerInterceptor;
@@ -64,7 +63,6 @@
6463
import java.util.stream.Collectors;
6564

6665
/** The main class for gRPC Google Cloud Platform Observability features. */
67-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/8869")
6866
public final class GcpObservability implements AutoCloseable {
6967

7068
private static final Logger logger = Logger.getLogger(GcpObservability.class.getName());
@@ -90,12 +88,10 @@ public final class GcpObservability implements AutoCloseable {
9088
*/
9189
public static synchronized GcpObservability grpcInit() throws IOException {
9290
if (instance == null) {
93-
GlobalLocationTags globalLocationTags = new GlobalLocationTags();
9491
ObservabilityConfigImpl observabilityConfig = ObservabilityConfigImpl.getInstance();
9592
TraceLoggingHelper traceLoggingHelper = new TraceLoggingHelper(
9693
observabilityConfig.getProjectId());
97-
Sink sink = new GcpLogSink(observabilityConfig.getProjectId(),
98-
globalLocationTags.getLocationTags(), observabilityConfig,
94+
Sink sink = new GcpLogSink(observabilityConfig.getProjectId(), observabilityConfig,
9995
SERVICES_TO_EXCLUDE, traceLoggingHelper);
10096
LogHelper helper = new LogHelper(sink);
10197
ConfigFilterHelper configFilterHelper = ConfigFilterHelper.getInstance(observabilityConfig);

gcp-observability/src/main/java/io/grpc/gcp/observability/GlobalLocationTags.java

Lines changed: 0 additions & 148 deletions
This file was deleted.

gcp-observability/src/main/java/io/grpc/gcp/observability/MetadataConfig.java

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)