-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add metrics to v2 api server. #969
Merged
cody-littley
merged 3 commits into
Layr-Labs:master
from
cody-littley:apiserver-metrics
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package apiserver | ||
|
||
import ( | ||
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"google.golang.org/grpc" | ||
"time" | ||
) | ||
|
||
const namespace = "eigenda_disperser_api" | ||
|
||
// metricsV2 encapsulates the metrics for the v2 API server. | ||
type metricsV2 struct { | ||
grpcServerOption grpc.ServerOption | ||
|
||
getBlobCommitmentLatency *prometheus.SummaryVec | ||
getPaymentStateLatency *prometheus.SummaryVec | ||
disperseBlobLatency *prometheus.SummaryVec | ||
disperseBlobSize *prometheus.GaugeVec | ||
validateDispersalRequestLatency *prometheus.SummaryVec | ||
storeBlobLatency *prometheus.SummaryVec | ||
getBlobStatusLatency *prometheus.SummaryVec | ||
} | ||
|
||
// newAPIServerV2Metrics creates a new metricsV2 instance. | ||
func newAPIServerV2Metrics(registry *prometheus.Registry) *metricsV2 { | ||
grpcMetrics := grpcprom.NewServerMetrics() | ||
registry.MustRegister(grpcMetrics) | ||
|
||
grpcServerOption := grpc.UnaryInterceptor( | ||
grpcMetrics.UnaryServerInterceptor(), | ||
) | ||
|
||
objectives := map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001} | ||
|
||
getBlobCommitmentLatency := promauto.With(registry).NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Namespace: namespace, | ||
Name: "get_blob_commitment_latency_ms", | ||
Help: "The time required to get the blob commitment.", | ||
Objectives: objectives, | ||
}, | ||
[]string{}, | ||
) | ||
|
||
getPaymentStateLatency := promauto.With(registry).NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Namespace: namespace, | ||
Name: "get_payment_state_latency_ms", | ||
Help: "The time required to get the payment state.", | ||
Objectives: objectives, | ||
}, | ||
[]string{}, | ||
) | ||
|
||
disperseBlobLatency := promauto.With(registry).NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Namespace: namespace, | ||
Name: "disperse_blob_latency_ms", | ||
Help: "The time required to disperse a blob.", | ||
Objectives: objectives, | ||
}, | ||
[]string{}, | ||
) | ||
|
||
disperseBlobSize := promauto.With(registry).NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Namespace: namespace, | ||
Name: "disperse_blob_size_bytes", | ||
Help: "The size of the blob in bytes.", | ||
}, | ||
[]string{}, | ||
) | ||
|
||
validateDispersalRequestLatency := promauto.With(registry).NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Namespace: namespace, | ||
Name: "validate_dispersal_request_latency_ms", | ||
Help: "The time required to validate a dispersal request.", | ||
Objectives: objectives, | ||
}, | ||
[]string{}, | ||
) | ||
|
||
storeBlobLatency := promauto.With(registry).NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Namespace: namespace, | ||
Name: "store_blob_latency_ms", | ||
Help: "The time required to store a blob.", | ||
Objectives: objectives, | ||
}, | ||
[]string{}, | ||
) | ||
|
||
getBlobStatusLatency := promauto.With(registry).NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Namespace: namespace, | ||
Name: "get_blob_status_latency_ms", | ||
Help: "The time required to get the blob status.", | ||
Objectives: objectives, | ||
}, | ||
[]string{}, | ||
) | ||
|
||
return &metricsV2{ | ||
grpcServerOption: grpcServerOption, | ||
getBlobCommitmentLatency: getBlobCommitmentLatency, | ||
getPaymentStateLatency: getPaymentStateLatency, | ||
disperseBlobLatency: disperseBlobLatency, | ||
disperseBlobSize: disperseBlobSize, | ||
validateDispersalRequestLatency: validateDispersalRequestLatency, | ||
storeBlobLatency: storeBlobLatency, | ||
getBlobStatusLatency: getBlobStatusLatency, | ||
} | ||
} | ||
|
||
func (m *metricsV2) reportGetBlobCommitmentLatency(duration time.Duration) { | ||
m.getBlobCommitmentLatency.WithLabelValues().Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond)) | ||
} | ||
|
||
func (m *metricsV2) reportGetPaymentStateLatency(duration time.Duration) { | ||
m.getPaymentStateLatency.WithLabelValues().Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond)) | ||
} | ||
|
||
func (m *metricsV2) reportDisperseBlobLatency(duration time.Duration) { | ||
m.disperseBlobLatency.WithLabelValues().Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond)) | ||
} | ||
|
||
func (m *metricsV2) reportDisperseBlobSize(size int) { | ||
m.disperseBlobSize.WithLabelValues().Set(float64(size)) | ||
} | ||
|
||
func (m *metricsV2) reportValidateDispersalRequestLatency(duration time.Duration) { | ||
m.validateDispersalRequestLatency.WithLabelValues().Observe( | ||
float64(duration.Nanoseconds()) / float64(time.Millisecond)) | ||
} | ||
|
||
func (m *metricsV2) reportStoreBlobLatency(duration time.Duration) { | ||
m.storeBlobLatency.WithLabelValues().Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond)) | ||
} | ||
|
||
func (m *metricsV2) reportGetBlobStatusLatency(duration time.Duration) { | ||
m.getBlobStatusLatency.WithLabelValues().Observe(float64(duration.Nanoseconds()) / float64(time.Millisecond)) | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇