From 6963cf07878d378921123676d91d8419a6592287 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Sun, 22 Sep 2024 22:18:20 +0100 Subject: [PATCH] Add name as service parameter. --- http/deliveredbidtrace.go | 1 + http/parameters.go | 10 +++++++++- http/receivedbidtraces.go | 1 + http/service.go | 12 ++++++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/http/deliveredbidtrace.go b/http/deliveredbidtrace.go index 64b27ee..38be797 100644 --- a/http/deliveredbidtrace.go +++ b/http/deliveredbidtrace.go @@ -31,6 +31,7 @@ import ( // Will return nil if the relay did not deliver a bid for the slot. func (s *Service) DeliveredBidTrace(ctx context.Context, slot phase0.Slot) (*v1.BidTrace, error) { ctx, span := otel.Tracer("attestantio.go-relay-client.http").Start(ctx, "DeliveredBidTrace", trace.WithAttributes( + //nolint:gosec attribute.Int64("slot", int64(slot)), )) defer span.End() diff --git a/http/parameters.go b/http/parameters.go index 7f15369..2ea2b48 100644 --- a/http/parameters.go +++ b/http/parameters.go @@ -1,4 +1,4 @@ -// Copyright © 2022, 2023 Attestant Limited. +// Copyright © 2022 - 2024 Attestant Limited. // 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 @@ -24,6 +24,7 @@ import ( type parameters struct { logLevel zerolog.Level monitor metrics.Service + name string address string timeout time.Duration extraHeaders map[string]string @@ -54,6 +55,13 @@ func WithMonitor(monitor metrics.Service) Parameter { }) } +// WithName provides the name for the endpoint. +func WithName(name string) Parameter { + return parameterFunc(func(p *parameters) { + p.name = name + }) +} + // WithAddress provides the address for the endpoint. func WithAddress(address string) Parameter { return parameterFunc(func(p *parameters) { diff --git a/http/receivedbidtraces.go b/http/receivedbidtraces.go index 7654e42..826e916 100644 --- a/http/receivedbidtraces.go +++ b/http/receivedbidtraces.go @@ -30,6 +30,7 @@ import ( // ReceivedBidTraces provides all bid traces received for a given slot. func (s *Service) ReceivedBidTraces(ctx context.Context, slot phase0.Slot) ([]*v1.BidTraceWithTimestamp, error) { ctx, span := otel.Tracer("attestantio.go-relay-client.http").Start(ctx, "ReceivedBidTraces", trace.WithAttributes( + //nolint:gosec attribute.Int64("slot", int64(slot)), )) defer span.End() diff --git a/http/service.go b/http/service.go index 88656c9..44d74c0 100644 --- a/http/service.go +++ b/http/service.go @@ -1,4 +1,4 @@ -// Copyright © 2022, 2023 Attestant Limited. +// Copyright © 2022 - 2024 Attestant Limited. // 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 @@ -33,6 +33,7 @@ import ( // Service is an Ethereum 2 client service. type Service struct { base *url.URL + name string address string client *http.Client timeout time.Duration @@ -100,8 +101,15 @@ func New(ctx context.Context, params ...Parameter) (builderclient.Service, error // Remove the user from the URL. base.User = nil } + + name := parameters.name + if name == "" { + name = base.String() + } + s := &Service{ base: base, + name: name, address: base.String(), client: client, timeout: parameters.timeout, @@ -121,7 +129,7 @@ func New(ctx context.Context, params ...Parameter) (builderclient.Service, error // Name provides the name of the service. func (s *Service) Name() string { - return s.address + return s.name } // Address provides the address for the connection.