Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/fabric-api/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/metrics"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

fabricapi "go.datum.net/galactic/internal/fabric/api/v1alpha1"
Expand Down Expand Up @@ -268,7 +267,7 @@ func runGateway(parent context.Context, o *gatewayOptions) error {
}

executor := gateway.NewExecutor(o.slots, o.expensiveSlots, o.queue)
metrics := gateway.NewMetrics(ctrlmetrics.Registry, func() float64 { return float64(executor.Depth()) })
metrics := gateway.NewMetrics(func() float64 { return float64(executor.Depth()) })
var admission *gateway.Admission
if o.aggregateBudgets {
admission, err = gateway.NewAdmission(o.limits, &limit.Authority{
Expand Down
7 changes: 4 additions & 3 deletions cmd/fabric-api/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"github.com/spf13/cobra"
instmetrics "go.miloapis.com/instrumentation/metrics"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
grpchealth "google.golang.org/grpc/health"
Expand Down Expand Up @@ -250,7 +251,7 @@ func runNode(parent context.Context, o *nodeOptions) error {
if metricsAddr == "" {
metricsAddr = net.JoinHostPort(hostIP.String(), "9345")
}
stopMetrics := serveMetrics(metricsAddr, metrics.Handler())
stopMetrics := serveMetrics(metricsAddr, instmetrics.Handler())
defer stopMetrics()

slog.Info("starting fabric-api node", "version", metadata.Version, "nodeName", o.nodeName, "site", o.site,
Expand Down Expand Up @@ -318,12 +319,12 @@ func nodePermits(o *nodeOptions, creds *identity.Credentials, metrics *node.Metr
func idleUnconfigured(parent context.Context, hostIP netip.Addr, o *nodeOptions) error {
ctx, stop := signalContext(parent)
defer stop()
metrics := node.NewMetrics()
node.NewMetrics()
addr := o.metricsAddress
if addr == "" {
addr = net.JoinHostPort(hostIP.String(), "9345")
}
stopMetrics := serveMetrics(addr, metrics.Handler())
stopMetrics := serveMetrics(addr, instmetrics.Handler())
defer stopMetrics()
slog.Error("fabric-api node is not configured: --cell (CELL) is empty; diagnostics are unavailable until it is set")
<-ctx.Done()
Expand Down
23 changes: 14 additions & 9 deletions cmd/fabric-api/scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ import (
"go.miloapis.com/instrumentation/instrumenttest"
"go.miloapis.com/instrumentation/metrics"

"go.datum.net/galactic/internal/fabric/gateway"
"go.datum.net/galactic/internal/fabric/index"
"go.datum.net/galactic/internal/fabric/node"
)

// TestMetricsScrape scrapes both roles' /metrics: the gateway's manager
// serves controller-runtime's registry, which metrics.Handler serves
// unchanged, and the node sidecar serves its own registry.
// TestMetricsScrape scrapes what both roles serve at /metrics, the
// instrumentation library's registry, once it holds the series each creates
// at startup, and lints them. Both roles define the certificate and
// credential gauges, so this also checks that their definitions agree. The
// gateway's admission and service switch gauges read a running cell, so they
// are left out.
func TestMetricsScrape(t *testing.T) {
t.Run("gateway", func(t *testing.T) {
instrumenttest.AssertScrapes(t, metrics.Handler())
})
t.Run("node", func(t *testing.T) {
instrumenttest.AssertScrapes(t, node.NewMetrics().Handler())
})
gateway.NewMetrics(func() float64 { return 0 })
m := node.NewMetrics()
m.RegisterClock(func() error { return nil })
m.RegisterIndex(index.New())
instrumenttest.AssertScrapes(t, metrics.Handler())
instrumenttest.Lint(t)
}
2 changes: 1 addition & 1 deletion docs/fabric-api/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ All are `severity: warning`, `service: galactic`, `team: connect`. A deployment
evaluates its own copy of the rules changes them here first, with their tests, then
updates that copy.

Node metrics (port 9345, a private registry with Go and process collectors):
Node metrics (port 9345, beside the Go runtime and process series):
`fabric_api_node_requests_total{type,outcome}`,
`fabric_api_node_request_duration_seconds{type}`,
`fabric_api_node_response_bytes{type}`,
Expand Down
29 changes: 16 additions & 13 deletions docs/observability/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,28 @@ Create every metric with the constructors in
[`go.miloapis.com/instrumentation/metrics`](https://github.com/milo-os/instrumentation),
and register a collector that reads state at scrape time with its
`metrics.MustRegister`. Both put the metric on controller-runtime's registry,
which every controller-runtime manager serves and `galactic-cni` and
`fabric-config-agent` serve with the library's `metrics.Handler`. The
fabric-api node sidecar serves only its own registry, so a library metric
linked into it is not exported until it serves the library's handler. The
tests in `internal/instrumentation` enforce the rule in the unit suite:
which every controller-runtime manager serves. `galactic-cni`,
`fabric-config-agent` and the fabric-api node sidecar, which serve metrics
without a manager, serve that registry with the library's `metrics.Handler`.

A metric created when its package loads is exported by every binary that
links the package. Where only some of them should export it, create it in a
constructor the binary calls at startup instead. The library's registry keeps
a series across calls, so a constructor that tests call repeatedly starts its
vectors over, and creates a function metric, which the library allows only
once per process, on its first call.

The tests in `internal/instrumentation` enforce the rule in the unit suite:

- `TestAdopted` runs the library's adoption check, which fails on a metric
registered outside the library and on a logger the library didn't build.
- `TestNoMetricsOutsideLibrary` fails on any metric constructor or registry
from `client_golang`'s `prometheus` package, including one passed in as a
`prometheus.Registerer`.
- `TestMetricsLint` checks every library metric's name against Prometheus
conventions. It imports each package that defines one, and
`TestLintLinksEveryMetric` fails when a package is missing from that list
or defines its metrics in a command's `main` package.
- `TestMetricsLint` checks the name of every library metric created when a
package loads against Prometheus conventions. It imports each package that
defines one, and `TestLintLinksEveryMetric` fails when a package is missing
from that list or creates a metric in a command's `main` package.
- Each command that serves `/metrics` has a `TestMetricsScrape`, which fails
when two registries export the same series. `TestEveryBinaryHasScrapeTest`
requires one for every new command, but can't tell whether the test scrapes
Expand All @@ -44,10 +51,6 @@ tests in `internal/instrumentation` enforce the rule in the unit suite:
first creates them through the same function the command calls, and also
runs the library's lint, which `TestMetricsLint` can't reach.

Both source checks skip the directories in `pending` in
`internal/instrumentation/adoption_test.go`, which haven't moved to the
library yet.

## Where the metrics come from

The dataplane and fabric-router DaemonSets use `hostNetwork: true`, so
Expand Down
Loading
Loading