-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1645 from openmeterio/refactor-topic-provisioner-…
…config refactor: topic provisioner config
- Loading branch information
Showing
9 changed files
with
96 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
// TopicProvisionerConfig stores the configuration for TopicProvisioner | ||
type TopicProvisionerConfig struct { | ||
// The maximum number of entries stored in topic cache at a time which after the least recently used is evicted. | ||
// Setting size to 0 makes it unlimited | ||
CacheSize int | ||
|
||
// The maximum time an entries is kept in cache before being evicted | ||
CacheTTL time.Duration | ||
} | ||
|
||
func (c TopicProvisionerConfig) Validate() error { | ||
var errs []error | ||
|
||
if c.CacheSize < 0 { | ||
errs = append(errs, fmt.Errorf("invalid cache size: %d", c.CacheSize)) | ||
} | ||
|
||
if c.CacheTTL < 0 { | ||
errs = append(errs, fmt.Errorf("invalid cache ttl: %d", c.CacheTTL)) | ||
} | ||
|
||
return errors.Join(errs...) | ||
} | ||
|
||
// ConfigureTopicProvisioner configures some defaults in the Viper instance. | ||
func ConfigureTopicProvisioner(v *viper.Viper, prefixes ...string) { | ||
prefixer := NewViperKeyPrefixer(prefixes...) | ||
|
||
v.SetDefault(prefixer("cacheSize"), 250) | ||
v.SetDefault(prefixer("cacheTTL"), "5m") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters