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