mirror of
https://github.com/luxfi/vm.git
synced 2026-10-30 15:13:40 +00:00
api/server was an earlier copy of node/server/http that had drifted behind it. Its exported surface was a strict subset of the node's, so this replaces the contents rather than adding a second package: a second server would have meant two Server interfaces, two New, two routers, and no answer to which one a chain should mount on. What arrives with it is the part api/server never had. Mount is the estate's only projection from a zip App to an http.Handler, and it installs Authorize before it serves, so an app cannot reach the router without the node's authorization decision on it. Chain builds the one address a chain answers at, and chain_test walks this module's own source to hold every caller to it. The ZAP-RPC listener and the /v1 prefix come across as well; api/server was still serving /ext. Two files stay behind because they already have homes here. The node's traced_handler duplicates api.TraceHandler, which this package was already calling, so server.go keeps calling it and takes luxfi/trace in place of the node-local trace shim. Two tests do not come across, and neither is dropped from the node. mount_test builds a real Z-Chain from luxfi/chains, which requires luxfi/vm, so importing it here would point the layering back at itself. probe_test needs the Ops app on node/service/health, which api/health does not carry. Both keep running where they are. constants moves to v1.6.4 to agree with the node on the chain segment. The two modules disagreed, v1.6.2 still saying bc where the node says chain, and the address Chain builds has to be the address the node's router serves. newMetrics now reports a duplicate registration instead of returning a half-built set, which is what TestMetricsRegistrationFailure had been asking for and failing to get. That test stays, next to the node's, because the two ask different questions: one registry twice, or two registries once. Co-authored-by: Hanzo Dev <[email protected]>
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package server
|
|
|
|
import (
|
|
"github.com/luxfi/metric"
|
|
)
|
|
|
|
type serverMetrics struct {
|
|
requests metric.CounterVec
|
|
duration metric.HistogramVec
|
|
inflight metric.Gauge
|
|
}
|
|
|
|
func newMetrics(registerer metric.Registerer) (*serverMetrics, error) {
|
|
m := &serverMetrics{
|
|
requests: registerer.NewCounterVec("api_requests_total", "Total number of API requests", []string{"method", "endpoint"}),
|
|
duration: registerer.NewHistogramVec("api_request_duration_seconds", "API request duration in seconds", []string{"method", "endpoint"}, nil),
|
|
inflight: registerer.NewGauge("api_requests_inflight", "Number of inflight API requests"),
|
|
}
|
|
|
|
if err := registerer.Register(metric.AsCollector(m.requests)); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := registerer.Register(metric.AsCollector(m.duration)); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := registerer.Register(metric.AsCollector(m.inflight)); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return m, nil
|
|
}
|