Skip to content

Commit

Permalink
Add current_billing_period activity endpoint param (#20694)
Browse files Browse the repository at this point in the history
* Add current_billing_period activity endpoint param

This commit introduces a new parameter: `current_billing_period`, which
can be used in lieu of `start_time` and `end_time` options.

GET ... /sys/internal/counters/activity?current_billing_period=true now
results in a response which contains the full billing period
information.

* changelog

* Update internal counters docs
  • Loading branch information
mpalmi committed May 22, 2023
1 parent a86d8c4 commit 810d504
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions changelog/20694.txt
@@ -0,0 +1,4 @@
```release-note:improvement
api: GET ... /sys/internal/counters/activity?current_billing_period=true now
results in a response which contains the full billing period
```
17 changes: 14 additions & 3 deletions vault/logical_system_activity.go
Expand Up @@ -29,6 +29,10 @@ func (b *SystemBackend) activityQueryPath() *framework.Path {
},

Fields: map[string]*framework.FieldSchema{
"current_billing_period": {
Type: framework.TypeBool,
Description: "Query utilization for configured billing period",
},
"start_time": {
Type: framework.TypeTime,
Description: "Start of query interval",
Expand Down Expand Up @@ -236,16 +240,23 @@ func (b *SystemBackend) handleClientExport(ctx context.Context, req *logical.Req
}

func (b *SystemBackend) handleClientMetricQuery(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
var startTime, endTime time.Time
b.Core.activityLogLock.RLock()
a := b.Core.activityLog
b.Core.activityLogLock.RUnlock()
if a == nil {
return logical.ErrorResponse("no activity log present"), nil
}

startTime, endTime, err := parseStartEndTimes(a, d)
if err != nil {
return logical.ErrorResponse(err.Error()), nil
if d.Get("current_billing_period").(bool) {
startTime = b.Core.BillingStart()
endTime = time.Now().UTC()
} else {
var err error
startTime, endTime, err = parseStartEndTimes(a, d)
if err != nil {
return logical.ErrorResponse(err.Error()), nil
}
}

var limitNamespaces int
Expand Down
4 changes: 4 additions & 0 deletions website/content/api-docs/system/internal-counters.mdx
Expand Up @@ -346,6 +346,10 @@ This endpoint was added in Vault 1.6.
- `limit_namespaces` `(int, optional)` - Controls the total number of by_namespace data returned. This can
be used to return the client counts for the specified number of namespaces having highest activity.
If no `limit_namespaces` parameter is specified, client counts for all namespaces in specified usage period is returned.
- `current_billing_period` `(bool, optional)` - Uses the builtin billing start
timestamp as `start_time` and the current time as the `end_time`, returning a
response with the current billing period information without having to
explicitly provide a start and end time.


### Sample Request
Expand Down

0 comments on commit 810d504

Please sign in to comment.