mirrored from https://chromium.googlesource.com/infra/luci/luci-go
/
flags.go
122 lines (108 loc) · 3.99 KB
/
flags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2021 The LUCI Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"time"
"go.chromium.org/luci/common/errors"
)
// CommandLineFlags contains archivist service configuration.
//
// It is exposed via CLI flags.
type CommandLineFlags struct {
// StagingBucket is the name of the Google Storage bucket to use for staging
// logs.
//
// All projects will share the same staging bucket. Logs for a project will be
// staged under `gs://<StagingBucket>/<AppID>/<ProjectName>/...`.
//
// Required.
StagingBucket string
// MaxConcurrentTasks is the maximum number of archival tasks to process
// concurrently or 0 for unlimited.
//
// Default is 1.
MaxConcurrentTasks int
// LeaseBatchSize is the number of archival tasks to lease from the taskqueue
// per one cycle.
//
// TaskQueue has a limit of 10qps for leasing tasks, so the batch size must
// be set to:
// LeaseBatchSize * 10 > (max expected stream creation QPS)
//
// In 2020, max stream QPS is approximately 1000 QPS.
//
// Default is 500.
LeaseBatchSize int
// LeaseTime is the amount of time to to lease the batch of tasks for.
//
// We need:
// (time to process avg stream) * LeaseBatchSize < LeaseTime
//
// As of 2020, 90th percentile process time per stream is ~5s, 95th
// percentile of the loop time is 25m.
//
//
// Default is 40 min.
LeaseTime time.Duration
// Entries below specify defaults for archive indexes generation. Individual
// projects may override these default values in their project configs.
// ArchiveIndexStreamRange, if not zero, is the maximum number of stream
// indexes between index entries.
//
// Default is 0.
ArchiveIndexStreamRange int
// ArchiveIndexPrefixRange, if not zero, is the maximum number of prefix
// indexes between index entries.
//
// Default is 0.
ArchiveIndexPrefixRange int
// ArchiveIndexByteRange, if not zero, is the maximum number of log data bytes
// between index entries.
//
// Default is 0.
ArchiveIndexByteRange int
}
// DefaultCommandLineFlags returns CommandLineFlags with populated defaults.
func DefaultCommandLineFlags() CommandLineFlags {
return CommandLineFlags{
MaxConcurrentTasks: 1,
LeaseBatchSize: 500,
LeaseTime: 40 * time.Minute,
}
}
// Register registers flags in the flag set.
func (f *CommandLineFlags) Register(fs *flag.FlagSet) {
fs.StringVar(&f.StagingBucket, "staging-bucket", f.StagingBucket,
"GCE bucket name to use for staging logs.")
fs.IntVar(&f.MaxConcurrentTasks, "max-concurrent-tasks", f.MaxConcurrentTasks,
"Maximum number of archival tasks to process concurrently or 0 for unlimited.")
fs.IntVar(&f.LeaseBatchSize, "lease-batch-size", f.LeaseBatchSize,
"How many tasks to lease per cycle.")
fs.DurationVar(&f.LeaseTime, "lease-time", f.LeaseTime,
"For how long to lease archival tasks.")
fs.IntVar(&f.ArchiveIndexStreamRange, "archive-index-stream-range", f.ArchiveIndexStreamRange,
"The maximum number of stream indexes between index entries.")
fs.IntVar(&f.ArchiveIndexPrefixRange, "archive-index-prefix-range", f.ArchiveIndexPrefixRange,
"The maximum number of prefix indexes between index entries.")
fs.IntVar(&f.ArchiveIndexByteRange, "archive-index-byte-range", f.ArchiveIndexByteRange,
"The maximum number of log data bytes between index entries.")
}
// Validate returns an error if some parsed flags have invalid values.
func (f *CommandLineFlags) Validate() error {
if f.StagingBucket == "" {
return errors.New("-staging-bucket is required")
}
return nil
}