From 4fe08472e65e508952270078c9e17dcae433ebc2 Mon Sep 17 00:00:00 2001 From: ptrus Date: Mon, 22 Jan 2024 10:57:19 +0100 Subject: [PATCH] breaks: rename 'oasis_oasis_' metrics prefix to 'oasis_' --- gas/backend.go | 4 ++-- indexer/backend_cache.go | 6 +++--- indexer/indexer.go | 6 +++--- rpc/apis.go | 1 - rpc/eth/filters/metrics.go | 4 ++-- rpc/eth/metrics/api.go | 2 +- rpc/metrics/metrics.go | 10 +++++----- rpc/oasis/api.go | 13 +++++++++---- server/json_rpc.go | 6 ++++++ storage/psql/metrics.go | 2 +- 10 files changed, 32 insertions(+), 22 deletions(-) diff --git a/gas/backend.go b/gas/backend.go index 7aa46971..68d91a1b 100644 --- a/gas/backend.go +++ b/gas/backend.go @@ -21,8 +21,8 @@ import ( ) var ( - metricNodeMinPrice = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_oasis_web3_gateway_gas_orcale_node_min_price", Help: "Min gas price periodically queried from the node."}) - metricComputedPrice = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_oasis_web3_gateway_gas_oracle_computed_price", Help: "Computed recommended gas price based on recent full blocks. -1 if none (no recent full blocks)."}) + metricNodeMinPrice = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_web3_gateway_gas_orcale_node_min_price", Help: "Min gas price periodically queried from the node."}) + metricComputedPrice = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_web3_gateway_gas_oracle_computed_price", Help: "Computed recommended gas price based on recent full blocks. -1 if none (no recent full blocks)."}) ) // Backend is the gas price oracle backend. diff --git a/indexer/backend_cache.go b/indexer/backend_cache.go index c9f546ba..36ed48c4 100644 --- a/indexer/backend_cache.go +++ b/indexer/backend_cache.go @@ -27,21 +27,21 @@ const periodicMetricsInterval = 60 * time.Second var ( metricCacheHits = promauto.NewGaugeVec( prometheus.GaugeOpts{ - Name: "oasis_oasis_web3_gateway_cache_hits", + Name: "oasis_web3_gateway_cache_hits", Help: "Number of cache hits.", }, []string{"cache"}, ) metricCacheMisses = promauto.NewGaugeVec( prometheus.GaugeOpts{ - Name: "oasis_oasis_web3_gateway_cache_misses", + Name: "oasis_web3_gateway_cache_misses", Help: "Number of cache misses.", }, []string{"cache"}, ) metricCacheHitRatio = promauto.NewGaugeVec( prometheus.GaugeOpts{ - Name: "oasis_oasis_web3_gateway_cache_hit_ratio", + Name: "oasis_web3_gateway_cache_hit_ratio", Help: "Percent of Hits over all accesses (Hits + Misses).", }, []string{"cache"}, diff --git a/indexer/indexer.go b/indexer/indexer.go index d91d369f..179068ef 100644 --- a/indexer/indexer.go +++ b/indexer/indexer.go @@ -32,9 +32,9 @@ const ( ) var ( - metricBlockIndexed = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_oasis_web3_gateway_block_indexed", Help: "Indexed block heights."}) - metricBlockPruned = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_oasis_web3_gateway_block_pruned", Help: "Pruned block heights."}) - metricHealthy = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_oasis_web3_gateway_health", Help: "1 if gateway healthcheck is reporting as healthy, 0 otherwise."}) + metricBlockIndexed = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_web3_gateway_block_indexed", Help: "Indexed block heights."}) + metricBlockPruned = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_web3_gateway_block_pruned", Help: "Pruned block heights."}) + metricHealthy = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_web3_gateway_indexer_health", Help: "1 if gateway indexer healthcheck is reporting as healthy, 0 otherwise."}) ) // ErrNotHealthy is the error returned if the gateway is unhealthy. diff --git a/rpc/apis.go b/rpc/apis.go index dec4e152..fa1f8b2a 100644 --- a/rpc/apis.go +++ b/rpc/apis.go @@ -48,7 +48,6 @@ func GetRPCAPIs( ethService = ethmetrics.NewMetricsWrapper(ethService, logging.GetLogger("eth_rpc_metrics"), backend) txpoolService = txpool.NewMetricsWrapper(txpoolService) filtersService = filters.NewMetricsWrapper(filtersService) - } apis = append(apis, ethRpc.API{ diff --git a/rpc/eth/filters/metrics.go b/rpc/eth/filters/metrics.go index 76c14c79..77375ee9 100644 --- a/rpc/eth/filters/metrics.go +++ b/rpc/eth/filters/metrics.go @@ -14,7 +14,7 @@ import ( var ( durations = promauto.NewHistogramVec( prometheus.HistogramOpts{ - Name: "oasis_oasis_web3_gateway_subscription_seconds", + Name: "oasis_web3_gateway_subscription_seconds", // Buckets ranging from 1 second to 24 hours. Buckets: []float64{1, 10, 30, 60, 600, 1800, 3600, 7200, 21600, 86400}, Help: "Histogram for the eth subscription API subscriptions duration.", @@ -23,7 +23,7 @@ var ( ) inflightSubs = promauto.NewGaugeVec( prometheus.GaugeOpts{ - Name: "oasis_oasis_web3_gateway_subscription_inflight", + Name: "oasis_web3_gateway_subscription_inflight", Help: "Number of concurrent eth inflight subscriptions.", }, []string{"method_name"}, diff --git a/rpc/eth/metrics/api.go b/rpc/eth/metrics/api.go index bd6d67fc..1d0930be 100644 --- a/rpc/eth/metrics/api.go +++ b/rpc/eth/metrics/api.go @@ -22,7 +22,7 @@ import ( var requestHeights = promauto.NewHistogramVec( prometheus.HistogramOpts{ - Name: "oasis_oasis_web3_gateway_api_request_heights", + Name: "oasis_web3_gateway_api_request_heights", Buckets: []float64{0, 1, 2, 3, 5, 10, 50, 100, 500, 1000}, Help: "Histogram of eth API request heights (difference from the latest height).", }, diff --git a/rpc/metrics/metrics.go b/rpc/metrics/metrics.go index 8b14f849..1e2a1dc5 100644 --- a/rpc/metrics/metrics.go +++ b/rpc/metrics/metrics.go @@ -6,11 +6,11 @@ import ( ) var ( - durations = promauto.NewHistogramVec(prometheus.HistogramOpts{Name: "oasis_oasis_web3_gateway_api_seconds", Buckets: []float64{0.00001, 0.0001, .001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}, Help: "Histogram for the eth API requests duration."}, []string{"method_name"}) - requests = promauto.NewCounterVec(prometheus.CounterOpts{Name: "oasis_oasis_web3_gateway_api_request", Help: "Counter for API requests."}, []string{"method_name"}) - failures = promauto.NewCounterVec(prometheus.CounterOpts{Name: "oasis_oasis_web3_gateway_api_failure", Help: "Counter for API request failures."}, []string{"method_name"}) - successes = promauto.NewCounterVec(prometheus.CounterOpts{Name: "oasis_oasis_web3_gateway_api_success", Help: "Counter for API successful requests."}, []string{"method_name"}) - inflight = promauto.NewGaugeVec(prometheus.GaugeOpts{Name: "oasis_oasis_web3_gateway_api_inflight", Help: "Number of inflight API request."}, []string{"method_name"}) + durations = promauto.NewHistogramVec(prometheus.HistogramOpts{Name: "oasis_web3_gateway_api_seconds", Buckets: []float64{0.00001, 0.0001, .001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}, Help: "Histogram for the eth API requests duration."}, []string{"method_name"}) + requests = promauto.NewCounterVec(prometheus.CounterOpts{Name: "oasis_web3_gateway_api_request", Help: "Counter for API requests."}, []string{"method_name"}) + failures = promauto.NewCounterVec(prometheus.CounterOpts{Name: "oasis_web3_gateway_api_failure", Help: "Counter for API request failures."}, []string{"method_name"}) + successes = promauto.NewCounterVec(prometheus.CounterOpts{Name: "oasis_web3_gateway_api_success", Help: "Counter for API successful requests."}, []string{"method_name"}) + inflight = promauto.NewGaugeVec(prometheus.GaugeOpts{Name: "oasis_web3_gateway_api_inflight", Help: "Number of inflight API request."}, []string{"method_name"}) ) // GetAPIMethodMetrics returns the method metrics for the specified API call. diff --git a/rpc/oasis/api.go b/rpc/oasis/api.go index d0a7b38f..ef3d0df6 100644 --- a/rpc/oasis/api.go +++ b/rpc/oasis/api.go @@ -9,6 +9,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/logging" "github.com/oasisprotocol/oasis-sdk/client-sdk/go/client" "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/core" + "github.com/oasisprotocol/oasis-web3-gateway/server" ) var ErrInternalError = errors.New("internal error") @@ -35,19 +36,23 @@ type CallDataPublicKey struct { type publicAPI struct { client client.RuntimeClient - Logger *logging.Logger + logger *logging.Logger } // NewPublicAPI creates an instance of the Web3 API and accompanying health check. func NewPublicAPI( + ctx context.Context, client client.RuntimeClient, logger *logging.Logger, -) API { - return &publicAPI{client: client, Logger: logger} +) (API, server.HealthCheck) { + health := &healthChecker{ctx: ctx, client: client, logger: logger} + go health.run() + + return &publicAPI{client: client, logger: logger}, health } func (api *publicAPI) CallDataPublicKey(ctx context.Context) (*CallDataPublicKey, error) { - logger := api.Logger.With("method", "oasis_callDataPublicKey") + logger := api.logger.With("method", "oasis_callDataPublicKey") res, err := core.NewV1(api.client).CallDataPublicKey(ctx) if err != nil { logger.Error("failed to fetch public key", "err", err) diff --git a/server/json_rpc.go b/server/json_rpc.go index 5075076f..5a407f02 100644 --- a/server/json_rpc.go +++ b/server/json_rpc.go @@ -11,11 +11,15 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/gorilla/mux" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/rs/cors" "github.com/oasisprotocol/oasis-core/go/common/logging" ) +var metricHealthy = promauto.NewGauge(prometheus.GaugeOpts{Name: "oasis_web3_gateway_health", Help: "1 if gateway healthcheck is reporting as healthy, 0 otherwise."}) + // httpConfig is the JSON-RPC/HTTP configuration. type httpConfig struct { Modules []string @@ -77,9 +81,11 @@ func healthCheckHandler(healthChecks []HealthCheck) func(w http.ResponseWriter, for _, h := range healthChecks { if err := h.Health(); err != nil { w.WriteHeader(http.StatusServiceUnavailable) + metricHealthy.Set(0) return } } + metricHealthy.Set(1) w.WriteHeader(http.StatusOK) } } diff --git a/storage/psql/metrics.go b/storage/psql/metrics.go index 72e90226..dd5867e6 100644 --- a/storage/psql/metrics.go +++ b/storage/psql/metrics.go @@ -13,7 +13,7 @@ import ( "github.com/oasisprotocol/oasis-web3-gateway/storage" ) -var durations = promauto.NewHistogramVec(prometheus.HistogramOpts{Name: "oasis_oasis_web3_gateway_psql_query_seconds", Buckets: []float64{0.001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}, Help: "Histogram for the postgresql query duration."}, []string{"query"}) +var durations = promauto.NewHistogramVec(prometheus.HistogramOpts{Name: "oasis_web3_gateway_psql_query_seconds", Buckets: []float64{0.001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}, Help: "Histogram for the postgresql query duration."}, []string{"query"}) func measureDuration(label string) func() { timer := prometheus.NewTimer(durations.WithLabelValues(label))