Skip to content

Commit

Permalink
push.go: expose InitPushExtWithOptions() function, since this it is n…
Browse files Browse the repository at this point in the history
…eede by VictoriaMetrics
  • Loading branch information
valyala committed Dec 17, 2023
1 parent bd3cd7b commit de71953
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit de71953

Please sign in to comment.