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

"vault operator usage" CLI for client count reporting #10365

Merged
merged 7 commits into from
Nov 23, 2020
Merged

Conversation

mgritter
Copy link
Contributor

@mgritter mgritter commented Nov 9, 2020

Here's the CLI in action:

mgritter@ubuntu:~/vault$ bin/vault operator usage
Period start: 2019-11-01T00:00:00Z
Period end: 2020-10-31T23:59:59Z

Namespace path              Distinct entities   Non-Entity tokens   Active clients
--------------              -----------------   -----------------   --------------
[root]                      448                 698                 1146
aaa/                        732                 794                 1526
aaa/ccc/                    1729                942                 2671
aaa/ddd/                    833                 929                 1762
aaa/ddd/eee/                476                 604                 1080
aaa/ddd/ggg/                1897                1117                3014
aaa/ddd/hhh/                515                 455                 970
bbb/                        911                 877                 1788
deleted namespace "mzK8K"   771                 1156                1927
                                                                     
Total                       8312                7572                15884

mgritter@ubuntu:~/vault$ bin/vault operator usage -ns=aaa/ddd
Period start: 2019-11-01T00:00:00Z
Period end: 2020-10-31T23:59:59Z

Namespace path   Distinct entities   Non-Entity tokens   Active clients
--------------   -----------------   -----------------   --------------
aaa/ddd/         833                 929                 1762
aaa/ddd/eee/     476                 604                 1080
aaa/ddd/ggg/     1897                1117                3014
aaa/ddd/hhh/     515                 455                 970
                                                          
Total            3721                3105                6826

mgritter@ubuntu:~/vault$ bin/vault operator usage -end-time=2019-06
No data is available for the given time range.

mgritter@ubuntu:~/vault$ bin/vault operator usage -start-time=2020-10-15
Period start: 2020-10-01T00:00:00Z
Period end: 2020-10-31T23:59:59Z

Namespace path              Distinct entities   Non-Entity tokens   Active clients
--------------              -----------------   -----------------   --------------
[root]                      342                 577                 919
aaa/                        176                 760                 936
aaa/ccc/                    822                 745                 1567
aaa/ddd/                    791                 180                 971
aaa/ddd/eee/                302                 217                 519
aaa/ddd/ggg/                899                 395                 1294
aaa/ddd/hhh/                184                 208                 392
bbb/                        871                 89                  960
deleted namespace "mzK8K"   87                  371                 458
                                                                     
Total                       4474                3542                8016

@mgritter mgritter marked this pull request as draft November 9, 2020 20:45
@mgritter mgritter marked this pull request as ready for review November 13, 2020 22:19
@mgritter
Copy link
Contributor Author

Help output:

mgritter@ubuntu:~/vault$ bin/vault operator usage -help
Usage: vault operator usage

  List the client counts for the default reporting period.

	  $ vault operator usage

  List the client counts for a specific time period.

          $ vault operator usage -start-time=2020-10 -end-time=2020-11

HTTP Options:

...

Output Options:

  -format=<string>
      Print the output in the given format. Valid formats are "table", "json",
      or "yaml". The default is table. This can also be specified via the
      VAULT_FORMAT environment variable.

Command Options:

  -end-time=<time>
      End of report period (defaults to end of last month.)

  -start-time=<time>
      Start of report period (defaults to default_reporting_period before end
      time.)

Copy link
Contributor

@swayne275 swayne275 left a comment

Choose a reason for hiding this comment

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

Looks really good!

Should any of this stuff be unit tested?

@mgritter
Copy link
Contributor Author

I don't know if I can get testVaultServer() to return anything sensible for unit testing.

}

if resp == nil || resp.Data == nil {
c.UI.Warn("No data is available for the given time range.")

Choose a reason for hiding this comment

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

In cases where a user only provides an end date or a start date (and not both), would it be possible to show the time range itself? E.g. if a user gives an end date of October 31, we say "No data is available for the given time range START to END." It gives some visibility into what's actually being done and may help the user form their search better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this suggestion, but I'm having a hard time implementing it, because all the logic is on the server side, and not returned in the current API (which just does a 204 no content response.)

Retrieving the default_reporting_period would require an extra round trip.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead, I added a check whether any queries were available, using the existing API. So we are paying that round trip but I still felt it was the wrong direction to reproduce the range-calculation logic in the client. (But I still agree that would be the clearest; maybe it makes sense to change the API response when no data is available.)

@mladlow
Copy link
Collaborator

mladlow commented Nov 19, 2020

Can you add a changelog file for this please?

@mgritter mgritter requested a review from swayne275 November 20, 2020 23:29
@mladlow mladlow added this to the 1.6.1 milestone Nov 23, 2020
@mgritter mgritter merged commit 3b4cc01 into master Nov 23, 2020
@mgritter mgritter deleted the activity_log_cli branch November 23, 2020 20:57
mgritter pushed a commit that referenced this pull request Nov 24, 2020
* Working draft of CLI command.
* Sort order, robustness checking.
* Text edits and check of queries_available.
* Added changelog.
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.

4 participants