Skip to content

Commit a318544

Browse files
narqoandyasp
andauthored
version: add UserAgent() (#7264)
Update pkg/util/version/info.go Update pkg/mimirtool/client/client.go Signed-off-by: Vladimir Varankin <[email protected]> Co-authored-by: Andy Asp <[email protected]>
1 parent c13772b commit a318544

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

pkg/mimirtool/client/client.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ const (
2828
)
2929

3030
var (
31-
UserAgent = fmt.Sprintf("mimirtool/%s %s", version.Version, version.Info())
3231
ErrResourceNotFound = errors.New("requested resource not found")
3332
errConflict = errors.New("conflict with current state of target resource")
3433
errTooManyRequests = errors.New("too many requests")
3534
)
3635

36+
// UserAgent returns build information in format suitable to be used in HTTP User-Agent header.
37+
func UserAgent() string {
38+
return fmt.Sprintf("mimirtool/%s %s", version.Version, version.Info())
39+
}
40+
3741
// Config is used to configure a MimirClient.
3842
type Config struct {
3943
User string `yaml:"user"`
@@ -253,6 +257,6 @@ func buildRequest(ctx context.Context, p, m string, endpoint url.URL, payload io
253257
if contentLength >= 0 {
254258
r.ContentLength = contentLength
255259
}
256-
r.Header.Add("User-Agent", UserAgent)
260+
r.Header.Add("User-Agent", UserAgent())
257261
return r, nil
258262
}

pkg/mimirtool/commands/analyse_prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (cmd *PrometheusAnalyzeCommand) parseUsedMetrics() (model.LabelValues, erro
8888

8989
func (cmd *PrometheusAnalyzeCommand) newAPI() (v1.API, error) {
9090
rt := api.DefaultRoundTripper
91-
rt = config.NewUserAgentRoundTripper(client.UserAgent, rt)
91+
rt = config.NewUserAgentRoundTripper(client.UserAgent(), rt)
9292
if cmd.username != "" {
9393
rt = &setTenantIDTransport{
9494
RoundTripper: rt,

pkg/mimirtool/commands/loadgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (c *LoadgenCommand) run(_ *kingpin.ParseContext) error {
139139
URL: &config.URL{URL: writeURL},
140140
Timeout: model.Duration(c.writeTimeout),
141141
Headers: map[string]string{
142-
"User-Agent": client.UserAgent,
142+
"User-Agent": client.UserAgent(),
143143
},
144144
})
145145
if err != nil {

pkg/mimirtool/commands/remote_read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (c *RemoteReadCommand) readClient() (remote.ReadClient, error) {
206206
},
207207
},
208208
Headers: map[string]string{
209-
"User-Agent": client.UserAgent,
209+
"User-Agent": client.UserAgent(),
210210
},
211211
})
212212
if err != nil {

pkg/ruler/remotequerier.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ const (
5252
formatProtobuf = "protobuf"
5353
)
5454

55-
var userAgent = fmt.Sprintf("mimir/%s", version.Version)
5655
var allFormats = []string{formatJSON, formatProtobuf}
5756

5857
// QueryFrontendConfig defines query-frontend transport configuration.
@@ -168,7 +167,7 @@ func (q *RemoteQuerier) Read(ctx context.Context, query *prompb.Query) (*prompb.
168167
{Key: textproto.CanonicalMIMEHeaderKey("Content-Encoding"), Values: []string{"snappy"}},
169168
{Key: textproto.CanonicalMIMEHeaderKey("Accept-Encoding"), Values: []string{"snappy"}},
170169
{Key: textproto.CanonicalMIMEHeaderKey("Content-Type"), Values: []string{"application/x-protobuf"}},
171-
{Key: textproto.CanonicalMIMEHeaderKey("User-Agent"), Values: []string{userAgent}},
170+
{Key: textproto.CanonicalMIMEHeaderKey("User-Agent"), Values: []string{version.UserAgent()}},
172171
{Key: textproto.CanonicalMIMEHeaderKey("X-Prometheus-Remote-Read-Version"), Values: []string{"0.1.0"}},
173172
}),
174173
}
@@ -272,7 +271,7 @@ func (q *RemoteQuerier) createRequest(ctx context.Context, query string, ts time
272271
Url: q.promHTTPPrefix + queryEndpointPath,
273272
Body: body,
274273
Headers: injectHTTPGrpcReadConsistencyHeader(ctx, []*httpgrpc.Header{
275-
{Key: textproto.CanonicalMIMEHeaderKey("User-Agent"), Values: []string{userAgent}},
274+
{Key: textproto.CanonicalMIMEHeaderKey("User-Agent"), Values: []string{version.UserAgent()}},
276275
{Key: textproto.CanonicalMIMEHeaderKey("Content-Type"), Values: []string{mimeTypeFormPost}},
277276
{Key: textproto.CanonicalMIMEHeaderKey("Content-Length"), Values: []string{strconv.Itoa(len(body))}},
278277
{Key: textproto.CanonicalMIMEHeaderKey("Accept"), Values: []string{acceptHeader}},

pkg/util/version/info.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ func Print(program string) string {
7777
func Info() string {
7878
return fmt.Sprintf("(version=%s, branch=%s, revision=%s)", Version, Branch, Revision)
7979
}
80+
81+
// UserAgent returns build information in format suitable to be used in HTTP User-Agent header.
82+
func UserAgent() string {
83+
return fmt.Sprintf("mimir/%s", Version)
84+
}

0 commit comments

Comments
 (0)