mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 04:54:05 -05:00
adding user agent validator beacon client (#15574)
* adding user agent validator beacon client * Update runtime/version/version.go Co-authored-by: Bastin <43618253+Inspector-Butters@users.noreply.github.com> * test cases * contribution readme * setting user agent to build version data --------- Co-authored-by: Bastin <43618253+Inspector-Butters@users.noreply.github.com>
This commit is contained in:
4
changelog/user-agent-addition-validator-outbound.md
Normal file
4
changelog/user-agent-addition-validator-outbound.md
Normal file
@@ -0,0 +1,4 @@
|
||||
### Added
|
||||
|
||||
- All outbound HTTP requests from the validator client now include a custom `User-Agent` header in the format `Prysm/<name>/<version>`. This enhances observability and enables upstream systems to correctly identify Prysm validator clients by their name and version.
|
||||
- Fixes [#15435](https://github.com/OffchainLabs/prysm/issues/15435).
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/OffchainLabs/prysm/v6/api/apiutil"
|
||||
"github.com/OffchainLabs/prysm/v6/config/params"
|
||||
"github.com/OffchainLabs/prysm/v6/network/httputil"
|
||||
"github.com/OffchainLabs/prysm/v6/runtime/version"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -74,6 +75,7 @@ func (c *BeaconApiRestHandler) Get(ctx context.Context, endpoint string, resp in
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create request for endpoint %s", url)
|
||||
}
|
||||
req.Header.Set("User-Agent", version.BuildData())
|
||||
httpResp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to perform request for endpoint %s", url)
|
||||
@@ -103,6 +105,7 @@ func (c *BeaconApiRestHandler) GetSSZ(ctx context.Context, endpoint string) ([]b
|
||||
o(req)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", version.BuildData())
|
||||
httpResp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "failed to perform request for endpoint %s", url)
|
||||
@@ -162,7 +165,7 @@ func (c *BeaconApiRestHandler) Post(
|
||||
req.Header.Set(headerKey, headerValue)
|
||||
}
|
||||
req.Header.Set("Content-Type", api.JsonMediaType)
|
||||
|
||||
req.Header.Set("User-Agent", version.BuildData())
|
||||
httpResp, err := c.client.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to perform request for endpoint %s", url)
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/OffchainLabs/prysm/v6/api/server/structs"
|
||||
"github.com/OffchainLabs/prysm/v6/config/params"
|
||||
"github.com/OffchainLabs/prysm/v6/network/httputil"
|
||||
"github.com/OffchainLabs/prysm/v6/runtime/version"
|
||||
"github.com/OffchainLabs/prysm/v6/testing/assert"
|
||||
"github.com/OffchainLabs/prysm/v6/testing/require"
|
||||
"github.com/pkg/errors"
|
||||
@@ -36,7 +37,7 @@ func TestGet(t *testing.T) {
|
||||
mux.HandleFunc(endpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||
marshalledJson, err := json.Marshal(genesisJson)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, version.BuildData(), r.Header.Get("User-Agent"))
|
||||
w.Header().Set("Content-Type", api.JsonMediaType)
|
||||
_, err = w.Write(marshalledJson)
|
||||
require.NoError(t, err)
|
||||
@@ -70,6 +71,7 @@ func TestGetSSZ(t *testing.T) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc(endpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.StringContains(t, api.OctetStreamMediaType, r.Header.Get("Accept"))
|
||||
assert.Equal(t, version.BuildData(), r.Header.Get("User-Agent"))
|
||||
w.Header().Set("Content-Type", api.OctetStreamMediaType)
|
||||
_, err := w.Write(expectedBody)
|
||||
require.NoError(t, err)
|
||||
@@ -182,6 +184,7 @@ func TestPost(t *testing.T) {
|
||||
mux.HandleFunc(endpoint, func(w http.ResponseWriter, r *http.Request) {
|
||||
// Make sure the request headers have been set
|
||||
assert.Equal(t, "bar", r.Header.Get("foo"))
|
||||
assert.Equal(t, version.BuildData(), r.Header.Get("User-Agent"))
|
||||
assert.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
|
||||
|
||||
// Make sure the data matches
|
||||
|
||||
Reference in New Issue
Block a user