Skip to content

Commit

Permalink
api: Add reporting fields to activitylog config endpoint (#20086)
Browse files Browse the repository at this point in the history
This PR adds the internal reporting state to the
`internal/counters/config` read endpoint:
* reporting_enabled
* billing_start_timestamp
  • Loading branch information
mpalmi authored Apr 12, 2023
1 parent 1a50a97 commit 05ba6bb
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
4 changes: 4 additions & 0 deletions changelog/20086.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:improvement
api: `/sys/internal/counters/config` endpoint now contains read-only
`reporting_enabled` and `billing_start_timestamp` fields.
```
30 changes: 18 additions & 12 deletions vault/activity_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion vault/census.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

package vault

import "time"

// CensusAgent is a stub for OSS
type CensusAgent struct{}
type CensusAgent struct {
billingStart time.Time
}
11 changes: 11 additions & 0 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 6 additions & 4 deletions vault/logical_system_activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion website/content/api-docs/system/internal-counters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 05ba6bb

Please sign in to comment.