Skip to content

Commit

Permalink
breaks: rename 'oasis_oasis_' metrics prefix to 'oasis_'
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Jan 22, 2024
1 parent cc6f4bf commit 4fe0847
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 22 deletions.
4 changes: 2 additions & 2 deletions gas/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions indexer/backend_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
6 changes: 3 additions & 3 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion rpc/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions rpc/eth/filters/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion rpc/eth/metrics/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
},
Expand Down
10 changes: 5 additions & 5 deletions rpc/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 9 additions & 4 deletions rpc/oasis/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions server/json_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion storage/psql/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 4fe0847

Please sign in to comment.