Skip to content

Commit 5209ff1

Browse files
authored
Sensible default quota and storage systems when MySQL support unavailable (#3679)
* Choose sensible default quota and storage systems when MySQL support unavailable * Update CHANGELOG.md
1 parent 92bc601 commit 5209ff1

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Misc
1313

1414
* Control included quota and storage providers via build tags by @robstradling in https://github.com/google/trillian/pull/3664
15+
* Sensible default quota and storage systems when MySQL support unavailable by @robstradling in https://github.com/google/trillian/pull/3679
1516

1617
## v1.6.1
1718

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package provider
2+
3+
import (
4+
"slices"
5+
6+
"github.com/google/trillian/quota"
7+
"github.com/google/trillian/storage"
8+
)
9+
10+
var (
11+
DefaultQuotaSystem string
12+
DefaultStorageSystem string
13+
)
14+
15+
func init() {
16+
defaultProvider := "mysql"
17+
providers := storage.Providers()
18+
if len(providers) > 0 && !slices.Contains(providers, defaultProvider) {
19+
slices.Sort(providers)
20+
defaultProvider = providers[0]
21+
}
22+
DefaultStorageSystem = defaultProvider
23+
24+
providers = quota.Providers()
25+
if len(providers) > 0 && !slices.Contains(providers, defaultProvider) {
26+
slices.Sort(providers)
27+
defaultProvider = providers[0]
28+
}
29+
DefaultQuotaSystem = defaultProvider
30+
}

cmd/trillian_log_server/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646
"k8s.io/klog/v2"
4747

4848
// Register supported storage and quota providers.
49-
_ "github.com/google/trillian/cmd/internal/provider"
49+
"github.com/google/trillian/cmd/internal/provider"
5050
)
5151

5252
var (
@@ -58,10 +58,10 @@ var (
5858
etcdService = flag.String("etcd_service", "trillian-logserver", "Service name to announce ourselves under")
5959
etcdHTTPService = flag.String("etcd_http_service", "trillian-logserver-http", "Service name to announce our HTTP endpoint under")
6060

61-
quotaSystem = flag.String("quota_system", "mysql", fmt.Sprintf("Quota system to use. One of: %v", quota.Providers()))
61+
quotaSystem = flag.String("quota_system", provider.DefaultQuotaSystem, fmt.Sprintf("Quota system to use. One of: %v", quota.Providers()))
6262
quotaDryRun = flag.Bool("quota_dry_run", false, "If true no requests are blocked due to lack of tokens")
6363

64-
storageSystem = flag.String("storage_system", "mysql", fmt.Sprintf("Storage system to use. One of: %v", storage.Providers()))
64+
storageSystem = flag.String("storage_system", provider.DefaultStorageSystem, fmt.Sprintf("Storage system to use. One of: %v", storage.Providers()))
6565

6666
treeGCEnabled = flag.Bool("tree_gc", true, "If true, tree garbage collection (hard-deletion) is periodically performed")
6767
treeDeleteThreshold = flag.Duration("tree_delete_threshold", serverutil.DefaultTreeDeleteThreshold, "Minimum period a tree has to remain deleted before being hard-deleted")

cmd/trillian_log_signer/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import (
5252
"k8s.io/klog/v2"
5353

5454
// Register supported storage and quota providers.
55-
_ "github.com/google/trillian/cmd/internal/provider"
55+
"github.com/google/trillian/cmd/internal/provider"
5656
)
5757

5858
var (
@@ -69,12 +69,12 @@ var (
6969
lockDir = flag.String("lock_file_path", "/test/multimaster", "etcd lock file directory path")
7070
healthzTimeout = flag.Duration("healthz_timeout", time.Second*5, "Timeout used during healthz checks")
7171

72-
quotaSystem = flag.String("quota_system", "mysql", fmt.Sprintf("Quota system to use. One of: %v", quota.Providers()))
72+
quotaSystem = flag.String("quota_system", provider.DefaultQuotaSystem, fmt.Sprintf("Quota system to use. One of: %v", quota.Providers()))
7373
quotaIncreaseFactor = flag.Float64("quota_increase_factor", log.QuotaIncreaseFactor,
7474
"Increase factor for tokens replenished by sequencing-based quotas (1 means a 1:1 relationship between sequenced leaves and replenished tokens)."+
7575
"Only effective for --quota_system=etcd.")
7676

77-
storageSystem = flag.String("storage_system", "mysql", fmt.Sprintf("Storage system to use. One of: %v", storage.Providers()))
77+
storageSystem = flag.String("storage_system", provider.DefaultStorageSystem, fmt.Sprintf("Storage system to use. One of: %v", storage.Providers()))
7878

7979
preElectionPause = flag.Duration("pre_election_pause", 1*time.Second, "Maximum time to wait before starting elections")
8080
masterHoldInterval = flag.Duration("master_hold_interval", 60*time.Second, "Minimum interval to hold mastership for")

0 commit comments

Comments
 (0)