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

Function NewWriteHandler

storage/remote/write_handler.go:60–82  ·  view source on GitHub ↗

NewWriteHandler creates a http.Handler that accepts remote write requests with the given message in acceptedMsgs and writes them to the provided appendable. NOTE(bwplotka): When accepting v2 proto and spec, partial writes are possible as per https://prometheus.io/docs/specs/remote_write_spec_2_0/#p

(logger *slog.Logger, reg prometheus.Registerer, appendable storage.Appendable, acceptedMsgs remoteapi.MessageTypes, ingestSTZeroSample, enableTypeAndUnitLabels, appendMetadata bool)

Source from the content-addressed store, hash-verified

58// NOTE(bwplotka): When accepting v2 proto and spec, partial writes are possible
59// as per https://prometheus.io/docs/specs/remote_write_spec_2_0/#partial-write.
60func NewWriteHandler(logger *slog.Logger, reg prometheus.Registerer, appendable storage.Appendable, acceptedMsgs remoteapi.MessageTypes, ingestSTZeroSample, enableTypeAndUnitLabels, appendMetadata bool) http.Handler {
61 h := &writeHandler{
62 logger: logger,
63 appendable: appendable,
64 samplesWithInvalidLabelsTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
65 Namespace: "prometheus",
66 Subsystem: "api",
67 Name: "remote_write_invalid_labels_samples_total",
68 Help: "The total number of received remote write samples and histogram samples which were rejected due to invalid labels.",
69 }),
70 samplesAppendedWithoutMetadata: promauto.With(reg).NewCounter(prometheus.CounterOpts{
71 Namespace: "prometheus",
72 Subsystem: "api",
73 Name: "remote_write_without_metadata_appended_samples_total",
74 Help: "The total number of received remote write samples (and histogram samples) which were ingested without corresponding metadata.",
75 }),
76
77 ingestSTZeroSample: ingestSTZeroSample,
78 enableTypeAndUnitLabels: enableTypeAndUnitLabels,
79 appendMetadata: appendMetadata,
80 }
81 return remoteapi.NewWriteHandler(h, acceptedMsgs, remoteapi.WithWriteHandlerLogger(logger))
82}
83
84// isHistogramValidationError checks if the error is a native histogram validation error.
85func isHistogramValidationError(err error) bool {

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…