-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metrics to v2 api server. (#969)
Signed-off-by: Cody Littley <[email protected]>
- Loading branch information
1 parent
4190d49
commit 4a98d98
Showing
6 changed files
with
200 additions
and
12 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 |
---|---|---|
@@ -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