From 5b8950ec14685e23711f7a3cae0d71dd76c988a1 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 16 Nov 2024 09:59:56 +0100 Subject: [PATCH 1/6] Open user-agent definition Signed-off-by: Matthieu MOREL --- version/info.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/version/info.go b/version/info.go index 3ca72ab3..f34ecd1b 100644 --- a/version/info.go +++ b/version/info.go @@ -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 fmt.Sprintf("%s/%s", component, Version) } func init() { From 3d71bf0a1fa736a25a330eea2057161cd2f0fd26 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 16 Nov 2024 10:14:24 +0100 Subject: [PATCH 2/6] Create info_test.go Signed-off-by: Matthieu MOREL --- version/info_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 version/info_test.go diff --git a/version/info_test.go b/version/info_test.go new file mode 100644 index 00000000..4007a2d1 --- /dev/null +++ b/version/info_test.go @@ -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")) +} From 4052576a2a1af101bd6316f2cdb501129f36da9e Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 16 Nov 2024 10:15:34 +0100 Subject: [PATCH 3/6] Update version/info.go Co-authored-by: Ben Kochie Signed-off-by: Matthieu MOREL --- version/info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/info.go b/version/info.go index f34ecd1b..c67cc8fb 100644 --- a/version/info.go +++ b/version/info.go @@ -95,7 +95,7 @@ func PrometheusUserAgent() string { } func ComponentUserAgent(component string) string { - return fmt.Sprintf("%s/%s", component, Version) + return component+"/"+Version } func init() { From 7dba901d1ce2f3a453b705a96276d9f65f6614ad Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 16 Nov 2024 10:17:26 +0100 Subject: [PATCH 4/6] Update info_test.go Signed-off-by: Matthieu MOREL --- version/info_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/version/info_test.go b/version/info_test.go index 4007a2d1..4d507f44 100644 --- a/version/info_test.go +++ b/version/info_test.go @@ -14,15 +14,15 @@ package version import ( - "testing" + "testing" "github.com/stretchr/testify/require" - ) +) func TestPrometheusUserAgent(t *testing.T) { - require.Equal(t, "Prometheus/" + Version, PrometheusUserAgent()) + require.Equal(t, "Prometheus/" + Version, PrometheusUserAgent()) } func TestComponentUserAgent(t *testing.T) { - require.Equal(t, "Component/" + Version, ComponentUserAgent("Component")) + require.Equal(t, "Component/" + Version, ComponentUserAgent("Component")) } From 4840ce37acd17bd39dd4aff5a63f12d255723dca Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 16 Nov 2024 10:20:07 +0100 Subject: [PATCH 5/6] Update info.go Signed-off-by: Matthieu MOREL --- version/info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/info.go b/version/info.go index c67cc8fb..61ed1ba3 100644 --- a/version/info.go +++ b/version/info.go @@ -95,7 +95,7 @@ func PrometheusUserAgent() string { } func ComponentUserAgent(component string) string { - return component+"/"+Version + return component + "/" + Version } func init() { From 83d20ca6a98589ed607f1e44a50f844eea4efa74 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sat, 16 Nov 2024 10:20:48 +0100 Subject: [PATCH 6/6] Update info_test.go Signed-off-by: Matthieu MOREL --- version/info_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version/info_test.go b/version/info_test.go index 4d507f44..a3689db9 100644 --- a/version/info_test.go +++ b/version/info_test.go @@ -20,9 +20,9 @@ import ( ) func TestPrometheusUserAgent(t *testing.T) { - require.Equal(t, "Prometheus/" + Version, PrometheusUserAgent()) + require.Equal(t, "Prometheus/"+Version, PrometheusUserAgent()) } func TestComponentUserAgent(t *testing.T) { - require.Equal(t, "Component/" + Version, ComponentUserAgent("Component")) + require.Equal(t, "Component/"+Version, ComponentUserAgent("Component")) }