-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #2143 Adds metrics to ShrexGetter, and ShrexEDS/ShrexND Client and Server (including shrex middleware)
- Loading branch information
1 parent
1329f8b
commit 4d31ad4
Showing
14 changed files
with
311 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
package share | ||
|
||
import ( | ||
"github.com/celestiaorg/celestia-node/share/getters" | ||
"github.com/celestiaorg/celestia-node/share/p2p/peers" | ||
"github.com/celestiaorg/celestia-node/share/p2p/shrexeds" | ||
"github.com/celestiaorg/celestia-node/share/p2p/shrexnd" | ||
) | ||
|
||
// WithPeerManagerMetrics is a utility function that is expected to be | ||
// "invoked" by the fx lifecycle. | ||
func WithPeerManagerMetrics(m *peers.Manager) error { | ||
return m.WithMetrics() | ||
} | ||
|
||
func WithShrexClientMetrics(edsClient *shrexeds.Client, ndClient *shrexnd.Client) error { | ||
err := edsClient.WithMetrics() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return ndClient.WithMetrics() | ||
} | ||
|
||
func WithShrexServerMetrics(edsServer *shrexeds.Server, ndServer *shrexnd.Server) error { | ||
err := edsServer.WithMetrics() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return ndServer.WithMetrics() | ||
} | ||
|
||
func WithShrexGetterMetrics(sg *getters.ShrexGetter) error { | ||
return sg.WithMetrics() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package p2p | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric/global" | ||
"go.opentelemetry.io/otel/metric/instrument" | ||
"go.opentelemetry.io/otel/metric/instrument/syncint64" | ||
"go.opentelemetry.io/otel/metric/unit" | ||
) | ||
|
||
var meter = global.MeterProvider().Meter("shrex/eds") | ||
|
||
var observationTimeout = 100 * time.Millisecond | ||
|
||
type status string | ||
|
||
const ( | ||
StatusInternalErr status = "internal_err" | ||
StatusNotFound status = "not_found" | ||
StatusTimeout status = "timeout" | ||
StatusSuccess status = "success" | ||
StatusRateLimited status = "rate_limited" | ||
) | ||
|
||
type Metrics struct { | ||
totalRequestCounter syncint64.Counter | ||
} | ||
|
||
// ObserveRequests increments the total number of requests sent with the given status as an attribute. | ||
func (m *Metrics) ObserveRequests(count int64, status status) { | ||
if m == nil { | ||
return | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), observationTimeout) | ||
defer cancel() | ||
m.totalRequestCounter.Add(ctx, count, attribute.String("status", string(status))) | ||
} | ||
|
||
func InitClientMetrics(protocol string) (*Metrics, error) { | ||
totalRequestCounter, err := meter.SyncInt64().Counter( | ||
fmt.Sprintf("shrex_%s_client_total_requests", protocol), | ||
instrument.WithUnit(unit.Dimensionless), | ||
instrument.WithDescription(fmt.Sprintf("Total count of sent shrex/%s requests", protocol)), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Metrics{ | ||
totalRequestCounter: totalRequestCounter, | ||
}, nil | ||
} | ||
|
||
func InitServerMetrics(protocol string) (*Metrics, error) { | ||
totalRequestCounter, err := meter.SyncInt64().Counter( | ||
fmt.Sprintf("shrex_%s_server_total_responses", protocol), | ||
instrument.WithUnit(unit.Dimensionless), | ||
instrument.WithDescription(fmt.Sprintf("Total count of sent shrex/%s responses", protocol)), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Metrics{ | ||
totalRequestCounter: totalRequestCounter, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.