Skip to content

Commit 42fc288

Browse files
committed
Add mechanism for choosing between the two metadata-sending methods, defaulting to the new one
Signed-off-by: Paschalis Tsilias <[email protected]>
1 parent 7ee3ae6 commit 42fc288

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

cmd/prometheus/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func main() {
413413
a.Flag("scrape.discovery-reload-interval", "Interval used by scrape manager to throttle target groups updates.").
414414
Hidden().Default("5s").SetValue(&cfg.scrape.DiscoveryReloadInterval)
415415

416-
a.Flag("enable-feature", "Comma separated feature names to enable. Valid options: agent, exemplar-storage, expand-external-labels, memory-snapshot-on-shutdown, promql-at-modifier, promql-negative-offset, promql-per-step-stats, remote-write-receiver (DEPRECATED), extra-scrape-metrics, new-service-discovery-manager, auto-gomaxprocs, no-default-scrape-port, native-histograms. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details.").
416+
a.Flag("enable-feature", "Comma separated feature names to enable. Valid options: agent, exemplar-storage, expand-external-labels, memory-snapshot-on-shutdown, promql-at-modifier, promql-negative-offset, promql-per-step-stats, remote-write-receiver (DEPRECATED), extra-scrape-metrics, new-service-discovery-manager, auto-gomaxprocs, no-default-scrape-port, native-histograms, metadata-storage. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details.").
417417
Default("").StringsVar(&cfg.featureList)
418418

419419
promlogflag.AddFlags(a, &cfg.promlogConfig)
@@ -500,6 +500,12 @@ func main() {
500500
cfg.tsdb.OutOfOrderTimeWindow = cfgFile.StorageConfig.TSDBConfig.OutOfOrderTimeWindow
501501
}
502502

503+
for _, rwc := range cfgFile.RemoteWriteConfigs {
504+
if rwc.SendWALMetadata && !cfg.scrape.EnableMetadataStorage {
505+
level.Warn(logger).Log("msg", "the 'send_metadata' remote_write parameter must be set along the --enable-features=metadata-storage flag to take effect")
506+
}
507+
}
508+
503509
// Now that the validity of the config is established, set the config
504510
// success metrics accordingly, although the config isn't really loaded
505511
// yet. This will happen later (including setting these metrics again),

docs/feature_flags.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,12 @@ still ingest those conventional histograms that do not come with a
126126
corresponding native histogram. However, if a native histogram is present,
127127
Prometheus will ignore the corresponding conventional histogram, with the
128128
notable exception of exemplars, which are always ingested.
129+
130+
## Metadata Storage
131+
`--enable-features=metadata-storage`
132+
133+
When enabled, Prometheus will store metadata in-memory and keep track of
134+
metadata changes as WAL records. This should be used along the remote write's
135+
`send_metadata` parameter.
136+
This new way of storing and sending metadata is mutually exclusive with the
137+
`metadata_config.send` field and the current way of sending metadata.

storage/remote/queue_manager_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,6 @@ func (c *TestWriteClient) waitForExpectedData(tb testing.TB) {
861861
}
862862
}
863863

864-
var emptyMetadata prompb.Metadata
865-
866864
func (c *TestWriteClient) Store(_ context.Context, req []byte) error {
867865
c.mtx.Lock()
868866
defer c.mtx.Unlock()

storage/remote/write.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/go-kit/log"
24+
"github.com/go-kit/log/level"
2425
"github.com/prometheus/client_golang/prometheus"
2526
"github.com/prometheus/client_golang/prometheus/promauto"
2627

@@ -145,6 +146,15 @@ func (rws *WriteStorage) ApplyConfig(conf *config.Config) error {
145146
return fmt.Errorf("duplicate remote write configs are not allowed, found duplicate for URL: %s", rwConf.URL)
146147
}
147148

149+
// The current MetadataWatcher implementation is mutually exclusive
150+
// with the new approach, which stores metadata as WAL records and
151+
// ships them alongside series. If both mechanisms are set, the new one
152+
// takes precedence by implicitly disabling the older one.
153+
if rwConf.MetadataConfig.Send && rwConf.SendWALMetadata {
154+
level.Warn(rws.logger).Log("msg", "the 'send_metadata' and 'metadata_config.send' parameters are mutually exclusive; defaulting to use 'send_metadata'")
155+
rwConf.MetadataConfig.Send = false
156+
}
157+
148158
// Set the queue name to the config hash if the user has not set
149159
// a name in their remote write config so we can still differentiate
150160
// between queues that have the same remote write endpoint.

storage/remote/write_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,43 @@ func TestWriteStorageApplyConfigsPartialUpdate(t *testing.T) {
373373
err = s.Close()
374374
require.NoError(t, err)
375375
}
376+
377+
func TestMetadataStorageMechanismPreference(t *testing.T) {
378+
dir := t.TempDir()
379+
s := NewWriteStorage(nil, nil, dir, defaultFlushDeadline, nil)
380+
381+
c0 := &config.RemoteWriteConfig{
382+
RemoteTimeout: model.Duration(10 * time.Second),
383+
QueueConfig: config.DefaultQueueConfig,
384+
WriteRelabelConfigs: []*relabel.Config{
385+
{
386+
Regex: relabel.MustNewRegexp(".+"),
387+
},
388+
},
389+
SendWALMetadata: true,
390+
MetadataConfig: config.DefaultMetadataConfig, // MetadataConfig.Send defaults to true
391+
}
392+
conf := &config.Config{
393+
GlobalConfig: config.GlobalConfig{},
394+
RemoteWriteConfigs: []*config.RemoteWriteConfig{c0},
395+
}
396+
// We need to set URL's so that metric creation doesn't panic.
397+
for i := range conf.RemoteWriteConfigs {
398+
conf.RemoteWriteConfigs[i].URL = &common_config.URL{
399+
URL: &url.URL{
400+
Host: "http://test-storage.com",
401+
},
402+
}
403+
}
404+
hash, err := toHash(conf.RemoteWriteConfigs[0])
405+
require.NoError(t, err)
406+
407+
require.NoError(t, s.ApplyConfig(conf))
408+
409+
require.Len(t, s.queues, 1)
410+
411+
// When both SendWALMetadata and MetadataConfig.Send are set to true,
412+
// default to only using the new mechanism.
413+
require.True(t, s.queues[hash].sendMetadata)
414+
require.False(t, s.queues[hash].mcfg.Send)
415+
}

0 commit comments

Comments
 (0)