mirror of
https://github.com/openziti/ziti.git
synced 2026-09-10 00:35:41 +00:00
Fix stale single-router perf test bind handler call
- updates Test_SingleRouterPerf for handler_xgress.NewBindHandler's signature, which takes an env.RouterEnv as its first argument - adds a minimal testRouterEnv stub supplying the forwarder and xgress metrics the bind handler uses - builds the xgress metrics from the test usage registry via router/metrics.NewXgressMetrics
This commit is contained in:
@@ -32,8 +32,9 @@ import (
|
||||
// package name is not transmitted in the binary encoding.
|
||||
//
|
||||
// The fact that this test binary links both proto packages (distinct proto
|
||||
// package names: ziti.common.metrics.pb vs ziti.metrics.pb) without panicking at
|
||||
// init also guards against a global proto-registry duplicate-registration clash.
|
||||
// package names: ziti.common.servermetrics.pb vs ziti.metrics.pb) without
|
||||
// panicking at init also guards against a global proto-registry
|
||||
// duplicate-registration clash.
|
||||
func Test_WireCompatibleWithLibraryMetricsMessage(t *testing.T) {
|
||||
req := require.New(t)
|
||||
|
||||
|
||||
@@ -38,12 +38,9 @@ const (
|
||||
// UsageRegistry extends a metrics registry with interval and usage counters and
|
||||
// produces ziti's MetricsMessage wire format. It embeds metrics.Registry (so
|
||||
// it can be used anywhere a base registry is expected, including the sdk xgress
|
||||
// machinery) and layers the reporting/usage subsystem ziti owns on top. The wire
|
||||
// poll is exposed as PollMessage rather than Poll to avoid colliding with the
|
||||
// embedded library's Poll, which returns the library's own (unused) message type.
|
||||
// machinery) and layers the reporting/usage subsystem ziti owns on top.
|
||||
type UsageRegistry interface {
|
||||
metrics.Registry
|
||||
PollMessage() *metrics_pb.MetricsMessage
|
||||
PollMessageWithoutUsageMetrics() *metrics_pb.MetricsMessage
|
||||
IntervalCounter(name string, intervalSize time.Duration) IntervalCounter
|
||||
UsageCounter(name string, intervalSize time.Duration) UsageCounter
|
||||
@@ -161,34 +158,6 @@ func (self *usageRegistryImpl) UsageCounter(name string, intervalSize time.Durat
|
||||
return usageCounter
|
||||
}
|
||||
|
||||
// PollMessage returns a MetricsMessage including the base metrics plus any
|
||||
// accumulated interval and usage buckets.
|
||||
func (self *usageRegistryImpl) PollMessage() *metrics_pb.MetricsMessage {
|
||||
base := pollRegistry(self.Registry, self.sourceId, self.tags)
|
||||
if base == nil && self.intervalBuckets == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var builder *messageBuilder
|
||||
if base == nil {
|
||||
builder = newMessageBuilder(self.sourceId, self.tags)
|
||||
} else {
|
||||
builder = (*messageBuilder)(base)
|
||||
}
|
||||
|
||||
builder.addIntervalBucketEvents(self.intervalBuckets)
|
||||
self.intervalBuckets = nil
|
||||
|
||||
builder.UsageCounters = self.usageBuckets
|
||||
self.usageBuckets = nil
|
||||
|
||||
sort.Slice(builder.UsageCounters, func(i, j int) bool {
|
||||
return builder.UsageCounters[i].IntervalStartUTC < builder.UsageCounters[j].IntervalStartUTC
|
||||
})
|
||||
|
||||
return (*metrics_pb.MetricsMessage)(builder)
|
||||
}
|
||||
|
||||
// PollMessageWithoutUsageMetrics returns a MetricsMessage of the base metrics
|
||||
// only, excluding interval and usage buckets.
|
||||
func (self *usageRegistryImpl) PollMessageWithoutUsageMetrics() *metrics_pb.MetricsMessage {
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/openziti/ziti/v2/router/env"
|
||||
"github.com/openziti/ziti/v2/router/forwarder"
|
||||
"github.com/openziti/ziti/v2/router/handler_xgress"
|
||||
routerMetrics "github.com/openziti/ziti/v2/router/metrics"
|
||||
"github.com/openziti/ziti/v2/router/xgress_router"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -136,6 +137,24 @@ type eventSink struct{}
|
||||
func (e eventSink) AcceptMetrics(message *metrics_pb.MetricsMessage) {
|
||||
}
|
||||
|
||||
// testRouterEnv is a minimal env.RouterEnv stub for the perf test. It supplies only the
|
||||
// forwarder and xgress metrics that the xgress bind handler accesses; any other method
|
||||
// call indicates the test exercised an unexpected code path and will panic on the nil
|
||||
// embedded interface.
|
||||
type testRouterEnv struct {
|
||||
env.RouterEnv
|
||||
forwarder env.Forwarder
|
||||
xgMetrics env.XgressMetrics
|
||||
}
|
||||
|
||||
func (self *testRouterEnv) GetForwarder() env.Forwarder {
|
||||
return self.forwarder
|
||||
}
|
||||
|
||||
func (self *testRouterEnv) GetXgressMetrics() env.XgressMetrics {
|
||||
return self.xgMetrics
|
||||
}
|
||||
|
||||
func Test_SingleRouterPerf(t *testing.T) {
|
||||
closeNotify := make(chan struct{})
|
||||
defer close(closeNotify)
|
||||
@@ -159,7 +178,12 @@ func Test_SingleRouterPerf(t *testing.T) {
|
||||
Metrics: xgress.NewMetrics(registry),
|
||||
})
|
||||
|
||||
bindHandler := handler_xgress.NewBindHandler(dataPlaneAdapter, testXgCloseHandler{}, fwd)
|
||||
routerEnv := &testRouterEnv{
|
||||
forwarder: fwd,
|
||||
xgMetrics: routerMetrics.NewXgressMetrics(registry),
|
||||
}
|
||||
|
||||
bindHandler := handler_xgress.NewBindHandler(routerEnv, dataPlaneAdapter, testXgCloseHandler{})
|
||||
|
||||
srcXg := xgress.NewXgress("test", "ctrl", "src", srcConn, xgress.Initiator, options, nil)
|
||||
bindHandler.HandleXgressBind(srcXg)
|
||||
|
||||
Reference in New Issue
Block a user