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:
Mike Palmiotto 2023-04-12 12:02:28 -04:00 committed by GitHub
parent 8458154fc3
commit 1b5d527521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 18 deletions

4
changelog/20086.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:improvement
api: `/sys/internal/counters/config` endpoint now contains read-only
`reporting_enabled` and `billing_start_timestamp` fields.
```

View File

@ -838,6 +838,8 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
"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 {
@ -919,6 +921,8 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
"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 {
@ -955,6 +959,8 @@ func TestActivityLog_API_ConfigCRUD(t *testing.T) {
"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 {

View File

@ -2,5 +2,9 @@
package vault
import "time"
// CensusAgent is a stub for OSS
type CensusAgent struct{}
type CensusAgent struct {
billingStart time.Time
}

View File

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

View File

@ -271,6 +271,8 @@ func (b *SystemBackend) handleActivityConfigRead(ctx context.Context, req *logic
"retention_months": config.RetentionMonths,
"enabled": config.Enabled,
"queries_available": qa,
"reporting_enabled": b.Core.censusLicensingEnabled,
"billing_start_timestamp": b.Core.GetBillingStart(),
},
}, nil
}

View File

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