api: Add reporting fields to activitylog config endpoint (#20086)
This PR adds the internal reporting state to the `internal/counters/config` read endpoint: * reporting_enabled * billing_start_timestamp
This commit is contained in:
parent
8458154fc3
commit
1b5d527521
|
@ -0,0 +1,4 @@
|
|||
```release-note:improvement
|
||||
api: `/sys/internal/counters/config` endpoint now contains read-only
|
||||
`reporting_enabled` and `billing_start_timestamp` fields.
|
||||
```
|
|
@ -834,10 +834,12 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
defaults := map[string]interface{}{
|
||||
"default_report_months": 12,
|
||||
"retention_months": 24,
|
||||
"enabled": activityLogEnabledDefaultValue,
|
||||
"queries_available": false,
|
||||
"default_report_months": 12,
|
||||
"retention_months": 24,
|
||||
"enabled": activityLogEnabledDefaultValue,
|
||||
"queries_available": false,
|
||||
"reporting_enabled": core.censusLicensingEnabled,
|
||||
"billing_start_timestamp": core.GetBillingStart(),
|
||||
}
|
||||
|
||||
if diff := deep.Equal(resp.Data, defaults); len(diff) > 0 {
|
||||
|
@ -915,10 +917,12 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
expected := map[string]interface{}{
|
||||
"default_report_months": 1,
|
||||
"retention_months": 2,
|
||||
"enabled": "enable",
|
||||
"queries_available": false,
|
||||
"default_report_months": 1,
|
||||
"retention_months": 2,
|
||||
"enabled": "enable",
|
||||
"queries_available": false,
|
||||
"reporting_enabled": false,
|
||||
"billing_start_timestamp": core.GetBillingStart(),
|
||||
}
|
||||
|
||||
if diff := deep.Equal(resp.Data, expected); len(diff) > 0 {
|
||||
|
@ -951,10 +955,12 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
|
|||
}
|
||||
|
||||
defaults := map[string]interface{}{
|
||||
"default_report_months": 12,
|
||||
"retention_months": 24,
|
||||
"enabled": activityLogEnabledDefaultValue,
|
||||
"queries_available": false,
|
||||
"default_report_months": 12,
|
||||
"retention_months": 24,
|
||||
"enabled": activityLogEnabledDefaultValue,
|
||||
"queries_available": false,
|
||||
"reporting_enabled": false,
|
||||
"billing_start_timestamp": core.GetBillingStart(),
|
||||
}
|
||||
|
||||
if diff := deep.Equal(resp.Data, defaults); len(diff) > 0 {
|
||||
|
|
|
@ -2,5 +2,9 @@
|
|||
|
||||
package vault
|
||||
|
||||
import "time"
|
||||
|
||||
// CensusAgent is a stub for OSS
|
||||
type CensusAgent struct{}
|
||||
type CensusAgent struct {
|
||||
billingStart time.Time
|
||||
}
|
||||
|
|
|
@ -4015,3 +4015,14 @@ func (c *Core) GetRaftAutopilotState(ctx context.Context) (*raft.AutopilotState,
|
|||
func (c *Core) Events() *eventbus.EventBus {
|
||||
return c.events
|
||||
}
|
||||
|
||||
// GetBillingStart gets the billing start timestamp from the configured Census
|
||||
// Agent, handling a nil agent.
|
||||
func (c *Core) GetBillingStart() time.Time {
|
||||
var billingStart time.Time
|
||||
if c.censusAgent != nil {
|
||||
billingStart = c.censusAgent.billingStart
|
||||
}
|
||||
|
||||
return billingStart
|
||||
}
|
||||
|
|
|
@ -267,10 +267,12 @@ func (b *SystemBackend) handleActivityConfigRead(ctx context.Context, req *logic
|
|||
|
||||
return &logical.Response{
|
||||
Data: map[string]interface{}{
|
||||
"default_report_months": config.DefaultReportMonths,
|
||||
"retention_months": config.RetentionMonths,
|
||||
"enabled": config.Enabled,
|
||||
"queries_available": qa,
|
||||
"default_report_months": config.DefaultReportMonths,
|
||||
"retention_months": config.RetentionMonths,
|
||||
"enabled": config.Enabled,
|
||||
"queries_available": qa,
|
||||
"reporting_enabled": b.Core.censusLicensingEnabled,
|
||||
"billing_start_timestamp": b.Core.GetBillingStart(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -924,7 +924,9 @@ $ curl \
|
|||
"default_report_months": 12,
|
||||
"enabled": "default-enabled",
|
||||
"queries_available": true,
|
||||
"retention_months": 24
|
||||
"retention_months": 24,
|
||||
"reporting_enabled": false,
|
||||
"billing_start_timestamp": "2022-03-01T00:00:00Z",
|
||||
},
|
||||
"warnings": null
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue