@@ -154,21 +154,21 @@ func init() {
154154// serverOnlyFlag creates server-only kingpin flag.
155155func serverOnlyFlag (app * kingpin.Application , name , help string ) * kingpin.FlagClause {
156156 return app .Flag (name , fmt .Sprintf ("%s Use with server mode only." , help )).
157- PreAction (func (parseContext * kingpin.ParseContext ) error {
158- // This will be invoked only if flag is actually provided by user.
159- serverOnlyFlags = append (serverOnlyFlags , "--" + name )
160- return nil
161- })
157+ PreAction (func (parseContext * kingpin.ParseContext ) error {
158+ // This will be invoked only if flag is actually provided by user.
159+ serverOnlyFlags = append (serverOnlyFlags , "--" + name )
160+ return nil
161+ })
162162}
163163
164164// agentOnlyFlag creates agent-only kingpin flag.
165165func agentOnlyFlag (app * kingpin.Application , name , help string ) * kingpin.FlagClause {
166166 return app .Flag (name , fmt .Sprintf ("%s Use with agent mode only." , help )).
167- PreAction (func (parseContext * kingpin.ParseContext ) error {
168- // This will be invoked only if flag is actually provided by user.
169- agentOnlyFlags = append (agentOnlyFlags , "--" + name )
170- return nil
171- })
167+ PreAction (func (parseContext * kingpin.ParseContext ) error {
168+ // This will be invoked only if flag is actually provided by user.
169+ agentOnlyFlags = append (agentOnlyFlags , "--" + name )
170+ return nil
171+ })
172172}
173173
174174type flagConfig struct {
@@ -427,6 +427,9 @@ func main() {
427427 serverOnlyFlag (a , "storage.tsdb.wal-compression-type" , "Compression algorithm for the tsdb WAL." ).
428428 Hidden ().Default (string (wlog .CompressionSnappy )).EnumVar (& cfg .tsdb .WALCompressionType , string (wlog .CompressionSnappy ), string (wlog .CompressionZstd ))
429429
430+ serverOnlyFlag (a , "storage.tsdb.wal-version" , fmt .Sprintf ("Version for the new WAL segments. Supported versions: %v" , wlog .ReleasedSupportedSegmentVersions ())).
431+ Default (fmt .Sprintf ("%v" , wlog .DefaultSegmentVersion )).Uint32Var (& cfg .tsdb .WALSegmentVersion )
432+
430433 serverOnlyFlag (a , "storage.tsdb.head-chunks-write-queue-size" , "Size of the queue through which head chunks are written to the disk to be m-mapped, 0 disables the queue completely. Experimental." ).
431434 Default ("0" ).IntVar (& cfg .tsdb .HeadChunksWriteQueueSize )
432435
@@ -443,12 +446,15 @@ func main() {
443446 "Size at which to split WAL segment files. Example: 100MB" ).
444447 Hidden ().PlaceHolder ("<bytes>" ).BytesVar (& cfg .agent .WALSegmentSize )
445448
446- agentOnlyFlag (a , "storage.agent.wal-compression" , "Compress the agent WAL." ).
449+ agentOnlyFlag (a , "storage.agent.wal-compression" , "Compress the new WAL segments ." ).
447450 Default ("true" ).BoolVar (& cfg .agent .WALCompression )
448451
449452 agentOnlyFlag (a , "storage.agent.wal-compression-type" , "Compression algorithm for the agent WAL." ).
450453 Hidden ().Default (string (wlog .CompressionSnappy )).EnumVar (& cfg .agent .WALCompressionType , string (wlog .CompressionSnappy ), string (wlog .CompressionZstd ))
451454
455+ agentOnlyFlag (a , "storage.agent.wal-version" , fmt .Sprintf ("Version for the new WAL segments. Supported versions: %v" , wlog .ReleasedSupportedSegmentVersions ())).
456+ Default (fmt .Sprintf ("%v" , wlog .DefaultSegmentVersion )).Uint32Var (& cfg .agent .WALSegmentVersion )
457+
452458 agentOnlyFlag (a , "storage.agent.wal-truncate-frequency" ,
453459 "The frequency at which to truncate the WAL and remove old data." ).
454460 Hidden ().PlaceHolder ("<duration>" ).SetValue (& cfg .agent .TruncateFrequency )
@@ -1229,6 +1235,10 @@ func main() {
12291235 g .Add (
12301236 func () error {
12311237 logger .Info ("Starting TSDB ..." )
1238+ if ! wlog .SegmentVersion (cfg .tsdb .WALSegmentVersion ).IsReleased () {
1239+ return fmt .Errorf ("flag 'storage.tsdb.wal-version' was set to unsupported WAL segment version %v; supported versions %v" , cfg .tsdb .WALSegmentVersion , wlog .ReleasedSupportedSegmentVersions ())
1240+ }
1241+
12321242 if cfg .tsdb .WALSegmentSize != 0 {
12331243 if cfg .tsdb .WALSegmentSize < 10 * 1024 * 1024 || cfg .tsdb .WALSegmentSize > 256 * 1024 * 1024 {
12341244 return errors .New ("flag 'storage.tsdb.wal-segment-size' must be set between 10MB and 256MB" )
@@ -1285,6 +1295,10 @@ func main() {
12851295 g .Add (
12861296 func () error {
12871297 logger .Info ("Starting WAL storage ..." )
1298+ if ! wlog .SegmentVersion (cfg .agent .WALSegmentVersion ).IsReleased () {
1299+ return fmt .Errorf ("flag 'storage.agent.wal-version' was set to unsupported WAL segment version %v; supported versions %v" , cfg .tsdb .WALSegmentVersion , wlog .ReleasedSupportedSegmentVersions ())
1300+ }
1301+
12881302 if cfg .agent .WALSegmentSize != 0 {
12891303 if cfg .agent .WALSegmentSize < 10 * 1024 * 1024 || cfg .agent .WALSegmentSize > 256 * 1024 * 1024 {
12901304 return errors .New ("flag 'storage.agent.wal-segment-size' must be set between 10MB and 256MB" )
@@ -1492,7 +1506,7 @@ func reloadConfig(filename string, enableExemplarStorage bool, logger *slog.Logg
14921506
14931507func startsOrEndsWithQuote (s string ) bool {
14941508 return strings .HasPrefix (s , "\" " ) || strings .HasPrefix (s , "'" ) ||
1495- strings .HasSuffix (s , "\" " ) || strings .HasSuffix (s , "'" )
1509+ strings .HasSuffix (s , "\" " ) || strings .HasSuffix (s , "'" )
14961510}
14971511
14981512// compileCORSRegexString compiles given string and adds anchors.
@@ -1780,6 +1794,7 @@ func (rm *readyScrapeManager) Get() (*scrape.Manager, error) {
17801794// This is required as tsdb.Option fields are unit agnostic (time).
17811795type tsdbOptions struct {
17821796 WALSegmentSize units.Base2Bytes
1797+ WALSegmentVersion uint32
17831798 MaxBlockChunkSegmentSize units.Base2Bytes
17841799 RetentionDuration model.Duration
17851800 MaxBytes units.Base2Bytes
@@ -1804,12 +1819,15 @@ type tsdbOptions struct {
18041819
18051820func (opts tsdbOptions ) ToTSDBOptions () tsdb.Options {
18061821 return tsdb.Options {
1807- WALSegmentSize : int (opts .WALSegmentSize ),
1822+ WALSegment : wlog.SegmentOptions {
1823+ Version : wlog .SegmentVersion (opts .WALSegmentVersion ),
1824+ Compression : wlog .ParseCompressionType (opts .WALCompression , opts .WALCompressionType ),
1825+ Size : int (opts .WALSegmentSize ),
1826+ },
18081827 MaxBlockChunkSegmentSize : int64 (opts .MaxBlockChunkSegmentSize ),
18091828 RetentionDuration : int64 (time .Duration (opts .RetentionDuration ) / time .Millisecond ),
18101829 MaxBytes : int64 (opts .MaxBytes ),
18111830 NoLockfile : opts .NoLockfile ,
1812- WALCompression : wlog .ParseCompressionType (opts .WALCompression , opts .WALCompressionType ),
18131831 HeadChunksWriteQueueSize : opts .HeadChunksWriteQueueSize ,
18141832 SamplesPerChunk : opts .SamplesPerChunk ,
18151833 StripeSize : opts .StripeSize ,
@@ -1833,6 +1851,7 @@ type agentOptions struct {
18331851 WALSegmentSize units.Base2Bytes
18341852 WALCompression bool
18351853 WALCompressionType string
1854+ WALSegmentVersion uint32
18361855 StripeSize int
18371856 TruncateFrequency model.Duration
18381857 MinWALTime , MaxWALTime model.Duration
@@ -1845,8 +1864,11 @@ func (opts agentOptions) ToAgentOptions(outOfOrderTimeWindow int64) agent.Option
18451864 outOfOrderTimeWindow = 0
18461865 }
18471866 return agent.Options {
1848- WALSegmentSize : int (opts .WALSegmentSize ),
1849- WALCompression : wlog .ParseCompressionType (opts .WALCompression , opts .WALCompressionType ),
1867+ WALSegment : wlog.SegmentOptions {
1868+ Version : wlog .SegmentVersion (opts .WALSegmentVersion ),
1869+ Compression : wlog .ParseCompressionType (opts .WALCompression , opts .WALCompressionType ),
1870+ Size : int (opts .WALSegmentSize ),
1871+ },
18501872 StripeSize : opts .StripeSize ,
18511873 TruncateFrequency : time .Duration (opts .TruncateFrequency ),
18521874 MinWALTime : durationToInt64Millis (time .Duration (opts .MinWALTime )),
0 commit comments