push.go: expose InitPushExtWithOptions() function, since this it is neede by VictoriaMetrics

This commit is contained in:
Aliaksandr Valialkin 2023-12-17 19:39:36 +02:00
parent bd3cd7b6ff
commit de719538d1
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB

25
push.go
View File

@ -52,7 +52,7 @@ func InitPushWithOptions(ctx context.Context, pushURL string, interval time.Dura
writeMetrics := func(w io.Writer) {
WritePrometheus(w, pushProcessMetrics)
}
return initPushWithOptions(ctx, pushURL, interval, writeMetrics, opts)
return InitPushExtWithOptions(ctx, pushURL, interval, writeMetrics, opts)
}
// InitPushProcessMetrics sets up periodic push for 'process_*' metrics to the given pushURL with the given interval.
@ -115,7 +115,7 @@ func (s *Set) InitPushWithOptions(ctx context.Context, pushURL string, interval
writeMetrics := func(w io.Writer) {
s.WritePrometheus(w)
}
return initPushWithOptions(ctx, pushURL, interval, writeMetrics, opts)
return InitPushExtWithOptions(ctx, pushURL, interval, writeMetrics, opts)
}
// InitPush sets up periodic push for metrics from s to the given pushURL with the given interval.
@ -158,10 +158,27 @@ func InitPushExt(pushURL string, interval time.Duration, extraLabels string, wri
opts := &PushOptions{
ExtraLabels: extraLabels,
}
return initPushWithOptions(context.Background(), pushURL, interval, writeMetrics, opts)
return InitPushExtWithOptions(context.Background(), pushURL, interval, writeMetrics, opts)
}
func initPushWithOptions(ctx context.Context, pushURL string, interval time.Duration, writeMetrics func(w io.Writer), opts *PushOptions) error {
// InitPushExtWithOptions sets up periodic push for metrics obtained by calling writeMetrics with the given interval.
//
// The writeMetrics callback must write metrics to w in Prometheus text exposition format without timestamps and trailing comments.
// See https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md#text-based-format
//
// The periodic push is stopped when the ctx is canceled.
//
// opts may contain additional configuration options if non-nil.
//
// It is recommended pushing metrics to /api/v1/import/prometheus endpoint according to
// https://docs.victoriametrics.com/#how-to-import-data-in-prometheus-exposition-format
//
// It is OK calling InitPushExtWithOptions multiple times with different pushURL -
// in this case metrics are pushed to all the provided pushURL urls.
//
// It is OK calling InitPushExtWithOptions multiple times with different writeMetrics -
// in this case all the metrics generated by writeMetrics callbacks are written to pushURL.
func InitPushExtWithOptions(ctx context.Context, pushURL string, interval time.Duration, writeMetrics func(w io.Writer), opts *PushOptions) error {
// validate pushURL
pu, err := url.Parse(pushURL)
if err != nil {