Add support for history data retention

This commit is contained in:
Patrick Pacher
2023-08-08 14:35:43 +02:00
parent 620a9c0fde
commit 3dbde10be0
6 changed files with 169 additions and 10 deletions

View File

@@ -112,6 +112,10 @@ var (
cfgOptionEnableHistory config.BoolOption
cfgOptionEnableHistoryOrder = 96
CfgOptionHistoryRetentionKey = "history/retention"
CfgOptionHistoryRetention config.IntOption
cfgOptionHistoryRetentionOrder = 97
// Setting "Enable SPN" at order 128.
CfgOptionUseSPNKey = "spn/use"
@@ -267,6 +271,27 @@ func registerConfiguration() error { //nolint:maintidx
cfgOptionEnableHistory = config.Concurrent.GetAsBool(CfgOptionEnableHistoryKey, false)
cfgBoolOptions[CfgOptionEnableHistoryKey] = cfgOptionEnableHistory
err = config.Register(&config.Option{
Name: "History Data Retention",
Key: CfgOptionHistoryRetentionKey,
Description: "How low, in days, connections should be kept in history.",
OptType: config.OptTypeInt,
ReleaseLevel: config.ReleaseLevelStable,
ExpertiseLevel: config.ExpertiseLevelUser,
DefaultValue: 7,
Annotations: config.Annotations{
config.UnitAnnotation: "Days",
config.DisplayOrderAnnotation: cfgOptionHistoryRetentionOrder,
config.CategoryAnnotation: "History",
config.RequiresFeatureID: account.FeatureHistory,
},
})
if err != nil {
return err
}
CfgOptionHistoryRetention = config.Concurrent.GetAsInt(CfgOptionHistoryRetentionKey, 7)
cfgIntOptions[CfgOptionHistoryRetentionKey] = CfgOptionHistoryRetention
rulesHelp := strings.ReplaceAll(`Rules are checked from top to bottom, stopping after the first match. They can match:
- By address: "192.168.0.1"

View File

@@ -127,10 +127,12 @@ func GetLocalProfile(id string, md MatchingData, createProfileCallback func() *P
// Update metadata.
var changed bool
if special {
changed = updateSpecialProfileMetadata(profile, md.Path())
} else {
changed = profile.updateMetadata(md.Path())
if md != nil {
if special {
changed = updateSpecialProfileMetadata(profile, md.Path())
} else {
changed = profile.updateMetadata(md.Path())
}
}
// Save if created or changed.

View File

@@ -137,6 +137,7 @@ type Profile struct { //nolint:maligned // not worth the effort
spnUsagePolicy endpoints.Endpoints
spnExitHubPolicy endpoints.Endpoints
enableHistory bool
historyRetention int
// Lifecycle Management
outdated *abool.AtomicBool
@@ -239,6 +240,13 @@ func (profile *Profile) parseConfig() error {
profile.enableHistory = enableHistory
}
retention, ok := profile.configPerspective.GetAsInt(CfgOptionHistoryRetentionKey)
if ok {
profile.historyRetention = int(retention)
} else {
profile.historyRetention = int(CfgOptionHistoryRetention())
}
return lastErr
}
@@ -326,6 +334,10 @@ func (profile *Profile) HistoryEnabled() bool {
return profile.enableHistory
}
func (profile *Profile) HistoryRetention() int {
return profile.historyRetention
}
// GetEndpoints returns the endpoint list of the profile. This functions
// requires the profile to be read locked.
func (profile *Profile) GetEndpoints() endpoints.Endpoints {