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

Disable Log Updates for JIB ProgressBar - supporting jib.console = plain functionality #894

Open
rohanmars opened this issue Sep 8, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@rohanmars
Copy link
Contributor

If you run a jib build in a non ansi terminal (like any CICD build tool) then the jib build will generate endless update messages and fill almost the entire build log. Would be nice to support an option like jukbe.jib.console = plain for that. Basically just print the begin and end messages, not the update ones.

The method I think that does it is static so I'm not sure the best way that should be structured in the code base.
https://github.com/eclipse/jkube/blob/master/jkube-kit/build/service/jib/src/main/java/org/eclipse/jkube/kit/service/jib/JibServiceUtil.java#L253

The log file generates endless messages like:

JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 59.9% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests
JIB> [================== ] 60.0% complete > scheduling building manifests

and

JIB> [================ ] 54.5% complete > scheduling pushing manifests
JIB> [=================== ] 63.6% complete > scheduling pushing manifests
JIB> [=================== ] 63.6% complete > scheduling pushing manifests
JIB> [=================== ] 63.6% complete > scheduling pushing manifests
JIB> [=================== ] 63.6% complete > scheduling pushing manifests
JIB> [=================== ] 63.6% complete > scheduling pushing manifests
JIB> [================ ] 54.5% complete > scheduling pushing manifests
JIB> [=================== ] 63.6% complete > scheduling pushing manifests
JIB> [=================== ] 63.6% complete > scheduling pushing manifests
JIB> [=================== ] 63.6% complete > scheduling pushing manifests

@manusa
Copy link
Member

manusa commented Sep 27, 2021

We should reuse (the existing useColor) or create ANSI specific configuration for logging and apply it to any logger instance we create.

This is what we are doing in with AnsiLogger:

https://github.com/eclipse/jkube/blob/bb25bc67546b02703d93eaf28b3a570e02d4c844/jkube-kit/common-maven/src/main/java/org/eclipse/jkube/kit/common/util/AnsiLogger.java#L216-L225

Which is initialized in (amongst other places):

https://github.com/eclipse/jkube/blob/fd9030014e6a48e0b91e98100976f7f0c07030f0/kubernetes-maven-plugin/plugin/src/main/java/org/eclipse/jkube/maven/plugin/mojo/build/AbstractDockerMojo.java#L409

@manusa manusa added the enhancement New feature or request label Sep 27, 2021
@rohanmars
Copy link
Contributor Author

@manusa that gave me the thought to implement a simple solution based on the static nature of the JibServiceUtil class.

rohanmars@d6f7518

The output on a useColor=false run will just output when the progress is complete for each task. If it's an acceptable approach/implementation I'll create a pull request.

--- a/jkube-kit/build/service/jib/src/main/java/org/eclipse/jkube/kit/service/jib/JibServiceUtil.java
+++ b/jkube-kit/build/service/jib/src/main/java/org/eclipse/jkube/kit/service/jib/JibServiceUtil.java
@@ -39,6 +39,7 @@ import org.eclipse.jkube.kit.config.image.ImageConfiguration;
 import org.eclipse.jkube.kit.config.image.ImageName;
 import org.eclipse.jkube.kit.config.image.build.Arguments;
 import org.eclipse.jkube.kit.config.image.build.BuildConfiguration;
+import org.fusesource.jansi.Ansi;
 
 import com.google.cloud.tools.jib.api.CacheDirectoryCreationException;
 import com.google.cloud.tools.jib.api.Containerizer;
@@ -253,7 +254,11 @@ public class JibServiceUtil {
             if (progressDisplay.size() > 2 && progressDisplay.stream().allMatch(Objects::nonNull)) {
                 final String progressBar = progressDisplay.get(1);
                 final String task = progressDisplay.get(2);
-                System.out.println(ansi().cursorUpLine(1).eraseLine().a(JIB_LOG_PREFIX).a(progressBar).a(" ").a(task));
+                if (Ansi.isEnabled()) {
+                    System.out.println(ansi().cursorUpLine(1).eraseLine().a(JIB_LOG_PREFIX).a(progressBar).a(" ").a(task));
+                } else if (update.getProgress() == 1.0F) {
+                    System.out.println(task);
+                }
             }
         };
     }

@rohanmars
Copy link
Contributor Author

} else if (update.getProgress() == 0.0F) {
works also, that might be more appropriate.

@manusa
Copy link
Member

manusa commented Oct 11, 2021

We'll need to refactor the whole Ansi configuration inference to provide a consistent behavior.

We already have some work in progress in the Gradle Plugin implementation. Once we merge those changes we can start to consider how to properly implement this.

As a note to your approach, even if the terminal supports Ansi, users might still want to opt-out.

@rohanmars
Copy link
Contributor Author

Sounds good.

In the approach (hack) I used jkube.useColor allows users to opt out, apparently because jkube calls Ansi.setEnabled(true/flase); in 2 locations based on useColor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants