robusta-dev / krr

Prometheus-based Kubernetes Resource Recommendations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dgdevops opened this issue · 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.

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

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

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.

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

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.

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

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.