krr icon indicating copy to clipboard operation
krr copied to clipboard

`--fileoutput` flag creates empty file when using table formatter

Open dgdevops opened this issue 11 months ago • 8 comments

Describe the bug When using the --fileoutput flag with or without specifying the --formatter table option the script succeeds but creates a 0 byte file with no content.

To Reproduce Steps to reproduce the behavior:

  1. Install/build version 1.7.1/1.7.0
  2. Run the script with default parameters and with the --fileoutput ./<your-file-name> flag specified
  3. Check the size & content of the output file (0 bytes in size, zero content)

Expected behavior The script should write out the table content to the desired output file.

Are you interested in contributing a fix for this? Yes

Desktop (please complete the following information):

  • OS: MacOS
  • Version [1.7.1]

Additional context Changing the --formatter flag to json, yaml, pprint results in correct file output. As a result of this issue Slack reports cannot be sent in table format. I have tested 1.5.3 and it works perfectly so something broke in version 1.6.0.

dgdevops avatar Mar 06 '24 17:03 dgdevops

Hello @aantn, Is there a way to get this prioritised? It is a main functionality that broke in the new version.

dgdevops avatar Mar 14 '24 08:03 dgdevops

Hi @dgdevops, As a workaround is it possible to use --quiet and pipe output from stdout to a file?

aantn avatar Mar 14 '24 09:03 aantn

Hello @aantn, Thank you for your quick response. To test this I split the action into two parts:

  1. Write out the output to a file (krr simple --prometheus-url http://localhost:53312 --quiet >> myfile)
  2. Repeat the command with the --slackoutput flag specified with value matching the name of the file that was written out in step 1): krr simple --prometheus-url http://localhost:53312 --quiet --slackoutput myfile

The second command overwrote the content of myfile so basically the content of the file was zeroized.

dgdevops avatar Mar 14 '24 10:03 dgdevops

Got it. Just to clarify, it works OK for your use case with --quiet?

aantn avatar Mar 14 '24 10:03 aantn

Using the --quiet flag on its own (krr simple --prometheus-url http://localhost:53312 --quiet --fileoutput myfile) still results in an empty file so I have to use >> to write out the output from stdout as you suggested. My initial intention with this GitHub issue was to find a workaround or implement a fix for the slack reporting that relies on file output, the --quite flag suggested above does not address this issue.

dgdevops avatar Mar 14 '24 11:03 dgdevops

I've added a fix in #231. Can you confirm that it works?

aantn avatar Mar 14 '24 13:03 aantn

Hello @aantn, I have tested it and both the --fileoutput & --slackoutput flags work fine. Thank you for your quick action.

One idea, when using the table formatter there is no information (name) about the cluster the information was gathered from, when using the JSON formatter for example there is a dedicated cluster_name field. Instead of displaying the namespace in the Slack message (https://github.com/robusta-dev/krr/blob/main/robusta_krr/core/runner.py#L102) the message should rather contain the name of the cluster as the namespace is part of the report regardless of the formatter used and it is currently redundant but the cluster name is not.

dgdevops avatar Mar 14 '24 14:03 dgdevops

Wonderful, thanks for the quick testing on your side!

On Thu, Mar 14, 2024 at 4:06 PM dgdevops @.***> wrote:

Hello @aantn https://github.com/aantn, I have tested it and both the --fileoutput & --slackoutput flags work fine. Thank you for your quick action.

— Reply to this email directly, view it on GitHub https://github.com/robusta-dev/krr/issues/225#issuecomment-1997540569, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADYUBYVKL5IXHC2GEBSU23YYGVFFAVCNFSM6AAAAABEJQ3PTOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJXGU2DANJWHE . You are receiving this because you were mentioned.Message ID: @.***>

aantn avatar Mar 14 '24 14:03 aantn