Files
ziti/controller/handler_ctrl/metrics.go
Paul Lorenz 187aa11f24 Own the metrics wire format in ziti. Fixes #4036
- adds a common/servermetrics package that owns the metrics MetricsMessage wire
  format and the reporting/usage subsystem (message builder, usage registry,
  interval and usage counters), wrapping the openziti/metrics Registry for
  metric collection
- moves the controllers metrics reporter into the router package and removes it
  from the shared metrics package, breaking a common -> router/env import cycle
- repoints controller and router consumers to common/servermetrics; base metric
  collection stays on openziti/metrics
- keeps the proto field numbers and the metrics content-type identical so the
  encoding is byte-compatible across the move, and uses a distinct proto package
  name so ziti's and the library's messages coexist without a global proto
  registry clash
- adds a round-trip test asserting wire compatibility with the library's
  MetricsMessage
- leaves openziti/metrics unchanged, so sdk-golang and the shared xgress data
  plane are unaffected
2026-06-29 22:37:25 -04:00

50 lines
1.5 KiB
Go

/*
Copyright NetFoundry Inc.
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
https://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 handler_ctrl
import (
"github.com/michaelquigley/pfxlog"
"github.com/openziti/channel/v5"
"github.com/openziti/ziti/v2/common/servermetrics/metrics_pb"
"github.com/openziti/ziti/v2/controller/event"
"github.com/openziti/ziti/v2/controller/network"
"google.golang.org/protobuf/proto"
)
type metricsHandler struct {
dispatcher event.Dispatcher
}
func newMetricsHandler(network *network.Network) *metricsHandler {
return &metricsHandler{
dispatcher: network.GetEventDispatcher(),
}
}
func (h *metricsHandler) ContentType() int32 {
return int32(metrics_pb.ContentType_MetricsType)
}
func (h *metricsHandler) HandleReceive(msg *channel.Message, ch channel.Channel) {
metricsMsg := &metrics_pb.MetricsMessage{}
if err := proto.Unmarshal(msg.Body, metricsMsg); err == nil {
h.dispatcher.AcceptMetricsMsg(metricsMsg)
} else {
pfxlog.ContextLogger(ch.Label()).Errorf("unexpected error (%s)", err)
}
}