MCPcopy Index your code
hub / github.com/prometheus/prometheus / AppendWatcherMetadata

Method AppendWatcherMetadata

storage/remote/queue_manager.go:562–589  ·  view source on GitHub ↗

AppendWatcherMetadata sends metadata to the remote storage. Metadata is sent in batches, but is not parallelized. This is only used for the metadata_config.send setting and 1.x Remote Write.

(ctx context.Context, metadata []scrape.MetricMetadata)

Source from the content-addressed store, hash-verified

560// AppendWatcherMetadata sends metadata to the remote storage. Metadata is sent in batches, but is not parallelized.
561// This is only used for the metadata_config.send setting and 1.x Remote Write.
562func (t *QueueManager) AppendWatcherMetadata(ctx context.Context, metadata []scrape.MetricMetadata) {
563 // no op for any newer proto format, which will cache metadata sent to it from the WAL watcher.
564 if t.protoMsg != remoteapi.WriteV1MessageType {
565 return
566 }
567
568 // 1.X will still get metadata in batches.
569 mm := make([]prompb.MetricMetadata, 0, len(metadata))
570 for _, entry := range metadata {
571 mm = append(mm, prompb.MetricMetadata{
572 MetricFamilyName: entry.MetricFamily,
573 Help: entry.Help,
574 Type: prompb.FromMetadataType(entry.Type),
575 Unit: entry.Unit,
576 })
577 }
578
579 pBuf := proto.NewBuffer(nil)
580 numSends := int(math.Ceil(float64(len(metadata)) / float64(t.mcfg.MaxSamplesPerSend)))
581 for i := range numSends {
582 last := min((i+1)*t.mcfg.MaxSamplesPerSend, len(metadata))
583 err := t.sendMetadataWithBackoff(ctx, mm[i*t.mcfg.MaxSamplesPerSend:last], pBuf)
584 if err != nil {
585 t.metrics.failedMetadataTotal.Add(float64(last - (i * t.mcfg.MaxSamplesPerSend)))
586 t.logger.Error("non-recoverable error while sending metadata", "count", last-(i*t.mcfg.MaxSamplesPerSend), "err", err)
587 }
588 }
589}
590
591func (t *QueueManager) sendMetadataWithBackoff(ctx context.Context, metadata []prompb.MetricMetadata, pBuf *proto.Buffer) error {
592 // Build the WriteRequest with no samples (v1 flow).

Callers

nothing calls this directly

Calls 4

FromMetadataTypeFunction · 0.92
AddMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected