Add current_billing_period activity endpoint param (#20694)

* 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
This commit is contained in:
Mike Palmiotto 2023-05-22 09:22:45 -04:00 committed by GitHub
parent 2658dcf48d
commit dc8d2af2d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

4
changelog/20694.txt Normal file
View File

@ -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
```

View File

@ -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",
@ -236,6 +240,7 @@ 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()
@ -243,10 +248,16 @@ func (b *SystemBackend) handleClientMetricQuery(ctx context.Context, req *logica
return logical.ErrorResponse("no activity log present"), nil
}
startTime, endTime, err := parseStartEndTimes(a, d)
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
if limitNamespacesRaw, ok := d.GetOk("limit_namespaces"); ok {

View File

@ -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