Skip to content

Commit

Permalink
Allow custom user-agent definition (#725)
Browse files Browse the repository at this point in the history
* Allow custom user-agent definition

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Ben Kochie <superq@gmail.com>
  • Loading branch information
mmorel-35 and SuperQ authored Nov 16, 2024
1 parent e25286d commit 7ed4523
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions version/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ func GetTags() string {
return computedTags
}

func UserAgent() string {
return "Prometheus/" + Version
func PrometheusUserAgent() string {
return ComponentUserAgent("Prometheus")
}

func ComponentUserAgent(component string) string {
return component + "/" + Version
}

func init() {
Expand Down
28 changes: 28 additions & 0 deletions version/info_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package version

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestPrometheusUserAgent(t *testing.T) {
require.Equal(t, "Prometheus/"+Version, PrometheusUserAgent())
}

func TestComponentUserAgent(t *testing.T) {
require.Equal(t, "Component/"+Version, ComponentUserAgent("Component"))
}

0 comments on commit 7ed4523

Please # to comment.