-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#7375] Add Channelz metric for grpc debug
- Loading branch information
Showing
24 changed files
with
566 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
grpc/src/test/java/com/navercorp/pinpoint/grpc/ManagedChannelUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.navercorp.pinpoint.grpc; | ||
|
||
import io.grpc.Channel; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ManagedChannelUtilsTest { | ||
@Test | ||
public void testGetLogId() { | ||
Channel channel = mock(Channel.class); | ||
when(channel.toString()).thenReturn("ManagedChannelOrphanWrapper{delegate=ManagedChannelImpl{logId=1, target=127.0.0.1:9993}}"); | ||
|
||
Assert.assertEquals(1, ManagedChannelUtils.getLogId(channel)); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
plugins-it/google-grpc-it/src/test/java/com/navercorp/pinpoint/plugin/grpc/BuilderUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.navercorp.pinpoint.plugin.grpc; | ||
|
||
import io.grpc.ManagedChannelBuilder; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
public class BuilderUtils { | ||
|
||
private interface Call<T> { | ||
void call(T target); | ||
} | ||
|
||
private static Call<ManagedChannelBuilder<?>> usePlaintext = getUsePlainText(); | ||
|
||
public static void usePlainText(ManagedChannelBuilder<?> builder) { | ||
usePlaintext.call(builder); | ||
} | ||
|
||
private static Call getUsePlainText() { | ||
final Class<ManagedChannelBuilder> builderClass = ManagedChannelBuilder.class; | ||
|
||
final Method oldUsePlaintext = getMethod(builderClass, "usePlaintext"); | ||
if (oldUsePlaintext != null) { | ||
return new Call<ManagedChannelBuilder<?>>() { | ||
@Override | ||
public void call(ManagedChannelBuilder<?> target) { | ||
try { | ||
oldUsePlaintext.invoke(target); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e.getMessage(), e); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
final Method newUsePlaintext = getMethod(builderClass, "usePlaintext", boolean.class); | ||
if (newUsePlaintext != null) { | ||
return new Call<ManagedChannelBuilder<?>>() { | ||
@Override | ||
public void call(ManagedChannelBuilder<?> target) { | ||
try { | ||
newUsePlaintext.invoke(target, true); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e.getMessage(), e); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
throw new UnsupportedOperationException("usePlaintext method not found"); | ||
} | ||
|
||
private static Method getMethod(Class<ManagedChannelBuilder> builderClass, String method, Class<?>... parameterTypes) { | ||
try { | ||
return builderClass.getMethod(method, parameterTypes); | ||
} catch (NoSuchMethodException e) { | ||
return null; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...-it/google-grpc-it/src/test/java/com/navercorp/pinpoint/plugin/grpc/BuilderUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.navercorp.pinpoint.plugin.grpc; | ||
|
||
import io.grpc.ManagedChannelBuilder; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
public class BuilderUtilsTest { | ||
@Test | ||
public void usePlainText() { | ||
ManagedChannelBuilder mock = mock(ManagedChannelBuilder.class); | ||
BuilderUtils.usePlainText(mock); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.