Skip to content

Commit

Permalink
Expose UserAgent and fix User-Agent version source (grafana#2603)
Browse files Browse the repository at this point in the history
* Use prometheus/common/version for reporting build version in User Agent header

Promtail wasn't using github.com/prometheus/common/version for the
User-Agent header when obtaining the build version. Instead, it imported
github.com/grafana/loki/pkg/build which modifies the Prometheus version
package on init.

This causes problems for importers that also import and modify
github.com/prometheus/common/version with their own build information
(i.e., grafana/agent).

This PR changes Promtail to obtain the build info from the common
dependency to obtain the correct build information regardless of
how Promtail is being run.

* expose UserAgent to allow it to be modifiable by importers
  • Loading branch information
rfratto committed Sep 8, 2020
1 parent 1664a98 commit ee67b9c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/promtail/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/common/version"

"github.com/grafana/loki/pkg/build"
"github.com/grafana/loki/pkg/helpers"
"github.com/grafana/loki/pkg/logproto"
)
Expand Down Expand Up @@ -72,7 +72,7 @@ var (
encodedBytes, sentBytes, droppedBytes, sentEntries, droppedEntries,
}

userAgent = fmt.Sprintf("promtail/%s", build.Version)
UserAgent = fmt.Sprintf("promtail/%s", version.Version)
)

func init() {
Expand Down Expand Up @@ -262,7 +262,7 @@ func (c *client) send(ctx context.Context, tenantID string, buf []byte) (int, er
}
req = req.WithContext(ctx)
req.Header.Set("Content-Type", contentType)
req.Header.Set("User-Agent", userAgent)
req.Header.Set("User-Agent", UserAgent)

// If the tenant ID is not empty promtail is running in multi-tenant mode, so
// we should send it to Loki
Expand Down

0 comments on commit ee67b9c

Please sign in to comment.