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

Display a warning message for Beta and Exerimental tools. #4429

Merged
merged 3 commits into from Feb 23, 2018

Conversation

cmnbroad
Copy link
Collaborator

@cmnbroad cmnbroad commented Feb 20, 2018

Fixes #4367. Includes a sleep for 5 seconds; not sure thats a good idea, although the warning message scrolls off the screen pretty quickly, especially with Spark apps. This will need to be replicated in Picard as well.

Experimental:

screen shot 2018-02-20 at 3 37 06 pm

Beta:

screen shot 2018-02-20 at 3 37 22 pm

if (warningMessage != null) {
logger.warn(warningMessage);
try {
Thread.sleep(5000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 seconds of sleep is going to drive me insane. .5 seems much more tolerable but still noticeable. We might want to add a command line option to disable the sleep and apply that to all the tests

@droazen
Copy link
Collaborator

droazen commented Feb 20, 2018

Let's remove the sleep delay @cmnbroad. Red text + a border made out of exclamation points should be sufficient.

@droazen droazen self-requested a review February 20, 2018 21:17
@droazen droazen self-assigned this Feb 20, 2018
@lbergelson
Copy link
Member

The one problem with using color in the output is that it makes it gross to read logs that aren't on an interactive terminal that supports color. We might want to make an attempt to tell if we're connected to a terminal or an output file and remove the colors if so.

@lbergelson
Copy link
Member

I have this class from an ancient branch that makes dealing with colors nicer in some ways. It tries to avoid printing colors to non-interactive things and it makes it harder to forget a reset:

/**
 * Provides ANSI colors for the terminal output *
 */
public final class TerminalColors {

    private TerminalColors(){};

    private enum TerminalColor{
        CYAN("\u001B[36m"),
        RED("\u001B[31m"),
        GREEN("\u001B[32m"),
        WHITE("\u001B[37m"),
        BOLD("\u001B[1m"),
        RESET("\u001B[0m"); // reset the colors

        private final String color;

        TerminalColor(String color){
            this.color = color;
        }

        public String getColorString(){
            return color;
        }

    }

    public static boolean isInteractive(){
        return !(System.console() == null);
    }

    public static String cyan(String toColor){
        return colorString(toColor, TerminalColor.CYAN);
    }

    public static String red(String toColor){
        return colorString(toColor, TerminalColor.RED);
    }

    public static String green(String toColor){
        return colorString(toColor, TerminalColor.GREEN);
    }

    public static String white(String toColor){
        return colorString(toColor, TerminalColor.WHITE);
    }

    public static String bold(String toBold){
        return colorString(toBold, TerminalColor.BOLD);
    }

    public static String colorString(String toColor, TerminalColor color) {
        if(isInteractive()) {
            return color.getColorString() + toColor + TerminalColor.RESET.getColorString();
        } else {
            return toColor;
        }
    }

    public static String stripColorsFromString(String colorString){
        String stripped = colorString;
        for(TerminalColor color : TerminalColor.values()) {
            stripped = stripped.replace(color.getColorString(),"");
        }
        return stripped;
    }
}

@cmnbroad
Copy link
Collaborator Author

@lbergelson What do you think about putting the TerminalColors class in Barclay ? The same changes I'm making here need to be made in Picard. We could put a lot of this behavior into a shared CommandLineProgram base class that uses TerminalColors.

@lbergelson
Copy link
Member

@cmnbroad Barclay sounds like the best place for things that have to deal with the command line. Feel free to use that class or not. I'm not sure it's the greatest way to deal with colors, but it seems better than manually adding the escape codes everywhere.

@codecov-io
Copy link

Codecov Report

Merging #4429 into master will increase coverage by 0.079%.
The diff coverage is 77.273%.

@@              Coverage Diff               @@
##             master     #4429       +/-   ##
==============================================
+ Coverage     79.04%   79.119%   +0.079%     
- Complexity    16447     16521       +74     
==============================================
  Files          1047      1047               
  Lines         59189     59460      +271     
  Branches       9672      9747       +75     
==============================================
+ Hits          46783     47044      +261     
+ Misses         8644      8639        -5     
- Partials       3762      3777       +15
Impacted Files Coverage Δ Complexity Δ
...stitute/hellbender/cmdline/CommandLineProgram.java 81.757% <77.273%> (-0.783%) 43 <9> (+9)
...park/sv/discovery/alignment/AlignmentInterval.java 89.272% <0%> (ø) 73% <0%> (ø) ⬇️
...kers/variantutils/PosteriorProbabilitiesUtils.java 77.966% <0%> (+0.847%) 43% <0%> (+1%) ⬆️
...oadinstitute/hellbender/utils/gcs/BucketUtils.java 80% <0%> (+1.29%) 39% <0%> (ø) ⬇️
...nder/tools/examples/ExampleVariantWalkerSpark.java 76.316% <0%> (+2.242%) 9% <0%> (+4%) ⬆️
...institute/hellbender/engine/FeatureDataSource.java 79.752% <0%> (+3.696%) 66% <0%> (+22%) ⬆️
...oadinstitute/hellbender/utils/test/XorWrapper.java 78.261% <0%> (+4.348%) 9% <0%> (+1%) ⬆️
...kers/variantutils/CalculateGenotypePosteriors.java 91.398% <0%> (+5.482%) 25% <0%> (+12%) ⬆️
...hellbender/utils/test/VariantContextTestUtils.java 89.053% <0%> (+6.621%) 83% <0%> (+23%) ⬆️
...utils/smithwaterman/SmithWatermanIntelAligner.java 90% <0%> (+40%) 3% <0%> (+2%) ⬆️

@magicDGS
Copy link
Contributor

Maybe https://github.com/fusesource/jansi to handle colors?

/**
* If a tool is either Experimental or Beta, log a warning against use in production a environment.
*/
protected void printProductionWarning() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe warnAboutToolStatus() would be clearer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* If a tool is either Experimental or Beta, log a warning against use in production a environment.
*/
protected void printProductionWarning() {
final String warningMessage = getProductionWarning(!(System.console() == null));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this check isn't 100% reliable, I would take it out. Printing the literal codes in non-interactive use is not that big of a deal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @param useTerminalColor true if the message should include highlighting terminal colorization
* @return a warning message if the tool is Beta or Experimental, otherwise null
*/
protected String getProductionWarning(final boolean useTerminalColor) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getToolStatusWarning() might be clearer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator

@droazen droazen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 merge after addressing comments

@droazen droazen assigned cmnbroad and unassigned droazen Feb 22, 2018
@cmnbroad cmnbroad merged commit c05ffd4 into master Feb 23, 2018
@cmnbroad cmnbroad deleted the cn_experimental_warning branch February 23, 2018 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants