diff options
| author | Bogdan Drutu <bdrutu@google.com> | 2017-11-03 09:25:12 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-03 09:25:12 +1100 |
| commit | 6cb4dd2cc949a2602783321da179cb11afb7fc7a (patch) | |
| tree | a9d81d79091ae9b6e9d8f4bae236625daefd7fe2 /contrib | |
| parent | 078349906aa2a6041ab5799f23e30ab0a6a99c07 (diff) | |
| download | platform_external_opencensus-java-6cb4dd2cc949a2602783321da179cb11afb7fc7a.tar.gz platform_external_opencensus-java-6cb4dd2cc949a2602783321da179cb11afb7fc7a.tar.bz2 platform_external_opencensus-java-6cb4dd2cc949a2602783321da179cb11afb7fc7a.zip | |
Add gradle plugin for google java format. Enforce all files to be formatted. (#771)
* Add gradle plugin for google java format. Enforce all files to be formatted.
* Fix javadoc comments.
* update to google-java-formatter 1.5
* Fix comments and run formatter only for java8.
* Formatter works only on java8.
Diffstat (limited to 'contrib')
20 files changed, 199 insertions, 243 deletions
diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentBuilderListener.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentBuilderListener.java index 548b14fc..54a82442 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentBuilderListener.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentBuilderListener.java @@ -33,44 +33,36 @@ final class AgentBuilderListener implements AgentBuilder.Listener { @Override public void onTransformation( - TypeDescription typeDescription, - ClassLoader classLoader, - JavaModule module, - boolean loaded, - DynamicType dynamicType) { + TypeDescription typeDescription, + ClassLoader classLoader, + JavaModule module, + boolean loaded, + DynamicType dynamicType) { logger.log(Level.FINE, "{0}", typeDescription); } @Override public void onIgnored( - TypeDescription typeDescription, - ClassLoader classLoader, - JavaModule module, - boolean loaded) { - } + TypeDescription typeDescription, + ClassLoader classLoader, + JavaModule module, + boolean loaded) {} @Override public void onError( - String typeName, - ClassLoader classLoader, - JavaModule module, - boolean loaded, - Throwable throwable) { + String typeName, + ClassLoader classLoader, + JavaModule module, + boolean loaded, + Throwable throwable) { logger.log(Level.WARNING, "Failed to handle " + typeName, throwable); } @Override public void onComplete( - String typeName, - ClassLoader classLoader, - JavaModule module, - boolean loaded) { - } + String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {} @Override - public void onDiscovery(String typeName, - ClassLoader classLoader, - JavaModule module, - boolean loaded) { - } + public void onDiscovery( + String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {} } diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentMain.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentMain.java index 5e1e7482..020987b4 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentMain.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentMain.java @@ -30,34 +30,33 @@ import java.util.logging.Logger; import net.bytebuddy.agent.builder.AgentBuilder; /** - * The <b>OpenCensus Agent for Java</b> collects and sends latency data about your Java - * process to OpenCensus backends such as Stackdriver Trace for analysis and visualization. + * The <b>OpenCensus Agent for Java</b> collects and sends latency data about your Java process to + * OpenCensus backends such as Stackdriver Trace for analysis and visualization. * - * <p>To enable the *OpenCensus Agent for Java* for your application, add the option - * <code>-javaagent:path/to/opencensus-contrib-agent.jar</code> to the invocation of the - * <code>java</code> executable as shown in the following example: + * <p>To enable the *OpenCensus Agent for Java* for your application, add the option <code> + * -javaagent:path/to/opencensus-contrib-agent.jar</code> to the invocation of the <code>java</code> + * executable as shown in the following example: * * <pre> * java -javaagent:path/to/opencensus-contrib-agent.jar ... * </pre> * - * @see <a href="https://github.com/census-instrumentation/instrumentation-java/tree/master/agent">https://github.com/census-instrumentation/instrumentation-java/tree/master/agent</a> + * @see <a + * href="https://github.com/census-instrumentation/instrumentation-java/tree/master/agent">https://github.com/census-instrumentation/instrumentation-java/tree/master/agent</a> */ public final class AgentMain { private static final Logger logger = Logger.getLogger(AgentMain.class.getName()); - private AgentMain() { - } + private AgentMain() {} /** * Initializes the OpenCensus Agent for Java. * * @param agentArgs agent options, passed as a single string by the JVM - * @param instrumentation the {@link Instrumentation} object provided by the JVM for - * instrumenting Java programming language code + * @param instrumentation the {@link Instrumentation} object provided by the JVM for instrumenting + * Java programming language code * @throws Exception if initialization of the agent fails - * * @see java.lang.instrument */ public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception { @@ -69,12 +68,13 @@ public final class AgentMain { // from classes loaded by the bootstrap classloader. Thus, these classes have to be loaded by // the bootstrap classloader, too. instrumentation.appendToBootstrapClassLoaderSearch( - new JarFile(Resources.getResourceAsTempFile("bootstrap.jar"))); + new JarFile(Resources.getResourceAsTempFile("bootstrap.jar"))); checkLoadedByBootstrapClassloader(ContextTrampoline.class); checkLoadedByBootstrapClassloader(ContextStrategy.class); - AgentBuilder agentBuilder = new AgentBuilder.Default() + AgentBuilder agentBuilder = + new AgentBuilder.Default() .disableClassFormatChanges() .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION) .with(new AgentBuilderListener()) @@ -88,8 +88,7 @@ public final class AgentMain { } private static void checkLoadedByBootstrapClassloader(Class<?> clazz) { - checkState(clazz.getClassLoader() == null, - "%s must be loaded by the bootstrap classloader", - clazz); + checkState( + clazz.getClassLoader() == null, "%s must be loaded by the bootstrap classloader", clazz); } } diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/Resources.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/Resources.java index 31170923..33b71feb 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/Resources.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/Resources.java @@ -28,9 +28,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -/** - * Helper methods for working with resources. - */ +/** Helper methods for working with resources. */ final class Resources { /** @@ -53,7 +51,7 @@ final class Resources { @VisibleForTesting static void getResourceAsTempFile(String resourceName, File file, OutputStream outputStream) - throws IOException { + throws IOException { file.deleteOnExit(); InputStream is = getResourceAsStream(resourceName); @@ -68,7 +66,7 @@ final class Resources { InputStream is = Resources.class.getResourceAsStream(resourceName); if (is == null) { throw new FileNotFoundException( - "Cannot find resource '" + resourceName + "' on the class path."); + "Cannot find resource '" + resourceName + "' on the class path."); } return is; } diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextStrategy.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextStrategy.java index 6f3b97aa..a51a9bfd 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextStrategy.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextStrategy.java @@ -16,9 +16,7 @@ package io.opencensus.contrib.agent.bootstrap; -/** - * Strategy interface for accessing and manipulating the context. - */ +/** Strategy interface for accessing and manipulating the context. */ public interface ContextStrategy { /** diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextTrampoline.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextTrampoline.java index f1efad35..dd250790 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextTrampoline.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextTrampoline.java @@ -24,9 +24,9 @@ package io.opencensus.contrib.agent.bootstrap; * context by accessing and manipulating the context through the {@link ContextStrategy} interface. * * <p>Both {@link ContextTrampoline} and {@link ContextStrategy} are loaded by the bootstrap - * classloader so that they can be used from classes loaded by the bootstrap classloader. - * A concrete implementation of {@link ContextStrategy} will be loaded by the system classloader. - * This allows for using the same context implementation as the instrumented application. + * classloader so that they can be used from classes loaded by the bootstrap classloader. A concrete + * implementation of {@link ContextStrategy} will be loaded by the system classloader. This allows + * for using the same context implementation as the instrumented application. * * <p>{@code ContextTrampoline} is implemented as a static class to allow for easy and fast use from * instrumented bytecode. We cannot use dependency injection for the instrumented bytecode. @@ -38,8 +38,7 @@ public final class ContextTrampoline { // other method of this class is called. private static ContextStrategy contextStrategy; - private ContextTrampoline() { - } + private ContextTrampoline() {} /** * Sets the concrete strategy for accessing and manipulating the context. @@ -67,7 +66,6 @@ public final class ContextTrampoline { * * @param runnable a {@link Runnable} object * @return the wrapped {@link Runnable} object - * * @see ContextStrategy#wrapInCurrentContext */ public static Runnable wrapInCurrentContext(Runnable runnable) { diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/deps/package-info.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/deps/package-info.java index 25de9eb0..71e81270 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/deps/package-info.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/deps/package-info.java @@ -18,6 +18,6 @@ package io.opencensus.contrib.agent.deps; /** * Contains third party packages, such as Byte Buddy, Guava, etc., relocated here by the build - * process to avoid any conflicts of the agent's classes with the app's classes, which are loaded - * by the same classloader (the system classloader). + * process to avoid any conflicts of the agent's classes with the app's classes, which are loaded by + * the same classloader (the system classloader). */ diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextStrategyImpl.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextStrategyImpl.java index 37fb9e0f..e99fbd3b 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextStrategyImpl.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextStrategyImpl.java @@ -23,8 +23,8 @@ import io.opencensus.contrib.agent.bootstrap.ContextStrategy; import java.lang.ref.WeakReference; /** - * Implementation of {@link ContextStrategy} for accessing and manipulating the - * {@link io.grpc.Context}. + * Implementation of {@link ContextStrategy} for accessing and manipulating the {@link + * io.grpc.Context}. */ final class ContextStrategyImpl implements ContextStrategy { @@ -49,8 +49,7 @@ final class ContextStrategyImpl implements ContextStrategy { * <p>NB: Using thread IDs as keys was considered: It's unclear how to safely detect and cleanup * otherwise unreferenced threads IDs from the map. */ - private final Cache<Thread, Context> savedContexts - = CacheBuilder.newBuilder().weakKeys().build(); + private final Cache<Thread, Context> savedContexts = CacheBuilder.newBuilder().weakKeys().build(); @Override public Runnable wrapInCurrentContext(Runnable runnable) { diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextTrampolineInitializer.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextTrampolineInitializer.java index 964ef053..1ed18857 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextTrampolineInitializer.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextTrampolineInitializer.java @@ -21,9 +21,7 @@ import io.opencensus.contrib.agent.bootstrap.ContextStrategy; import io.opencensus.contrib.agent.bootstrap.ContextTrampoline; import net.bytebuddy.agent.builder.AgentBuilder; -/** - * Initializes the {@link ContextTrampoline} with a concrete {@link ContextStrategy}. - */ +/** Initializes the {@link ContextTrampoline} with a concrete {@link ContextStrategy}. */ @AutoService(Instrumenter.class) public final class ContextTrampolineInitializer implements Instrumenter { diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ExecutorInstrumentation.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ExecutorInstrumentation.java index 3859744f..669c0627 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ExecutorInstrumentation.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ExecutorInstrumentation.java @@ -36,8 +36,8 @@ import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.utility.JavaModule; /** - * Propagates the context of the caller of {@link Executor#execute} to the submitted - * {@link Runnable}, just like the Microsoft .Net Framework propagates the <a + * Propagates the context of the caller of {@link Executor#execute} to the submitted {@link + * Runnable}, just like the Microsoft .Net Framework propagates the <a * href="https://msdn.microsoft.com/en-us/library/system.threading.executioncontext(v=vs.110).aspx">System.Threading.ExecutionContext</a>. */ @AutoService(Instrumenter.class) @@ -47,16 +47,17 @@ public final class ExecutorInstrumentation implements Instrumenter { public AgentBuilder instrument(AgentBuilder agentBuilder) { checkNotNull(agentBuilder, "agentBuilder"); - return agentBuilder - .type(createMatcher()) - .transform(new Transformer()); + return agentBuilder.type(createMatcher()).transform(new Transformer()); } private static class Transformer implements AgentBuilder.Transformer { @Override - public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, - TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) { + public DynamicType.Builder<?> transform( + DynamicType.Builder<?> builder, + TypeDescription typeDescription, + ClassLoader classLoader, + JavaModule module) { return builder.visit(Advice.to(Execute.class).on(named("execute"))); } } @@ -69,9 +70,12 @@ public final class ExecutorInstrumentation implements Instrumenter { // turned into a no-op to avoid another unneeded context propagation. Likewise, when using // FixedContextExecutor, the automatic context propagation added by the agent is unneeded. return isSubTypeOf(Executor.class) - .and(not(isAbstract())) - .and(not(nameStartsWith("io.grpc.Context$") - .and(nameEndsWith("CurrentContextExecutor") + .and(not(isAbstract())) + .and( + not( + nameStartsWith("io.grpc.Context$") + .and( + nameEndsWith("CurrentContextExecutor") .or(nameEndsWith("FixedContextExecutor"))))); } @@ -88,7 +92,7 @@ public final class ExecutorInstrumentation implements Instrumenter { */ @Advice.OnMethodEnter @SuppressWarnings(value = "UnusedAssignment") - @SuppressFBWarnings(value = {"DLS_DEAD_LOCAL_STORE", "UPM_UNCALLED_PRIVATE_METHOD",}) + @SuppressFBWarnings(value = {"DLS_DEAD_LOCAL_STORE", "UPM_UNCALLED_PRIVATE_METHOD"}) private static void enter(@Advice.Argument(value = 0, readOnly = false) Runnable runnable) { runnable = ContextTrampoline.wrapInCurrentContext(runnable); } diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/Instrumenter.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/Instrumenter.java index a485177d..9168eef6 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/Instrumenter.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/Instrumenter.java @@ -18,16 +18,14 @@ package io.opencensus.contrib.agent.instrumentation; import net.bytebuddy.agent.builder.AgentBuilder; -/** - * Interface for plug-ins that add bytecode instrumentation. - */ +/** Interface for plug-ins that add bytecode instrumentation. */ public interface Instrumenter { /** * Adds bytecode instrumentation to the given {@link AgentBuilder}. * * @param agentBuilder an {@link AgentBuilder} object to which the additional instrumentation is - * added + * added * @return an {@link AgentBuilder} object having the additional instrumentation */ AgentBuilder instrument(AgentBuilder agentBuilder); diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ThreadInstrumentation.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ThreadInstrumentation.java index cb185445..a1b6e17e 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ThreadInstrumentation.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ThreadInstrumentation.java @@ -45,19 +45,20 @@ public final class ThreadInstrumentation implements Instrumenter { public AgentBuilder instrument(AgentBuilder agentBuilder) { checkNotNull(agentBuilder, "agentBuilder"); - return agentBuilder - .type(isSubTypeOf(Thread.class)) - .transform(new Transformer()); + return agentBuilder.type(isSubTypeOf(Thread.class)).transform(new Transformer()); } private static class Transformer implements AgentBuilder.Transformer { @Override - public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, - TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) { + public DynamicType.Builder<?> transform( + DynamicType.Builder<?> builder, + TypeDescription typeDescription, + ClassLoader classLoader, + JavaModule module) { return builder - .visit(Advice.to(Start.class).on(named("start"))) - .visit(Advice.to(Run.class).on(named("run"))); + .visit(Advice.to(Start.class).on(named("start"))) + .visit(Advice.to(Run.class).on(named("run"))); } } diff --git a/contrib/agent/src/test/java/io/opencensus/contrib/agent/ResourcesTest.java b/contrib/agent/src/test/java/io/opencensus/contrib/agent/ResourcesTest.java index 8a765556..4de58884 100644 --- a/contrib/agent/src/test/java/io/opencensus/contrib/agent/ResourcesTest.java +++ b/contrib/agent/src/test/java/io/opencensus/contrib/agent/ResourcesTest.java @@ -32,17 +32,13 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -/** - * Unit tests for {@link Resources}. - */ +/** Unit tests for {@link Resources}. */ @RunWith(MockitoJUnitRunner.class) public class ResourcesTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Mock - private File mockFile; + @Rule public final ExpectedException exception = ExpectedException.none(); + + @Mock private File mockFile; @Test public void getResourceAsTempFile_deleteOnExit() throws IOException { @@ -56,7 +52,7 @@ public class ResourcesTest { File file = Resources.getResourceAsTempFile("some_resource.txt"); assertThat(new String(java.nio.file.Files.readAllBytes(file.toPath()), Charsets.UTF_8)) - .isEqualTo("A resource!"); + .isEqualTo("A resource!"); } @Test @@ -75,12 +71,13 @@ public class ResourcesTest { @Test public void getResourceAsTempFile_WriteFailure() throws IOException { - OutputStream badOutputStream = new OutputStream() { - @Override - public void write(int b) throws IOException { - throw new IOException("denied"); - } - }; + OutputStream badOutputStream = + new OutputStream() { + @Override + public void write(int b) throws IOException { + throw new IOException("denied"); + } + }; exception.expect(IOException.class); exception.expectMessage("denied"); diff --git a/contrib/agent/src/test/java/io/opencensus/contrib/agent/bootstrap/ContextTrampolineTest.java b/contrib/agent/src/test/java/io/opencensus/contrib/agent/bootstrap/ContextTrampolineTest.java index bccdec92..f693dc3b 100644 --- a/contrib/agent/src/test/java/io/opencensus/contrib/agent/bootstrap/ContextTrampolineTest.java +++ b/contrib/agent/src/test/java/io/opencensus/contrib/agent/bootstrap/ContextTrampolineTest.java @@ -26,9 +26,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -/** - * Unit tests for {@link ContextTrampoline}. - */ +/** Unit tests for {@link ContextTrampoline}. */ @RunWith(MockitoJUnitRunner.class) public class ContextTrampolineTest { @@ -39,14 +37,11 @@ public class ContextTrampolineTest { ContextTrampoline.setContextStrategy(mockContextStrategy); } - @Rule - public final ExpectedException exception = ExpectedException.none(); + @Rule public final ExpectedException exception = ExpectedException.none(); - @Mock - private Runnable runnable; + @Mock private Runnable runnable; - @Mock - private Thread thread; + @Mock private Thread thread; @Test public void setContextStrategy_already_initialized() { diff --git a/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java b/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java index 36e981e0..531b6e11 100644 --- a/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java +++ b/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java @@ -21,9 +21,7 @@ import io.opencensus.stats.Measure.MeasureDouble; import io.opencensus.stats.Measure.MeasureLong; import io.opencensus.tags.TagKey; -/** - * Constants for collecting rpc stats. - */ +/** Constants for collecting rpc stats. */ public final class RpcMeasureConstants { // Rpc tag keys. @@ -37,118 +35,67 @@ public final class RpcMeasureConstants { // RPC client Measures. public static final MeasureLong RPC_CLIENT_ERROR_COUNT = - Measure.MeasureLong.create( - "grpc.io/client/error_count", - "RPC Errors", - COUNT); + Measure.MeasureLong.create("grpc.io/client/error_count", "RPC Errors", COUNT); public static final MeasureDouble RPC_CLIENT_REQUEST_BYTES = - Measure.MeasureDouble.create( - "grpc.io/client/request_bytes", - "Request bytes", - BYTE); + Measure.MeasureDouble.create("grpc.io/client/request_bytes", "Request bytes", BYTE); public static final MeasureDouble RPC_CLIENT_RESPONSE_BYTES = - Measure.MeasureDouble.create( - "grpc.io/client/response_bytes", - "Response bytes", - BYTE); + Measure.MeasureDouble.create("grpc.io/client/response_bytes", "Response bytes", BYTE); public static final MeasureDouble RPC_CLIENT_ROUNDTRIP_LATENCY = Measure.MeasureDouble.create( - "grpc.io/client/roundtrip_latency", - "RPC roundtrip latency msec", - MILLISECOND); + "grpc.io/client/roundtrip_latency", "RPC roundtrip latency msec", MILLISECOND); public static final MeasureDouble RPC_CLIENT_SERVER_ELAPSED_TIME = Measure.MeasureDouble.create( - "grpc.io/client/server_elapsed_time", - "Server elapsed time in msecs", - MILLISECOND); + "grpc.io/client/server_elapsed_time", "Server elapsed time in msecs", MILLISECOND); public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES = Measure.MeasureDouble.create( - "grpc.io/client/uncompressed_request_bytes", - "Uncompressed Request bytes", - BYTE); + "grpc.io/client/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE); public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES = Measure.MeasureDouble.create( - "grpc.io/client/uncompressed_response_bytes", - "Uncompressed Response bytes", - BYTE); + "grpc.io/client/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE); public static final MeasureLong RPC_CLIENT_STARTED_COUNT = Measure.MeasureLong.create( - "grpc.io/client/started_count", - "Number of client RPCs (streams) started", - COUNT); + "grpc.io/client/started_count", "Number of client RPCs (streams) started", COUNT); public static final MeasureLong RPC_CLIENT_FINISHED_COUNT = Measure.MeasureLong.create( - "grpc.io/client/finished_count", - "Number of client RPCs (streams) finished", - COUNT); + "grpc.io/client/finished_count", "Number of client RPCs (streams) finished", COUNT); public static final MeasureLong RPC_CLIENT_REQUEST_COUNT = Measure.MeasureLong.create( - "grpc.io/client/request_count", - "Number of client RPC request messages", - COUNT); + "grpc.io/client/request_count", "Number of client RPC request messages", COUNT); public static final MeasureLong RPC_CLIENT_RESPONSE_COUNT = Measure.MeasureLong.create( - "grpc.io/client/response_count", - "Number of client RPC response messages", - COUNT); - + "grpc.io/client/response_count", "Number of client RPC response messages", COUNT); // RPC server Measures. public static final MeasureLong RPC_SERVER_ERROR_COUNT = - Measure.MeasureLong.create( - "grpc.io/server/error_count", - "RPC Errors", - COUNT); + Measure.MeasureLong.create("grpc.io/server/error_count", "RPC Errors", COUNT); public static final MeasureDouble RPC_SERVER_REQUEST_BYTES = - Measure.MeasureDouble.create( - "grpc.io/server/request_bytes", - "Request bytes", - BYTE); + Measure.MeasureDouble.create("grpc.io/server/request_bytes", "Request bytes", BYTE); public static final MeasureDouble RPC_SERVER_RESPONSE_BYTES = - Measure.MeasureDouble.create( - "grpc.io/server/response_bytes", - "Response bytes", - BYTE); + Measure.MeasureDouble.create("grpc.io/server/response_bytes", "Response bytes", BYTE); public static final MeasureDouble RPC_SERVER_SERVER_ELAPSED_TIME = Measure.MeasureDouble.create( - "grpc.io/server/server_elapsed_time", - "Server elapsed time in msecs", - MILLISECOND); + "grpc.io/server/server_elapsed_time", "Server elapsed time in msecs", MILLISECOND); public static final MeasureDouble RPC_SERVER_SERVER_LATENCY = Measure.MeasureDouble.create( - "grpc.io/server/server_latency", - "Latency in msecs", - MILLISECOND); + "grpc.io/server/server_latency", "Latency in msecs", MILLISECOND); public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES = Measure.MeasureDouble.create( - "grpc.io/server/uncompressed_request_bytes", - "Uncompressed Request bytes", - BYTE); + "grpc.io/server/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE); public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES = Measure.MeasureDouble.create( - "grpc.io/server/uncompressed_response_bytes", - "Uncompressed Response bytes", - BYTE); + "grpc.io/server/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE); public static final MeasureLong RPC_SERVER_STARTED_COUNT = Measure.MeasureLong.create( - "grpc.io/server/started_count", - "Number of server RPCs (streams) started", - COUNT); + "grpc.io/server/started_count", "Number of server RPCs (streams) started", COUNT); public static final MeasureLong RPC_SERVER_FINISHED_COUNT = Measure.MeasureLong.create( - "grpc.io/server/finished_count", - "Number of server RPCs (streams) finished", - COUNT); + "grpc.io/server/finished_count", "Number of server RPCs (streams) finished", COUNT); public static final MeasureLong RPC_SERVER_REQUEST_COUNT = Measure.MeasureLong.create( - "grpc.io/server/request_count", - "Number of server RPC request messages", - COUNT); + "grpc.io/server/request_count", "Number of server RPC request messages", COUNT); public static final MeasureLong RPC_SERVER_RESPONSE_COUNT = Measure.MeasureLong.create( - "grpc.io/server/response_count", - "Number of server RPC response messages", - COUNT); + "grpc.io/server/response_count", "Number of server RPC response messages", COUNT); // Visible for testing. RpcMeasureConstants() { diff --git a/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java b/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java index da3f3e5f..83ced6ba 100644 --- a/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java +++ b/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java @@ -58,25 +58,43 @@ import java.util.List; public final class RpcViewConstants { // Common histogram bucket boundaries for bytes received/sets Views. - static final List<Double> RPC_BYTES_BUCKET_BOUNDARIES = Collections.unmodifiableList( - Arrays.asList(0.0, 1024.0, 2048.0, 4096.0, 16384.0, 65536.0, 262144.0, 1048576.0, 4194304.0, - 16777216.0, 67108864.0, 268435456.0, 1073741824.0, 4294967296.0)); + static final List<Double> RPC_BYTES_BUCKET_BOUNDARIES = + Collections.unmodifiableList( + Arrays.asList( + 0.0, + 1024.0, + 2048.0, + 4096.0, + 16384.0, + 65536.0, + 262144.0, + 1048576.0, + 4194304.0, + 16777216.0, + 67108864.0, + 268435456.0, + 1073741824.0, + 4294967296.0)); // Common histogram bucket boundaries for latency and elapsed-time Views. - static final List<Double> RPC_MILLIS_BUCKET_BOUNDARIES = Collections.unmodifiableList( - Arrays.asList(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, - 40.0, 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, - 800.0, 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0)); + static final List<Double> RPC_MILLIS_BUCKET_BOUNDARIES = + Collections.unmodifiableList( + Arrays.asList( + 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, 40.0, + 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, + 800.0, 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0)); // Common histogram bucket boundaries for request/response count Views. - static final List<Double> RPC_COUNT_BUCKET_BOUNDARIES = Collections.unmodifiableList( - Arrays.asList(0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, - 4096.0, 8192.0, 16384.0, 32768.0, 65536.0)); + static final List<Double> RPC_COUNT_BUCKET_BOUNDARIES = + Collections.unmodifiableList( + Arrays.asList( + 0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, + 4096.0, 8192.0, 16384.0, 32768.0, 65536.0)); // Use Aggregation.Mean to record sum and count stats at the same time. static final Aggregation MEAN = Mean.create(); - static final Aggregation AGGREGATION_WITH_BYTES_HISTOGRAM = + static final Aggregation AGGREGATION_WITH_BYTES_HISTOGRAM = Distribution.create(BucketBoundaries.create(RPC_BYTES_BUCKET_BOUNDARIES)); static final Aggregation AGGREGATION_WITH_MILLIS_HISTOGRAM = @@ -165,7 +183,6 @@ public final class RpcViewConstants { Arrays.asList(RPC_METHOD), CUMULATIVE); - // Rpc server cumulative views. public static final View RPC_SERVER_ERROR_COUNT_VIEW = View.create( diff --git a/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstantsTest.java b/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstantsTest.java index ee5114be..d945ee93 100644 --- a/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstantsTest.java +++ b/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstantsTest.java @@ -22,9 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * Test for {@link RpcMeasureConstants}. - */ +/** Test for {@link RpcMeasureConstants}. */ @RunWith(JUnit4.class) public class RpcMeasureConstantsTest { diff --git a/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcViewConstantsTest.java b/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcViewConstantsTest.java index 99cf80b3..b226d326 100644 --- a/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcViewConstantsTest.java +++ b/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcViewConstantsTest.java @@ -36,36 +36,57 @@ public final class RpcViewConstantsTest { public void testConstants() { // Test bucket boundaries. - assertThat(RpcViewConstants.RPC_BYTES_BUCKET_BOUNDARIES).containsExactly( - 0.0, 1024.0, 2048.0, 4096.0, 16384.0, 65536.0, 262144.0, 1048576.0, 4194304.0, - 16777216.0, 67108864.0, 268435456.0, 1073741824.0, 4294967296.0).inOrder(); - assertThat(RpcViewConstants.RPC_MILLIS_BUCKET_BOUNDARIES).containsExactly( - 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, - 40.0, 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, - 800.0, 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0).inOrder(); - assertThat(RpcViewConstants.RPC_COUNT_BUCKET_BOUNDARIES).containsExactly( - 0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, - 4096.0, 8192.0, 16384.0, 32768.0, 65536.0).inOrder(); + assertThat(RpcViewConstants.RPC_BYTES_BUCKET_BOUNDARIES) + .containsExactly( + 0.0, + 1024.0, + 2048.0, + 4096.0, + 16384.0, + 65536.0, + 262144.0, + 1048576.0, + 4194304.0, + 16777216.0, + 67108864.0, + 268435456.0, + 1073741824.0, + 4294967296.0) + .inOrder(); + assertThat(RpcViewConstants.RPC_MILLIS_BUCKET_BOUNDARIES) + .containsExactly( + 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, 40.0, 50.0, + 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, 800.0, + 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0) + .inOrder(); + assertThat(RpcViewConstants.RPC_COUNT_BUCKET_BOUNDARIES) + .containsExactly( + 0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, 4096.0, + 8192.0, 16384.0, 32768.0, 65536.0) + .inOrder(); // Test Aggregations assertThat(RpcViewConstants.MEAN).isEqualTo(Mean.create()); - assertThat(RpcViewConstants.AGGREGATION_WITH_BYTES_HISTOGRAM).isEqualTo( - Distribution.create(BucketBoundaries.create(RpcViewConstants.RPC_BYTES_BUCKET_BOUNDARIES))); - assertThat(RpcViewConstants.AGGREGATION_WITH_MILLIS_HISTOGRAM).isEqualTo( - Distribution.create( - BucketBoundaries.create(RpcViewConstants.RPC_MILLIS_BUCKET_BOUNDARIES))); - assertThat(RpcViewConstants.AGGREGATION_WITH_COUNT_HISTOGRAM).isEqualTo( - Distribution.create(BucketBoundaries.create(RpcViewConstants.RPC_COUNT_BUCKET_BOUNDARIES))); + assertThat(RpcViewConstants.AGGREGATION_WITH_BYTES_HISTOGRAM) + .isEqualTo( + Distribution.create( + BucketBoundaries.create(RpcViewConstants.RPC_BYTES_BUCKET_BOUNDARIES))); + assertThat(RpcViewConstants.AGGREGATION_WITH_MILLIS_HISTOGRAM) + .isEqualTo( + Distribution.create( + BucketBoundaries.create(RpcViewConstants.RPC_MILLIS_BUCKET_BOUNDARIES))); + assertThat(RpcViewConstants.AGGREGATION_WITH_COUNT_HISTOGRAM) + .isEqualTo( + Distribution.create( + BucketBoundaries.create(RpcViewConstants.RPC_COUNT_BUCKET_BOUNDARIES))); // Test Duration and Window assertThat(RpcViewConstants.MINUTE).isEqualTo(Duration.create(60, 0)); assertThat(RpcViewConstants.HOUR).isEqualTo(Duration.create(60 * 60, 0)); assertThat(RpcViewConstants.CUMULATIVE).isEqualTo(Cumulative.create()); - assertThat(RpcViewConstants.INTERVAL_MINUTE).isEqualTo( - Interval.create(RpcViewConstants.MINUTE)); - assertThat(RpcViewConstants.INTERVAL_HOUR).isEqualTo( - Interval.create(RpcViewConstants.HOUR)); - + assertThat(RpcViewConstants.INTERVAL_MINUTE) + .isEqualTo(Interval.create(RpcViewConstants.MINUTE)); + assertThat(RpcViewConstants.INTERVAL_HOUR).isEqualTo(Interval.create(RpcViewConstants.HOUR)); // Test client distribution view descriptors. assertThat(RpcViewConstants.RPC_CLIENT_ERROR_COUNT_VIEW).isNotNull(); diff --git a/contrib/grpc_util/src/main/java/io/opencensus/contrib/grpc/util/StatusConverter.java b/contrib/grpc_util/src/main/java/io/opencensus/contrib/grpc/util/StatusConverter.java index 3bf91e3f..a5732327 100644 --- a/contrib/grpc_util/src/main/java/io/opencensus/contrib/grpc/util/StatusConverter.java +++ b/contrib/grpc_util/src/main/java/io/opencensus/contrib/grpc/util/StatusConverter.java @@ -52,8 +52,8 @@ public final class StatusConverter { * @param opencensusCanonicalCode the given {@code io.opencensus.trace.Status.CanonicalCode}. * @return a {@code io.grpc.Status.Code} from a {@code io.opencensus.trace.Status.CanonicalCode}. */ - public static io.grpc.Status.Code toGrpcCode(io.opencensus.trace.Status.CanonicalCode - opencensusCanonicalCode) { + public static io.grpc.Status.Code toGrpcCode( + io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode) { return grpcStatusFromOpencensusCanonicalCode(opencensusCanonicalCode).getCode(); } @@ -64,16 +64,16 @@ public final class StatusConverter { * @return a {@code io.grpc.Status} from a {@code io.opencensus.trace.Status}. */ public static io.grpc.Status toGrpcStatus(io.opencensus.trace.Status opencensusStatus) { - io.grpc.Status status = grpcStatusFromOpencensusCanonicalCode(opencensusStatus - .getCanonicalCode()); + io.grpc.Status status = + grpcStatusFromOpencensusCanonicalCode(opencensusStatus.getCanonicalCode()); if (opencensusStatus.getDescription() != null) { status = status.withDescription(opencensusStatus.getDescription()); } return status; } - private static io.opencensus.trace.Status opencensusStatusFromGrpcCode(io.grpc.Status.Code - grpcCanonicaleCode) { + private static io.opencensus.trace.Status opencensusStatusFromGrpcCode( + io.grpc.Status.Code grpcCanonicaleCode) { switch (grpcCanonicaleCode) { case OK: return io.opencensus.trace.Status.OK; @@ -113,8 +113,8 @@ public final class StatusConverter { throw new AssertionError("Unhandled status code " + grpcCanonicaleCode); } - private static io.grpc.Status grpcStatusFromOpencensusCanonicalCode(io.opencensus.trace.Status - .CanonicalCode opencensusCanonicalCode) { + private static io.grpc.Status grpcStatusFromOpencensusCanonicalCode( + io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode) { switch (opencensusCanonicalCode) { case OK: return io.grpc.Status.OK; @@ -154,6 +154,5 @@ public final class StatusConverter { throw new AssertionError("Unhandled status code " + opencensusCanonicalCode); } - private StatusConverter() { - } + private StatusConverter() {} } diff --git a/contrib/grpc_util/src/test/java/io/opencensus/contrib/grpc/util/StatusConverterTest.java b/contrib/grpc_util/src/test/java/io/opencensus/contrib/grpc/util/StatusConverterTest.java index c62c5fa7..a6b5e87c 100644 --- a/contrib/grpc_util/src/test/java/io/opencensus/contrib/grpc/util/StatusConverterTest.java +++ b/contrib/grpc_util/src/test/java/io/opencensus/contrib/grpc/util/StatusConverterTest.java @@ -22,17 +22,15 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * Unit tests for {@link StatusConverter}. - */ +/** Unit tests for {@link StatusConverter}. */ @RunWith(JUnit4.class) public class StatusConverterTest { @Test public void convertFromGrpcCode() { for (io.grpc.Status.Code grpcCanonicalCode : io.grpc.Status.Code.values()) { - io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode = StatusConverter - .fromGrpcCode(grpcCanonicalCode); + io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode = + StatusConverter.fromGrpcCode(grpcCanonicalCode); assertThat(opencensusCanonicalCode.toString()).isEqualTo(grpcCanonicalCode.toString()); } } @@ -63,8 +61,7 @@ public class StatusConverterTest { public void convertToGrpcCode() { for (io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode : io.opencensus.trace.Status.CanonicalCode.values()) { - io.grpc.Status.Code grpcCanonicalCode = StatusConverter - .toGrpcCode(opencensusCanonicalCode); + io.grpc.Status.Code grpcCanonicalCode = StatusConverter.toGrpcCode(opencensusCanonicalCode); assertThat(grpcCanonicalCode.toString()).isEqualTo(opencensusCanonicalCode.toString()); } } diff --git a/contrib/zpages/src/main/java/io/opencensus/contrib/zpages/TracezZPageHandler.java b/contrib/zpages/src/main/java/io/opencensus/contrib/zpages/TracezZPageHandler.java index e8ed9b9f..9b86179d 100644 --- a/contrib/zpages/src/main/java/io/opencensus/contrib/zpages/TracezZPageHandler.java +++ b/contrib/zpages/src/main/java/io/opencensus/contrib/zpages/TracezZPageHandler.java @@ -523,10 +523,10 @@ final class TracezZPageHandler extends ZPageHandler { private static void emitLegend(PrintWriter out) { out.write("<br>\n"); - out.printf("<p><b style=\"color:%s;\">TraceId</b> means sampled request. " + out.printf( + "<p><b style=\"color:%s;\">TraceId</b> means sampled request. " + "<b style=\"color:%s;\">TraceId</b> means not sampled request.</p>%n", - SAMPLED_TRACE_ID_COLOR, - NOT_SAMPLED_TRACE_ID_COLOR); + SAMPLED_TRACE_ID_COLOR, NOT_SAMPLED_TRACE_ID_COLOR); } private static Map<LatencyBucketBoundaries, String> buildLatencyBucketBoundariesStringMap() { |
