diff --git a/benchmarking/atunnel/internal/workerhost/workerhost.go b/benchmarking/atunnel/internal/workerhost/workerhost.go index 232e0f4499..a29ae8e2bb 100644 --- a/benchmarking/atunnel/internal/workerhost/workerhost.go +++ b/benchmarking/atunnel/internal/workerhost/workerhost.go @@ -29,6 +29,8 @@ import ( "strconv" "sync" + "go.opentelemetry.io/otel/metric/noop" + "go.ate.dev/substrate/internal/ateworker/actornet" "go.ate.dev/substrate/internal/atunnel" "go.ate.dev/substrate/internal/nodepath" @@ -76,7 +78,7 @@ type actor struct { // Start starts atunnel from cfg, as a worker's main does, and hosts actors // actors whose egress tunnels to gatewayAddress. func Start(ctx context.Context, cfg atunnel.Config, actors int, gatewayAddress string) (*Host, error) { - t, err := atunnel.Start(ctx, cfg, actornet.ActorHTTPUpstream) + t, err := atunnel.Start(ctx, cfg, actornet.ActorHTTPUpstream, noop.Meter{}) if err != nil { return nil, err } diff --git a/cmd/ateworker-gvisor/main.go b/cmd/ateworker-gvisor/main.go index d42598a5cd..75905878fa 100644 --- a/cmd/ateworker-gvisor/main.go +++ b/cmd/ateworker-gvisor/main.go @@ -263,7 +263,7 @@ func do(ctx context.Context) error { } actorLogger := actorlog.NewActorLogger(syncedWriter, metadata.OnGCE()) - tunnel, err := atunnel.Start(ctx, *tunnelConfig, actornet.ActorHTTPUpstream) + tunnel, err := atunnel.Start(ctx, *tunnelConfig, actornet.ActorHTTPUpstream, mp.Meter(serviceName)) if err != nil { return err } diff --git a/cmd/ateworker-microvm/main.go b/cmd/ateworker-microvm/main.go index 845f26d006..8fba5830f9 100644 --- a/cmd/ateworker-microvm/main.go +++ b/cmd/ateworker-microvm/main.go @@ -234,7 +234,7 @@ func do(ctx context.Context) error { return fmt.Errorf("while delegating the worker cgroup: %w", err) } - tunnel, err := atunnel.Start(ctx, *tunnelConfig, actornet.ActorHTTPUpstream) + tunnel, err := atunnel.Start(ctx, *tunnelConfig, actornet.ActorHTTPUpstream, mp.Meter(serviceName)) if err != nil { return err } diff --git a/docs/guides/observability.md b/docs/guides/observability.md index 8969b174fe..0fc3dc7b30 100644 --- a/docs/guides/observability.md +++ b/docs/guides/observability.md @@ -305,6 +305,7 @@ Agent Substrate emits foundational OpenTelemetry system and server metrics to mo | `ate.filecache.size` | atelet | up/down counter | bytes of disk a node-local file cache occupies, by `ate.filecache.name`, read on each collection; compare with `--sandbox-asset-cache-max-bytes` | | `ate.filecache.evictions` | atelet | counter | entries the eviction passes removed from a node-local file cache, by `ate.filecache.name`; a steady rate at the budget means the cache thrashes and actors pay for downloads again | | `ate.filecache.gc.passes` | atelet | counter | eviction passes over a node-local file cache, by `ate.filecache.name`, that had work to do, by outcome (`ate.filecache.gc.outcome`: `complete`, `shortfall`, `skipped`); a pass within budget is not counted | +| `ate.dns.queries` | ateworker-gvisor & ateworker-microvm | counter | actor DNS queries the sandbox DNS relay checked against the actor's egress policy, by `ate.dns.decision` (`allowed` or `denied`); a denied query gets `NXDOMAIN`, and most lookups also cause denials for the worker pod's search domains, which resolvers try first | The table lists the OpenTelemetry instrument names. How a name appears in a query depends on the backend (Cloud Monitoring (GMP) / Kind collector). diff --git a/docs/metrics/registry/metrics.yaml b/docs/metrics/registry/metrics.yaml index 93d4214b07..3c21c7e1b3 100644 --- a/docs/metrics/registry/metrics.yaml +++ b/docs/metrics/registry/metrics.yaml @@ -634,6 +634,30 @@ groups: value: skipped brief: The pass could not size the cache and removed nothing. It retries on the next tick. + - id: registry.ate.dns + type: attribute_group + brief: > + The labels of the DNS relay of the sandbox. The relay checks each DNS + query of the actor against the egress policy of the actor. + attributes: + - id: ate.dns.decision + stability: development + brief: The decision of the egress policy on one DNS query. + type: + members: + - id: allowed + stability: development + value: allowed + brief: A rule of the policy allows the name. The relay sends the query to the resolvers of the worker pod. + - id: denied + stability: development + value: denied + brief: > + No rule allows the name, or the relay could not fetch the + policy and holds no earlier copy. The relay answers NXDOMAIN. + Thus the actor sees the same error as for a name that does not + exist. + - id: registry.ate.stats type: attribute_group brief: The labels of the resource measurements of the actors. @@ -1598,6 +1622,35 @@ groups: - ref: ate.router.outcome requirement_level: required + # --------------------------------------------------------------------------- + # Metrics. ateworker + # --------------------------------------------------------------------------- + + - id: metric.ate.dns.queries + type: metric + metric_name: ate.dns.queries + instrument: counter + unit: "{query}" + stability: development + brief: The number of actor DNS queries that the DNS relay of the sandbox checked against the egress policy, by decision. + note: > + The sandbox keeps the search domains of the worker pod and ndots:5. Thus + a stub resolver tries the search domains before most names, and most + lookups cause denials, even when a rule allows the name. Compare the + denied rate with its usual level. A rise means that egress policies block + names that actors look up. The actor sees only "bad address" or "could + not resolve host". The relay does not count a query that it drops or + rejects before the policy check, such as a malformed query. + annotations: + substrate: + emitted_by: [ateworker-gvisor, ateworker-microvm] + golden_signals: [traffic, errors] + code_anchor: internal/atunnel/dns/metrics.go + cuj: Actors cannot resolve external names. Does an egress policy deny them? + attributes: + - ref: ate.dns.decision + requirement_level: required + # --------------------------------------------------------------------------- # Metrics. Upstream instrumentation # --------------------------------------------------------------------------- @@ -1611,9 +1664,8 @@ groups: brief: The time, the rate and the errors of each gRPC method on the server. note: > The otelgrpc interceptor sends this instrument. The code of Substrate does - not make it. This instrument is the only metric of ateworker. ateworker has it on - the gRPC interface that atelet calls. credprovider is the - kubernetes-secrets credential provider in + not make it. ateworker has it on the gRPC interface that atelet calls. + credprovider is the kubernetes-secrets credential provider in cmd/credential-provider/kubernetes-secrets. annotations: substrate: diff --git a/internal/ateattr/ateattr.go b/internal/ateattr/ateattr.go index 5f55a8b2c3..e7161cc1a2 100644 --- a/internal/ateattr/ateattr.go +++ b/internal/ateattr/ateattr.go @@ -167,6 +167,7 @@ const ( RouterResumeKey = attribute.Key("ate.router.resume") RouterOutcomeKey = attribute.Key("ate.router.outcome") StatsSourceKey = attribute.Key("ate.stats.source") + DNSDecisionKey = attribute.Key("ate.dns.decision") ) // Keys of the actor usage record. Logs only: the measurements are unbounded and @@ -239,6 +240,13 @@ const ( ImageCacheOutcomeTimeout = "timeout" ) +// Values for DNSDecisionKey: whether the actor's egress policy let the sandbox +// DNS relay forward a query. The relay answers a denied query with NXDOMAIN. +const ( + DNSDecisionAllowed = "allowed" + DNSDecisionDenied = "denied" +) + // Values for FileCacheNameKey. const ( // FileCacheSandboxAsset is the sandbox asset cache: the runsc binaries, diff --git a/internal/atunnel/dns/dnshandler.go b/internal/atunnel/dns/dnshandler.go index ae19e99c7e..46bc2ee2e6 100644 --- a/internal/atunnel/dns/dnshandler.go +++ b/internal/atunnel/dns/dnshandler.go @@ -61,9 +61,10 @@ type dnsHandler struct { pending *pendingRequests limiter *limiter allow queryPolicy + metrics *metrics } -func newDNSHandler(pending *pendingRequests, lim *limiter, allow queryPolicy) *dnsHandler { +func newDNSHandler(pending *pendingRequests, lim *limiter, allow queryPolicy, metrics *metrics) *dnsHandler { if allow == nil { allow = func(dnsmessage.Question) bool { return true } } @@ -71,6 +72,7 @@ func newDNSHandler(pending *pendingRequests, lim *limiter, allow queryPolicy) *d pending: pending, limiter: lim, allow: allow, + metrics: metrics, } } @@ -122,7 +124,9 @@ func (h *dnsHandler) onRequestCommon(raw []byte) (dnsmessage.Header, dnsmessage. // Note: NXDOMAIN seems to interact better with application stacks than other // error codes such as REFUSED. cq := canonicalizeQuestion(q) - if !h.allow(cq) { + allowed := h.allow(cq) + h.metrics.recordQuery(allowed) + if !allowed { return hdr, dnsmessage.Question{}, action{ kind: actionReply, payload: protocol.NXDomainPacket(hdr, q), diff --git a/internal/atunnel/dns/dnshandler_test.go b/internal/atunnel/dns/dnshandler_test.go index f07061b9da..a4480c7774 100644 --- a/internal/atunnel/dns/dnshandler_test.go +++ b/internal/atunnel/dns/dnshandler_test.go @@ -76,7 +76,7 @@ func TestDNSHandlerOnRequestDrop(t *testing.T) { connections: &limiterSlots{max: 1}, } pending := newPendingRequests(lim) - h := newDNSHandler(pending, lim, nil) + h := newDNSHandler(pending, lim, nil, nil) upstreams := []string{"10.96.0.10:53"} // 1. Short packet (< 12 bytes). @@ -110,7 +110,7 @@ func TestDNSHandlerOnRequestSynthesizedReplies(t *testing.T) { allow := func(q dnsmessage.Question) bool { return q.Name.String() != "blocked.example.com." && q.Type != dnsmessage.TypeTXT } - h := newDNSHandler(pending, lim, allow) + h := newDNSHandler(pending, lim, allow, nil) upstreams := []string{"10.96.0.10:53"} qExample := dnsmessage.Question{ @@ -246,7 +246,7 @@ func TestDNSHandlerOnRequestSynthesizedReplies(t *testing.T) { func TestDNSHandlerUDPForwardAndResponseValidation(t *testing.T) { lim := newLimiter() pending := newPendingRequests(lim) - h := newDNSHandler(pending, lim, nil) + h := newDNSHandler(pending, lim, nil, nil) upstream1 := &net.UDPAddr{IP: net.ParseIP("10.96.0.10"), Port: 53} upstream2 := &net.UDPAddr{IP: net.ParseIP("10.96.0.11"), Port: 53} @@ -358,7 +358,7 @@ func TestDNSHandlerUDPForwardAndResponseValidation(t *testing.T) { func TestDNSHandlerTCPForwardAndResponseValidation(t *testing.T) { lim := newLimiter() pending := newPendingRequests(lim) - h := newDNSHandler(pending, lim, nil) + h := newDNSHandler(pending, lim, nil, nil) query := dnsQuery(0xbeef) act := h.onTCPRequest(bytes.Clone(query)) diff --git a/internal/atunnel/dns/metrics.go b/internal/atunnel/dns/metrics.go new file mode 100644 index 0000000000..00759ae9e7 --- /dev/null +++ b/internal/atunnel/dns/metrics.go @@ -0,0 +1,57 @@ +// Copyright 2026 The Agent Substrate Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dns + +import ( + "context" + "fmt" + + "go.opentelemetry.io/otel/metric" + + "go.ate.dev/substrate/internal/ateattr" +) + +const queriesMetric = "ate.dns.queries" + +// metrics holds the DNS relay's metric instruments. A nil *metrics is a valid +// no-op, so call sites need no guard. +type metrics struct { + queries metric.Int64Counter +} + +// newMetrics creates the DNS relay's metric instruments against meter. +func newMetrics(meter metric.Meter) (*metrics, error) { + queries, err := meter.Int64Counter( + queriesMetric, + metric.WithUnit("{query}"), + metric.WithDescription("Number of actor DNS queries the sandbox DNS relay checked against the actor's egress policy, by decision."), + ) + if err != nil { + return nil, fmt.Errorf("create %s counter: %w", queriesMetric, err) + } + return &metrics{queries: queries}, nil +} + +// recordQuery counts one query the egress policy allowed or denied. +func (m *metrics) recordQuery(allowed bool) { + if m == nil { + return + } + decision := ateattr.DNSDecisionDenied + if allowed { + decision = ateattr.DNSDecisionAllowed + } + m.queries.Add(context.Background(), 1, metric.WithAttributes(ateattr.DNSDecisionKey.String(decision))) +} diff --git a/internal/atunnel/dns/metrics_test.go b/internal/atunnel/dns/metrics_test.go new file mode 100644 index 0000000000..cb0bfda52d --- /dev/null +++ b/internal/atunnel/dns/metrics_test.go @@ -0,0 +1,122 @@ +// Copyright 2026 The Agent Substrate Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dns + +import ( + "context" + "os" + "path/filepath" + "testing" + + "github.com/google/go-cmp/cmp" + sdkmetric "go.opentelemetry.io/otel/sdk/metric" + "go.opentelemetry.io/otel/sdk/metric/metricdata" + "golang.org/x/net/dns/dnsmessage" + + "go.ate.dev/substrate/internal/ateattr" +) + +// collectQueries returns the ate.dns.queries count for each ate.dns.decision. +func collectQueries(t *testing.T, reader *sdkmetric.ManualReader) map[string]int64 { + t.Helper() + var rm metricdata.ResourceMetrics + if err := reader.Collect(context.Background(), &rm); err != nil { + t.Fatalf("collect: %v", err) + } + got := make(map[string]int64) + for _, sm := range rm.ScopeMetrics { + for _, m := range sm.Metrics { + if m.Name != queriesMetric { + continue + } + if m.Unit != "{query}" { + t.Errorf("unit = %q, want {query}", m.Unit) + } + sum, ok := m.Data.(metricdata.Sum[int64]) + if !ok { + t.Fatalf("data type = %T, want Sum[int64]", m.Data) + } + if !sum.IsMonotonic { + t.Error("IsMonotonic = false, want true") + } + for _, dp := range sum.DataPoints { + if dp.Attributes.Len() != 1 { + t.Errorf("attributes = %v, want only %s", dp.Attributes.ToSlice(), ateattr.DNSDecisionKey) + } + v, _ := dp.Attributes.Value(ateattr.DNSDecisionKey) + got[v.AsString()] += dp.Value + } + } + } + return got +} + +// TestQueriesCountsPolicyDecisions: every query the egress policy judges is +// counted once, on either transport. A malformed query never reaches the +// policy and is not counted. +func TestQueriesCountsPolicyDecisions(t *testing.T) { + reader := sdkmetric.NewManualReader() + m, err := newMetrics(sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)).Meter("ateworker-gvisor")) + if err != nil { + t.Fatalf("newMetrics: %v", err) + } + lim := newLimiter() + allow := func(q dnsmessage.Question) bool { return q.Name.String() != "blocked.example.com." } + h := newDNSHandler(newPendingRequests(lim), lim, allow, m) + upstreams := []string{"10.96.0.10:53"} + + allowed, _ := dnsQueryForName(t, 1, "example.com.") + denied, _ := dnsQueryForName(t, 2, "blocked.example.com.") + h.onUDPRequest(allowed, nil, upstreams) + h.onTCPRequest(allowed) + h.onUDPRequest(denied, nil, upstreams) + h.onTCPRequest(denied) + h.onTCPRequest(buildTestMessage(t, dnsmessage.Header{ID: 3}, nil)) + + want := map[string]int64{ + ateattr.DNSDecisionAllowed: 2, + ateattr.DNSDecisionDenied: 2, + } + if diff := cmp.Diff(want, collectQueries(t, reader)); diff != "" { + t.Errorf("ate.dns.queries mismatch (-want +got):\n%s", diff) + } +} + +// TestNewRelayCountsQueries: a relay from NewRelay counts on its meter. +func TestNewRelayCountsQueries(t *testing.T) { + path := filepath.Join(t.TempDir(), "resolv.conf") + if err := os.WriteFile(path, []byte("nameserver 127.0.0.1\n"), 0o644); err != nil { + t.Fatal(err) + } + reader := sdkmetric.NewManualReader() + relay, err := NewRelay(path, sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)).Meter("ateworker-gvisor")) + if err != nil { + t.Fatalf("NewRelay: %v", err) + } + // The actor has no policy, so the relay answers the query itself. + _, udpAddr, _ := serveLoopbackWithPolicy(t, relay, staticPolicy{}) + conn := dialRelay(t, "udp", udpAddr) + + query, q := dnsQueryForName(t, 1, "example.com.") + if _, err := conn.Write(query); err != nil { + t.Fatal(err) + } + checkAnswerForQuestion(t, readWithin(t, conn), 1, q, dnsmessage.RCodeNameError) + + want := map[string]int64{ateattr.DNSDecisionDenied: 1} + if diff := cmp.Diff(want, collectQueries(t, reader)); diff != "" { + t.Errorf("ate.dns.queries mismatch (-want +got):\n%s", diff) + } +} diff --git a/internal/atunnel/dns/readme.md b/internal/atunnel/dns/readme.md index 2b5bda0010..14225bbbc1 100644 --- a/internal/atunnel/dns/readme.md +++ b/internal/atunnel/dns/readme.md @@ -73,3 +73,4 @@ UDP and TCP call up to the DNS protocol layer (`golang.org/x/net/dns/dnsmessage` - `evaluator` (`evaluator.go`) compiles the hostname and wildcard patterns from an `EgressPolicy`'s `http`, `https`, and `tls_passthrough` rules and evaluates normalized `QNAME`s via `allowsHostname(qname)`. - `egressPolicyCheck` adapts the source to the `dnsHandler`'s `queryPolicy` hook, caching the compiled `*evaluator` for the current `*ateletpb.EgressPolicy` pointer and consulting it for every query. Fetching uses the `Server`'s context, so `Stop()` cancels a fetch in progress. - `allowQuery` evaluates a single `dnsmessage.Question` against a policy using `evaluator`. +- `metrics` (`metrics.go`) counts each decision on `ate.dns.queries`, by `ate.dns.decision`. diff --git a/internal/atunnel/dns/relay.go b/internal/atunnel/dns/relay.go index 71f215cf08..b716364608 100644 --- a/internal/atunnel/dns/relay.go +++ b/internal/atunnel/dns/relay.go @@ -21,6 +21,8 @@ import ( "net" "net/netip" "time" + + "go.opentelemetry.io/otel/metric" ) const ( @@ -39,15 +41,25 @@ type Relay struct { // dialer reaches upstream resolvers from the worker namespace. dialer *net.Dialer + + metrics *metrics } // NewRelay reads nameservers from resolvConfPath and forwards to each on port 53. -func NewRelay(resolvConfPath string) (*Relay, error) { +// It reports its metrics on meter. +func NewRelay(resolvConfPath string, meter metric.Meter) (*Relay, error) { upstreams, err := resolvConfNameservers(resolvConfPath) if err != nil { return nil, err } - return NewRelayForUpstreams(upstreams) + r, err := NewRelayForUpstreams(upstreams) + if err != nil { + return nil, err + } + if r.metrics, err = newMetrics(meter); err != nil { + return nil, err + } + return r, nil } func normalizeAddr(addr net.Addr) string { @@ -98,5 +110,5 @@ func NewRelayForUpstreams(upstreams []string) (*Relay, error) { // serveOn serves DNS on netC's sockets, which the caller has already bound, // and dials upstreams with netC's dialer. func (r *Relay) serveOn(ctx context.Context, netC *netConn, policy PolicySource) (*Server, error) { - return newServer(ctx, &serverConfig{upstreams: r.upstreams, policy: policy}, netC) + return newServer(ctx, &serverConfig{upstreams: r.upstreams, policy: policy, metrics: r.metrics}, netC) } diff --git a/internal/atunnel/dns/relay_test.go b/internal/atunnel/dns/relay_test.go index 2ba5b78eb6..8186b98b92 100644 --- a/internal/atunnel/dns/relay_test.go +++ b/internal/atunnel/dns/relay_test.go @@ -28,6 +28,7 @@ import ( "time" "github.com/google/go-cmp/cmp" + "go.opentelemetry.io/otel/metric/noop" "golang.org/x/net/dns/dnsmessage" ) @@ -124,7 +125,7 @@ func TestNewRelayRejects(t *testing.T) { if err := os.WriteFile(empty, nil, 0o644); err != nil { t.Fatal(err) } - if _, err := NewRelay(empty); err == nil { + if _, err := NewRelay(empty, noop.Meter{}); err == nil { t.Error("NewRelay succeeded with an empty resolv.conf") } if _, err := NewRelayForUpstreams(nil); err == nil { diff --git a/internal/atunnel/dns/server.go b/internal/atunnel/dns/server.go index 8fe8a5f080..4cc7065ff3 100644 --- a/internal/atunnel/dns/server.go +++ b/internal/atunnel/dns/server.go @@ -29,6 +29,8 @@ type serverConfig struct { // policy supplies the actor's egress policy, which each query is checked // against. Nil refuses every query. policy PolicySource + // metrics counts the policy decisions. Nil records nothing. + metrics *metrics } type netConn struct { @@ -88,7 +90,7 @@ func newServer( s.pendingRequests = newPendingRequests(s.limiter) // The check fetches with serveCtx, so that Stop cancels one in progress. - s.dns = newDNSHandler(s.pendingRequests, s.limiter, egressPolicyCheck(serveCtx, config.policy)) + s.dns = newDNSHandler(s.pendingRequests, s.limiter, egressPolicyCheck(serveCtx, config.policy), config.metrics) s.udp = newUDPHandler(netC.udp, netC.egressUDP, udpAddrs, s.dns, s.pendingRequests) s.tcp = newTCPHandler(config.upstreams, netC.tcpListener, netC.dialer, s.dns, s.limiter) diff --git a/internal/atunnel/dns/tcphandler_test.go b/internal/atunnel/dns/tcphandler_test.go index 006d363f6c..fc54b4d6d3 100644 --- a/internal/atunnel/dns/tcphandler_test.go +++ b/internal/atunnel/dns/tcphandler_test.go @@ -34,7 +34,7 @@ func startTestTCPHandler(t *testing.T, upstreams []string, configure func(*tcpHa } lim := newLimiter() - dnsH := newDNSHandler(nil, lim, nil) + dnsH := newDNSHandler(nil, lim, nil, nil) h := newTCPHandler(upstreams, lis, net.Dialer{Timeout: 5 * time.Second}, dnsH, lim) if configure != nil { configure(h, dnsH) diff --git a/internal/atunnel/dns/udphandler_test.go b/internal/atunnel/dns/udphandler_test.go index a6ab35fbe8..4fad99e4b3 100644 --- a/internal/atunnel/dns/udphandler_test.go +++ b/internal/atunnel/dns/udphandler_test.go @@ -50,7 +50,7 @@ func startTestUDPHandler(t *testing.T, upstreams []string, configure func(*udpHa lim := newLimiter() pending := newPendingRequests(lim) - dnsH := newDNSHandler(pending, lim, nil) + dnsH := newDNSHandler(pending, lim, nil, nil) h := newUDPHandler(ingress, egress, udpAddrs, dnsH, pending) if configure != nil { configure(h, dnsH) diff --git a/internal/atunnel/tunnel.go b/internal/atunnel/tunnel.go index d27d29fe7f..6904b83047 100644 --- a/internal/atunnel/tunnel.go +++ b/internal/atunnel/tunnel.go @@ -29,6 +29,8 @@ import ( "net/url" "time" + "go.opentelemetry.io/otel/metric" + "go.ate.dev/substrate/internal/ateletdial" "go.ate.dev/substrate/internal/atunnel/dns" "go.ate.dev/substrate/internal/atunnel/egress" @@ -112,8 +114,8 @@ type Tunnel struct { // Start builds the DNS relay and starts serving actor ingress, which proxies // to upstream inside each sandbox. Egress binds only in sandbox namespaces, so -// nothing listens for it here. -func Start(ctx context.Context, cfg Config, upstream string) (*Tunnel, error) { +// nothing listens for it here. The DNS relay reports its metrics on meter. +func Start(ctx context.Context, cfg Config, upstream string, meter metric.Meter) (*Tunnel, error) { if err := egresspolicy.ValidateDNSEgressPolicy(cfg.DNSEgressPolicy); err != nil { return nil, err } @@ -122,7 +124,7 @@ func Start(ctx context.Context, cfg Config, upstream string) (*Tunnel, error) { return nil, fmt.Errorf("while parsing atunnel upstream: %w", err) } - dnsRelay, err := dns.NewRelay(resolvConfPath) + dnsRelay, err := dns.NewRelay(resolvConfPath, meter) if err != nil { return nil, fmt.Errorf("configuring DNS relay: %w", err) } diff --git a/internal/atunnel/tunnel_test.go b/internal/atunnel/tunnel_test.go index 629739cf60..200d19ed06 100644 --- a/internal/atunnel/tunnel_test.go +++ b/internal/atunnel/tunnel_test.go @@ -38,6 +38,7 @@ import ( "go.ate.dev/substrate/internal/proto/ateworkerpb" "go.ate.dev/substrate/internal/resources" "go.ate.dev/substrate/internal/substratex509" + "go.opentelemetry.io/otel/metric/noop" ) func TestRegisterFlags(t *testing.T) { @@ -203,7 +204,7 @@ func startTunnel(t *testing.T, cfg Config) *Tunnel { t.Helper() ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) - tunnel, err := Start(ctx, cfg, "http://169.254.17.2:80") + tunnel, err := Start(ctx, cfg, "http://169.254.17.2:80", noop.Meter{}) if err != nil { t.Fatal(err) } @@ -284,7 +285,7 @@ func TestStartErrors(t *testing.T) { tc.edit(t, &cfg) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - _, err := Start(ctx, cfg, "http://169.254.17.2:80") + _, err := Start(ctx, cfg, "http://169.254.17.2:80", noop.Meter{}) if (err != nil) != tc.wantErr { t.Fatalf("Start error = %v, wantErr = %v", err, tc.wantErr) } @@ -292,7 +293,7 @@ func TestStartErrors(t *testing.T) { } t.Run("bad upstream", func(t *testing.T) { - _, err := Start(context.Background(), testConfig(t), "http://[::1") + _, err := Start(context.Background(), testConfig(t), "http://[::1", noop.Meter{}) if err == nil { t.Fatalf("Start error = %v, want an error", err) }