Documentation
¶
Overview ¶
Package comparator provides comparison functions for HAProxy Enterprise Edition sections.
This file contains comparison functions for EE-only sections: - Bot Management Profiles (v3.0+ EE) - Captcha (v3.0+ EE) - WAF Profile (v3.2+ EE) - WAF Global (v3.2+ EE)
Package comparator provides fine-grained configuration comparison and operation generation for HAProxy Dataplane API synchronization.
The comparator performs attribute-level comparison between current and desired configurations, generating the minimal set of operations needed to transform one into the other.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comparator ¶
type Comparator struct{}
Comparator performs fine-grained comparison between HAProxy configurations.
It generates the minimal set of operations needed to transform a current configuration into a desired configuration, using attribute-level granularity to minimize API calls and avoid unnecessary HAProxy reloads.
func (*Comparator) Compare ¶
func (c *Comparator) Compare(current, desired *parser.StructuredConfig) (*ConfigDiff, error)
Compare performs a deep comparison between current and desired configurations.
It returns a ConfigDiff containing all operations needed to transform current into desired, along with a summary of changes.
The comparison is performed at attribute-level granularity - if only a single attribute changes (e.g., server weight), only that attribute is updated rather than replacing the entire resource.
Example:
// cmp is a *Comparator; the variable name avoids shadowing the
// imported `comparator` package so subsequent comparator.X type
// references in the same scope keep working.
cmp := comparator.New()
diff, err := cmp.Compare(currentConfig, desiredConfig)
if err != nil {
slog.Error("Comparison failed", "error", err)
os.Exit(1)
}
fmt.Printf("Changes: %s\n", diff.Summary.String())
for _, op := range diff.Operations {
fmt.Printf("- %s\n", op.Describe())
}
type ConfigDiff ¶
type ConfigDiff struct {
// Operations is the ordered list of operations to execute
Operations []Operation
// Summary provides a high-level overview of changes
Summary DiffSummary
}
ConfigDiff represents the difference between two HAProxy configurations.
It contains all operations needed to transform the current configuration into the desired configuration, along with a summary of changes.
type DiffSummary ¶
type DiffSummary struct {
// Total counts by operation type
TotalCreates int
TotalUpdates int
TotalDeletes int
// Global and defaults changes
GlobalChanged bool
DefaultsChanged bool
// Frontend changes
FrontendsAdded []string
FrontendsModified []string
FrontendsDeleted []string
// Backend changes
BackendsAdded []string
BackendsModified []string
BackendsDeleted []string
// Server changes (map of backend -> server names)
ServersAdded map[string][]string
ServersModified map[string][]string
ServersDeleted map[string][]string
// Backend diff fields: for each modified backend, the list of BackendBase fields that differ.
// Populated only when backend attributes (not nested collections) cause the update.
// Useful for diagnosing false diffs from parser round-trip asymmetries.
BackendDiffFields map[string][]string
// Other section changes (extensible for future sections)
OtherChanges map[string]int // section name -> count of changes
}
DiffSummary provides a high-level overview of configuration changes.
This is useful for logging, monitoring, and decision-making about whether to proceed with a configuration update.
func NewDiffSummary ¶
func NewDiffSummary() DiffSummary
NewDiffSummary creates an empty DiffSummary with initialized maps.
func (*DiffSummary) HasChanges ¶
func (s *DiffSummary) HasChanges() bool
HasChanges returns true if any configuration changes are present.
func (*DiffSummary) String ¶
func (s *DiffSummary) String() string
String returns a human-readable summary of changes.
func (*DiffSummary) StructuralOperations ¶
func (s *DiffSummary) StructuralOperations() int
StructuralOperations returns the number of operations that require HAProxy reload. This excludes server UPDATE operations which are runtime-eligible and can be applied without reload via the HAProxy Runtime API.
Use this to choose the apply strategy: zero structural operations means the diff can be applied with a skip-reload runtime push, since runtime-eligible operations should not trigger reloads.
func (*DiffSummary) TotalOperations ¶
func (s *DiffSummary) TotalOperations() int
TotalOperations returns the total number of operations across all types.
type Operation ¶
Operation represents a single configuration change operation.
Operations are executed within transactions and map to specific Dataplane API endpoints for atomic configuration updates.
This is an alias for sections.Operation: factory functions in the sections package return the same interface that the comparator surfaces to the rest of the dataplane package.