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:
parent
2658dcf48d
commit
dc8d2af2d8
|
@ -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
|
||||
```
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue