You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/10/26 07:01:39 UTC
[GitHub] [ignite-3] valepakh opened a new pull request, #1249: IGNITE-17786 Add --verbose option to all commands
valepakh opened a new pull request, #1249:
URL: https://github.com/apache/ignite-3/pull/1249
https://issues.apache.org/jira/browse/IGNITE-17786
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] valepakh commented on a diff in pull request #1249: IGNITE-17786 Add --verbose option to all commands
Posted by GitBox <gi...@apache.org>.
valepakh commented on code in PR #1249:
URL: https://github.com/apache/ignite-3/pull/1249#discussion_r1005514991
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/flow/builder/FlowBuilderImpl.java:
##########
@@ -46,9 +47,10 @@
private final Flow<I, O> flow;
private final ExceptionHandlers exceptionHandlers;
private final DecoratorRegistry decoratorRegistry;
+ private boolean verbose;
Review Comment:
It's not final because it's set by the method, not the constructor.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #1249: IGNITE-17786 Add --verbose option to all commands
Posted by GitBox <gi...@apache.org>.
PakhomovAlexander commented on code in PR #1249:
URL: https://github.com/apache/ignite-3/pull/1249#discussion_r1005304923
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/call/CallExecutionPipeline.java:
##########
@@ -83,6 +90,19 @@ public static <I extends CallInput, T> CallExecutionPipelineBuilder<I, T> builde
* @return exit code.
*/
public int runPipeline() {
+ try {
+ if (verbose) {
+ CliLoggers.redirectOutput(errOutput);
+ }
+ return runPipelineInternal();
+ } finally {
+ if (verbose) {
+ CliLoggers.redirectOutput(null);
Review Comment:
`CliLoggers.redirectOutput(null);` looks strange. It could be read as "redirect logger output to nothing" that might give a false illustion that the logger won't write logs at all. But in fact, it writes to log file. I would suggest to add one more method like `setDefaultOutput()`.
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/flow/builder/FlowBuilderImpl.java:
##########
@@ -46,9 +47,10 @@
private final Flow<I, O> flow;
private final ExceptionHandlers exceptionHandlers;
private final DecoratorRegistry decoratorRegistry;
+ private boolean verbose;
Review Comment:
why not final?
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/logger/CliLoggers.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.logger;
+
+import java.io.PrintWriter;
+import java.lang.System.Logger;
+import java.util.ResourceBundle;
+import okhttp3.OkHttpClient;
+import okhttp3.OkHttpClient.Builder;
+import okhttp3.logging.HttpLoggingInterceptor;
+import okhttp3.logging.HttpLoggingInterceptor.Level;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.lang.LoggerFactory;
+import org.apache.ignite.rest.client.invoker.ApiClient;
+import org.apache.ignite.rest.client.invoker.Configuration;
+
+public class CliLoggers {
+ private static PrintWriter output;
+
+ private static boolean isVerbose;
+
+ private static final LoggerFactory loggerFactory = name -> new CliLogger(System.getLogger(name));
+
+ public static IgniteLogger forClass(Class<?> cls) {
+ return Loggers.forClass(cls, loggerFactory);
+ }
+
+ public static IgniteLogger forName(String name) {
+ return Loggers.forName(name, loggerFactory);
+ }
+
+ public static void redirectOutput(PrintWriter output) {
+ CliLoggers.output = output;
+ boolean isVerbose = output != null;
+ if (CliLoggers.isVerbose != isVerbose) {
+ setHttpLogging(isVerbose);
+ }
+ CliLoggers.isVerbose = isVerbose;
+ }
+
+ private static void setHttpLogging(boolean isVerbose) {
Review Comment:
I think this code should not be located in a class named CliLoggers. We have to rename this class or move this http-related code to a separate class.
##########
modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/flow/FlowTest.java:
##########
@@ -53,6 +55,25 @@ class FlowTest {
private StringWriter out;
private StringWriter errOut;
+ @Test
+ void testVerbose() throws IOException {
Review Comment:
this test is good and it would be nice to test CallExcecutionPipeline too. Maybe it could be just a regular command test but with --verbose flag.
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/logger/CliLoggers.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.logger;
+
+import java.io.PrintWriter;
+import java.lang.System.Logger;
+import java.util.ResourceBundle;
+import okhttp3.OkHttpClient;
+import okhttp3.OkHttpClient.Builder;
+import okhttp3.logging.HttpLoggingInterceptor;
+import okhttp3.logging.HttpLoggingInterceptor.Level;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.lang.LoggerFactory;
+import org.apache.ignite.rest.client.invoker.ApiClient;
+import org.apache.ignite.rest.client.invoker.Configuration;
+
+public class CliLoggers {
Review Comment:
It might be useful to add a javadoc that explains why this class exists and when to use it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] SammyVimes commented on a diff in pull request #1249: IGNITE-17786 Add --verbose option to all commands
Posted by GitBox <gi...@apache.org>.
SammyVimes commented on code in PR #1249:
URL: https://github.com/apache/ignite-3/pull/1249#discussion_r1010263166
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/logger/HttpLogging.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.logger;
+
+import java.io.PrintWriter;
+import okhttp3.OkHttpClient.Builder;
+import okhttp3.logging.HttpLoggingInterceptor;
+import okhttp3.logging.HttpLoggingInterceptor.Level;
+import org.apache.ignite.rest.client.invoker.ApiClient;
+import org.apache.ignite.rest.client.invoker.Configuration;
+
+/** Helper class for logging HTTP requests/responses from generated REST API client. */
+public class HttpLogging {
+ /**
+ * Starts logging HTTP requests/responses to specified {@code PrintWriter}.
+ *
+ * @param output Print writer to print logs to.
+ */
+ public static void startHttpLogging(PrintWriter output) {
+ ApiClient client = Configuration.getDefaultApiClient();
+ Builder builder = client.getHttpClient().newBuilder();
+
+ HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(output::println);
+ interceptor.setLevel(Level.BASIC);
+ builder.interceptors().add(interceptor);
+
+ client.setHttpClient(builder.build());
+ }
+
+ /**
+ * Stops logging previously started by {@link HttpLogging#startHttpLogging(PrintWriter)}.
+ */
+ public static void stopHttpLogging() {
+ ApiClient client = Configuration.getDefaultApiClient();
+ Builder builder = client.getHttpClient().newBuilder();
+
+ builder.interceptors().clear();
Review Comment:
Won't it clear **all** interceptors when we only want to stop http log?
Also, adding a test checking correct behaviour of this method would be cool
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/flow/builder/FlowBuilder.java:
##########
@@ -102,6 +102,14 @@ default <OT> FlowBuilder<I, OT> map(Function<O, OT> mapper) {
*/
FlowBuilder<I, O> exceptionHandler(ExceptionHandler<?> exceptionHandler);
+ /**
+ * Adds verbose output from debug log to the output.
+ *
+ * @param verbose if @{code true}, flow execution will print debug logs
+ * @return instance of builder
Review Comment:
```suggestion
* @param verbose If @{code true}, flow execution will print debug logs.
* @return Builder instance.
```
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/BaseCommand.java:
##########
@@ -29,6 +29,9 @@ public abstract class BaseCommand {
@Option(names = {"-h", "--help"}, usageHelp = true, description = "Show this help message and exit.")
protected boolean usageHelpRequested;
+ @Option(names = {"-v", "--verbose"}, description = "Show additional information about errors.")
+ protected boolean verbose;
Review Comment:
Is it always about errors?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] SammyVimes merged pull request #1249: IGNITE-17786 Add --verbose option to all commands
Posted by GitBox <gi...@apache.org>.
SammyVimes merged PR #1249:
URL: https://github.com/apache/ignite-3/pull/1249
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org