Files
ziti/controller/model/config_model.go
T
Paul Lorenz 6c20e68038 Apply managed link heartbeat and queue settings at runtime. For #3743
- applies the router.link.v1 heartbeat settings (sendInterval, checkInterval,
  closeUnresponsiveTimeout) and payload/ack sender queue sizes at runtime,
  replacing the hardcoded 10s/1s link heartbeat intervals and the ignored fields;
  new links take them at bind time, established links are re-tuned in place
  through the channel HeartbeatControl, and queue sizes reach new links only
- publishes heartbeat settings as an immutable generation in one atomic swap, so
  no reader pairs one generation's interval with another's timeout, and has each
  link enforce the timeout belonging to its own intervals
- pushes a generation and its intervals as one step under the link's lock and
  ignores a generation at or below the one applied, so an overtaken update cannot
  roll a link back; reconciles every channel of a link, including a split link
  whose channels bind on either side of a config change, to the newest generation
- adopts the first registered settings explicitly, since a router with no managed
  link config publishes its defaults at generation 0
- re-arms a link's liveness deadline when its generation changes, so age
  accumulated under the previous intervals cannot close a healthy link when a
  timeout is shortened
- honors a closeUnresponsiveTimeout below 30s, which previously sat behind the
  unhealthy threshold; treats a zero timeout as closing nothing, and reports a
  closing link unhealthy
- scales the unhealthy threshold with the intervals, to max(30s, 2 x (send +
  check)): reporting unhealthy poisons the latency metric the controller routes
  on, so a fixed 30s priced healthy links with a long send interval out of
  routing every cycle
- validates heartbeat timing on the controller and the router: durations must be
  positive, their sum representable, and the timeout at least 10s and greater
  than sendInterval + checkInterval; a timeout under two heartbeat cycles is
  accepted with a warning
- adds a per-config-type semantic validator registry to ConfigManager, run after
  schema validation, and moves the router.link config definition to
  common/config/routerlink so the controller applies the same rules
- treats a link section in router YAML, of any content, as local config that
  takes precedence over the controller's for the whole router.link type, since
  the loader defaults every field and so now records presence separately; warns
  at startup when that section has no listeners or dialers
- translates local heartbeat timing leniently, since a local failure stops the
  router from starting: keeps an explicit zero, raises a timeout below the floor
  to it, and falls back to the defaults for other invalid timing, each with a
  warning
- stamps UpdateLinkListeners with the config generation it came from and has the
  controller drop superseded sets, which a multi-underlay control channel can
  deliver out of order and which would otherwise send peers to withdrawn
  addresses
- logs every successful link config apply, including those that dispatch no work,
  and pins that a queue-size-only change triggers no GC pass
- deprecates split links, documents the feature in the changelog and the router
  config design doc, and brings both up to date

Builds on the channel/v5 HeartbeatControl from openziti/channel#265.
2026-09-23 13:35:30 -04:00

111 lines
3.3 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 model
import (
"errors"
"github.com/openziti/foundation/v2/errorz"
"github.com/openziti/ziti/v2/controller/apierror"
"github.com/openziti/ziti/v2/controller/db"
"github.com/openziti/ziti/v2/controller/models"
"github.com/openziti/ziti/v2/controller/storage/boltz"
"github.com/xeipuuv/gojsonschema"
"go.etcd.io/bbolt"
)
type Config struct {
models.BaseEntity
Name string
TypeId string
Data map[string]interface{}
}
func (entity *Config) toBoltEntity(tx *bbolt.Tx, env Env) (*db.Config, error) {
if entity.TypeId != "" {
providedType := entity.TypeId
configTypeStore := env.GetStores().ConfigType
if !configTypeStore.IsEntityPresent(tx, entity.TypeId) {
return nil, errorz.NewFieldError("invalid config type", db.FieldConfigType, providedType)
}
}
if entity.TypeId == "" {
currentConfig, err := env.GetManagers().Config.readInTx(tx, entity.Id)
if err != nil {
return nil, err
}
entity.TypeId = currentConfig.TypeId
}
configType, _ := env.GetManagers().ConfigType.readInTx(tx, entity.TypeId)
if configType != nil && len(configType.Schema) > 0 {
compileSchema, err := configType.GetCompiledSchema()
if err != nil {
return nil, err
}
jsonLoader := gojsonschema.NewGoLoader(entity.Data)
result, err := compileSchema.Validate(jsonLoader)
if err != nil {
return nil, err
}
if !result.Valid() {
return nil, apierror.NewValidationErrors(result)
}
}
// Semantic validation runs after the schema, so a validator can assume the
// shape is already right and only judge the values. Keyed on the type name,
// which is stable across networks in a way the id is not.
if configType != nil {
if err := env.GetManagers().Config.validateData(configType.Name, entity.Data); err != nil {
var fieldErr *errorz.FieldError
if errors.As(err, &fieldErr) {
return nil, fieldErr
}
return nil, errorz.NewFieldError(err.Error(), db.FieldConfigData, entity.Data)
}
}
return &db.Config{
BaseExtEntity: *boltz.NewExtEntity(entity.Id, entity.Tags),
Name: entity.Name,
TypeId: entity.TypeId,
Data: entity.Data,
}, nil
}
func (entity *Config) toBoltEntityForCreate(tx *bbolt.Tx, env Env) (*db.Config, error) {
if entity.TypeId == "" {
return nil, errorz.NewFieldError("config type must be specified", db.FieldConfigType, entity.TypeId)
}
return entity.toBoltEntity(tx, env)
}
func (entity *Config) toBoltEntityForUpdate(tx *bbolt.Tx, env Env, _ boltz.FieldChecker) (*db.Config, error) {
return entity.toBoltEntity(tx, env)
}
func (entity *Config) fillFrom(_ Env, _ *bbolt.Tx, boltConfig *db.Config) error {
entity.FillCommon(boltConfig)
entity.Name = boltConfig.Name
entity.TypeId = boltConfig.TypeId
entity.Data = boltConfig.Data
return nil
}