Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add process start time header to client_golang prometheus #1278

Merged
merged 4 commits into from
May 26, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions prometheus/promhttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"strings"
"sync"
"time"

"github.com/prometheus/common/expfmt"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt"
logicalhan marked this conversation as resolved.
Show resolved Hide resolved
)

const (
contentTypeHeader = "Content-Type"
contentEncodingHeader = "Content-Encoding"
acceptEncodingHeader = "Accept-Encoding"
contentTypeHeader = "Content-Type"
contentEncodingHeader = "Content-Encoding"
acceptEncodingHeader = "Accept-Encoding"
processStartTimeHeader = "Process-Start-Time-Unix"
)

var gzipPool = sync.Pool{
Expand Down Expand Up @@ -121,6 +122,9 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
}

h := http.HandlerFunc(func(rsp http.ResponseWriter, req *http.Request) {
if !opts.ProcessStartTime.IsZero() {
rsp.Header().Set(processStartTimeHeader, strconv.FormatInt(opts.ProcessStartTime.Unix(), 10))
}
if inFlightSem != nil {
select {
case inFlightSem <- struct{}{}: // All good, carry on.
Expand Down Expand Up @@ -366,6 +370,14 @@ type HandlerOpts struct {
// (which changes the identity of the resulting series on the Prometheus
// server).
EnableOpenMetrics bool
// ProcessStartTime allows setting process start timevalue that will be exposed
// with "Process-Start-Time-Unix" response header along with the metrics
// payload. This allow callers to have efficient transformations to cumulative
// counters (e.g. OpenTelemetry) or generally _created timestamp estimation per
// scrape target.
// NOTE: This feature is experimental and not covered by OpenMetrics or Prometheus
// exposition format.
logicalhan marked this conversation as resolved.
Show resolved Hide resolved
ProcessStartTime time.Time
}

// gzipAccepted returns whether the client will accept gzip-encoded content.
Expand Down