reconciler

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

README

reconcile

Package reconcile provides complex multi-source data reconciliation with field-level authority and provenance tracking.

reconciler

import "github.com/agentstation/starmap/pkg/reconciler"

Package reconciler provides catalog synchronization and reconciliation capabilities. It handles merging data from multiple sources, detecting changes, and applying updates while respecting data authorities and merge strategies.

Index

func ConvertCatalogsMapToSources

func ConvertCatalogsMapToSources(srcs map[sources.Type]catalogs.Catalog) []sources.Source

ConvertCatalogsMapToSources converts the old map format to sources slice for testing.

func NewMockSource

func NewMockSource(sourceType sources.Type, catalog catalogs.Catalog) sources.Source

NewMockSource creates a new mock source for testing.

type AuthorityStrategy

AuthorityStrategy uses field authorities to resolve conflicts.

type AuthorityStrategy struct {
    // contains filtered or unexported fields
}

func (*AuthorityStrategy) ResolveConflict
func (s *AuthorityStrategy) ResolveConflict(field string, values map[sources.Type]any) (any, sources.Type, string)

ResolveConflict uses authorities to resolve conflicts.

type Merger

Merger performs the actual merging of resources.

type Merger interface {
    // Models merges models from multiple sources
    Models(sources map[sources.Type][]catalogs.Model) ([]catalogs.Model, provenance.Map, error)

    // Providers merges providers from multiple sources
    Providers(sources map[sources.Type][]catalogs.Provider) ([]catalogs.Provider, provenance.Map, error)
}

type Option

Option is a function that configures a Reconciler.

type Option func(*options) error

func WithAuthorities
func WithAuthorities(authorities authority.Authority) Option

WithAuthorities sets the field authorities.

func WithBaseline
func WithBaseline(catalog catalogs.Catalog) Option

WithBaseline sets an existing catalog to compare against for change detection.

func WithEnhancers
func WithEnhancers(enhancers ...enhancer.Enhancer) Option

WithEnhancers adds model enhancers to the pipeline.

func WithProvenance
func WithProvenance(enabled bool) Option

WithProvenance enables field-level tracking.

func WithStrategy
func WithStrategy(strategy Strategy) Option

WithStrategy sets the merge strategy.

type Reconciler

Reconciler is the main interface for reconciling data from multiple sources.

type Reconciler interface {
    // Sources reconciles multiple catalogs from different sources
    // The primary source determines which models exist; other sources provide enrichment only
    Sources(ctx context.Context, primary sources.Type, srcs []sources.Source) (*Result, error)
}

func New
func New(opts ...Option) (Reconciler, error)

New creates a new Reconciler with options.

type Result

Result represents the outcome of a reconciliation operation.

type Result struct {
    // Core data
    Catalog        catalogs.Catalog
    Changeset      *differ.Changeset
    AppliedChanges *differ.Changeset

    // Tracking maps
    ProviderAPICounts map[catalogs.ProviderID]int
    ModelProviderMap  map[string]catalogs.ProviderID

    // Metadata
    Metadata ResultMetadata

    // Provenance tracking
    Provenance provenance.Map

    // Issues
    Errors   []error
    Warnings []string
}

func NewResult
func NewResult() *Result

NewResult creates a new result with defaults.

func (*Result) Finalize
func (r *Result) Finalize()

Finalize calculates duration and marks completion.

func (*Result) HasChanges
func (r *Result) HasChanges() bool

HasChanges returns true if any changes were detected.

func (*Result) IsSuccess
func (r *Result) IsSuccess() bool

IsSuccess returns true if the reconciliation was successful.

func (*Result) Summary
func (r *Result) Summary() string

Summary returns a human-readable summary of the result.

func (*Result) WasApplied
func (r *Result) WasApplied() bool

WasApplied returns true if changes were applied.

type ResultMetadata

ResultMetadata contains metadata about the reconciliation process.

type ResultMetadata struct {
    // StartTime when reconciliation started
    StartTime time.Time

    // EndTime when reconciliation completed
    EndTime time.Time

    // Duration of the reconciliation
    Duration time.Duration

    // Sources that were reconciled
    Sources []sources.Type

    // Strategy used for reconciliation
    Strategy Strategy

    // DryRun indicates if this was a dry-run
    DryRun bool

    // Statistics about the reconciliation
    Stats ResultStatistics
}

type ResultStatistics

ResultStatistics contains statistics about the reconciliation.

type ResultStatistics struct {
    ModelsProcessed    int
    ProvidersProcessed int
    ConflictsResolved  int
    ResourcesSkipped   int
    TotalTimeMs        int64
}

type SourceOrderStrategy

SourceOrderStrategy resolves conflicts using a fixed source precedence order. Sources earlier in the priority slice have higher precedence than sources later in the slice.

type SourceOrderStrategy struct {
    // contains filtered or unexported fields
}

func (*SourceOrderStrategy) ResolveConflict
func (s *SourceOrderStrategy) ResolveConflict(_ string, values map[sources.Type]any) (any, sources.Type, string)

ResolveConflict uses source priority order to resolve conflicts.

type Strategy

Strategy defines how reconciliation should be performed.

type Strategy interface {
    // Type returns the strategy type
    Type() StrategyType

    // Description returns a human-readable description
    Description() string

    // ShouldMerge determines if resources should be merged
    ShouldMerge(resourceType sources.ResourceType) bool

    // ResolveConflict determines how to resolve conflicts
    ResolveConflict(field string, values map[sources.Type]any) (any, sources.Type, string)

    // ValidateResult validates the reconciliation result
    ValidateResult(result *Result) error

    // ApplyStrategy returns how changes should be applied
    ApplyStrategy() differ.ApplyStrategy
}

func NewAuthorityStrategy
func NewAuthorityStrategy(authorities authority.Authority) Strategy

NewAuthorityStrategy creates a new authority-based strategy.

func NewSourceOrderStrategy
func NewSourceOrderStrategy(priorityOrder []sources.Type) Strategy

NewSourceOrderStrategy creates a new source priority order strategy. The priorityOrder slice determines precedence: earlier elements have higher priority.

type StrategyType

StrategyType represents the type of reconciliation strategy.

type StrategyType string

const (
    // StrategyTypeFieldAuthority uses field-specific authority scores to resolve conflicts.
    StrategyTypeFieldAuthority StrategyType = "field-authority"
    // StrategyTypeSourceOrder uses source ordering to resolve conflicts.
    StrategyTypeSourceOrder StrategyType = "source-order"
)

func (StrategyType) Name
func (s StrategyType) Name() string

Name returns the name of the strategy type.

func (StrategyType) String
func (s StrategyType) String() string

String returns the string representation of a strategy type.

type ValidationError

ValidationError represents a validation error.

type ValidationError struct {
    ResourceType sources.ResourceType
    ResourceID   string
    Field        string
    Message      string
}

type ValidationResult

ValidationResult represents the result of validating a catalog or changeset.

type ValidationResult struct {
    Valid    bool
    Errors   []ValidationError
    Warnings []ValidationWarning
}

func (*ValidationResult) HasWarnings
func (v *ValidationResult) HasWarnings() bool

HasWarnings returns true if there are warnings.

func (*ValidationResult) IsValid
func (v *ValidationResult) IsValid() bool

IsValid returns true if validation passed.

func (*ValidationResult) String
func (v *ValidationResult) String() string

String returns a string representation of the validation result.

type ValidationWarning

ValidationWarning represents a validation warning.

type ValidationWarning struct {
    ResourceType sources.ResourceType
    ResourceID   string
    Field        string
    Message      string
}

Generated by gomarkdoc

Documentation

Overview

Package reconciler provides catalog synchronization and reconciliation capabilities. It handles merging data from multiple sources, detecting changes, and applying updates while respecting data authorities and merge strategies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertCatalogsMapToSources

func ConvertCatalogsMapToSources(srcs map[sources.Type]catalogs.Catalog) []sources.Source

ConvertCatalogsMapToSources converts the old map format to sources slice for testing.

func NewMockSource

func NewMockSource(sourceType sources.Type, catalog catalogs.Catalog) sources.Source

NewMockSource creates a new mock source for testing.

Types

type AuthorityStrategy

type AuthorityStrategy struct {
	// contains filtered or unexported fields
}

AuthorityStrategy uses field authorities to resolve conflicts.

func (*AuthorityStrategy) ApplyStrategy

func (s *AuthorityStrategy) ApplyStrategy() differ.ApplyStrategy

ApplyStrategy returns how changes should be applied.

func (*AuthorityStrategy) Description

func (s *AuthorityStrategy) Description() string

Description returns a human-readable description.

func (*AuthorityStrategy) ResolveConflict

func (s *AuthorityStrategy) ResolveConflict(field string, values map[sources.Type]any) (any, sources.Type, string)

ResolveConflict uses authorities to resolve conflicts.

func (*AuthorityStrategy) ShouldMerge

func (s *AuthorityStrategy) ShouldMerge(resourceType sources.ResourceType) bool

ShouldMerge determines if resources should be merged.

func (*AuthorityStrategy) Type

func (s *AuthorityStrategy) Type() StrategyType

Type returns the strategy type.

func (*AuthorityStrategy) ValidateResult

func (s *AuthorityStrategy) ValidateResult(result *Result) error

ValidateResult validates the reconciliation result.

type Merger

type Merger interface {
	// Models merges models from multiple sources
	Models(sources map[sources.Type][]catalogs.Model) ([]catalogs.Model, provenance.Map, error)

	// Providers merges providers from multiple sources
	Providers(sources map[sources.Type][]catalogs.Provider) ([]catalogs.Provider, provenance.Map, error)
}

Merger performs the actual merging of resources.

type Option

type Option func(*options) error

Option is a function that configures a Reconciler.

func WithAuthorities

func WithAuthorities(authorities authority.Authority) Option

WithAuthorities sets the field authorities.

func WithBaseline

func WithBaseline(catalog catalogs.Catalog) Option

WithBaseline sets an existing catalog to compare against for change detection.

func WithEnhancers

func WithEnhancers(enhancers ...enhancer.Enhancer) Option

WithEnhancers adds model enhancers to the pipeline.

func WithProvenance

func WithProvenance(enabled bool) Option

WithProvenance enables field-level tracking.

func WithStrategy

func WithStrategy(strategy Strategy) Option

WithStrategy sets the merge strategy.

type Reconciler

type Reconciler interface {
	// Sources reconciles multiple catalogs from different sources
	// The primary source determines which models exist; other sources provide enrichment only
	Sources(ctx context.Context, primary sources.Type, srcs []sources.Source) (*Result, error)
}

Reconciler is the main interface for reconciling data from multiple sources.

func New

func New(opts ...Option) (Reconciler, error)

New creates a new Reconciler with options.

type Result

type Result struct {
	// Core data
	Catalog        catalogs.Catalog
	Changeset      *differ.Changeset
	AppliedChanges *differ.Changeset

	// Tracking maps
	ProviderAPICounts map[catalogs.ProviderID]int
	ModelProviderMap  map[string]catalogs.ProviderID

	// Metadata
	Metadata ResultMetadata

	// Provenance tracking
	Provenance provenance.Map

	// Issues
	Errors   []error
	Warnings []string
}

Result represents the outcome of a reconciliation operation.

func NewResult

func NewResult() *Result

NewResult creates a new result with defaults.

func (*Result) Finalize

func (r *Result) Finalize()

Finalize calculates duration and marks completion.

func (*Result) HasChanges

func (r *Result) HasChanges() bool

HasChanges returns true if any changes were detected.

func (*Result) IsSuccess

func (r *Result) IsSuccess() bool

IsSuccess returns true if the reconciliation was successful.

func (*Result) Summary

func (r *Result) Summary() string

Summary returns a human-readable summary of the result.

func (*Result) WasApplied

func (r *Result) WasApplied() bool

WasApplied returns true if changes were applied.

type ResultMetadata

type ResultMetadata struct {
	// StartTime when reconciliation started
	StartTime time.Time

	// EndTime when reconciliation completed
	EndTime time.Time

	// Duration of the reconciliation
	Duration time.Duration

	// Sources that were reconciled
	Sources []sources.Type

	// Strategy used for reconciliation
	Strategy Strategy

	// DryRun indicates if this was a dry-run
	DryRun bool

	// Statistics about the reconciliation
	Stats ResultStatistics
}

ResultMetadata contains metadata about the reconciliation process.

type ResultStatistics

type ResultStatistics struct {
	ModelsProcessed    int
	ProvidersProcessed int
	ConflictsResolved  int
	ResourcesSkipped   int
	TotalTimeMs        int64
}

ResultStatistics contains statistics about the reconciliation.

type SourceOrderStrategy

type SourceOrderStrategy struct {
	// contains filtered or unexported fields
}

SourceOrderStrategy resolves conflicts using a fixed source precedence order. Sources earlier in the priority slice have higher precedence than sources later in the slice.

func (*SourceOrderStrategy) ApplyStrategy

func (s *SourceOrderStrategy) ApplyStrategy() differ.ApplyStrategy

ApplyStrategy returns how changes should be applied.

func (*SourceOrderStrategy) Description

func (s *SourceOrderStrategy) Description() string

Description returns a human-readable description.

func (*SourceOrderStrategy) ResolveConflict

func (s *SourceOrderStrategy) ResolveConflict(_ string, values map[sources.Type]any) (any, sources.Type, string)

ResolveConflict uses source priority order to resolve conflicts.

func (*SourceOrderStrategy) ShouldMerge

func (s *SourceOrderStrategy) ShouldMerge(resourceType sources.ResourceType) bool

ShouldMerge determines if resources should be merged.

func (*SourceOrderStrategy) Type

func (s *SourceOrderStrategy) Type() StrategyType

Type returns the strategy type.

func (*SourceOrderStrategy) ValidateResult

func (s *SourceOrderStrategy) ValidateResult(result *Result) error

ValidateResult validates the reconciliation result.

type Strategy

type Strategy interface {
	// Type returns the strategy type
	Type() StrategyType

	// Description returns a human-readable description
	Description() string

	// ShouldMerge determines if resources should be merged
	ShouldMerge(resourceType sources.ResourceType) bool

	// ResolveConflict determines how to resolve conflicts
	ResolveConflict(field string, values map[sources.Type]any) (any, sources.Type, string)

	// ValidateResult validates the reconciliation result
	ValidateResult(result *Result) error

	// ApplyStrategy returns how changes should be applied
	ApplyStrategy() differ.ApplyStrategy
}

Strategy defines how reconciliation should be performed.

func NewAuthorityStrategy

func NewAuthorityStrategy(authorities authority.Authority) Strategy

NewAuthorityStrategy creates a new authority-based strategy.

func NewSourceOrderStrategy

func NewSourceOrderStrategy(priorityOrder []sources.Type) Strategy

NewSourceOrderStrategy creates a new source priority order strategy. The priorityOrder slice determines precedence: earlier elements have higher priority.

type StrategyType

type StrategyType string

StrategyType represents the type of reconciliation strategy.

const (
	// StrategyTypeFieldAuthority uses field-specific authority scores to resolve conflicts.
	StrategyTypeFieldAuthority StrategyType = "field-authority"
	// StrategyTypeSourceOrder uses source ordering to resolve conflicts.
	StrategyTypeSourceOrder StrategyType = "source-order"
)

func (StrategyType) Name

func (s StrategyType) Name() string

Name returns the name of the strategy type.

func (StrategyType) String

func (s StrategyType) String() string

String returns the string representation of a strategy type.

type ValidationError

type ValidationError struct {
	ResourceType sources.ResourceType
	ResourceID   string
	Field        string
	Message      string
}

ValidationError represents a validation error.

type ValidationResult

type ValidationResult struct {
	Valid    bool
	Errors   []ValidationError
	Warnings []ValidationWarning
}

ValidationResult represents the result of validating a catalog or changeset.

func (*ValidationResult) HasWarnings

func (v *ValidationResult) HasWarnings() bool

HasWarnings returns true if there are warnings.

func (*ValidationResult) IsValid

func (v *ValidationResult) IsValid() bool

IsValid returns true if validation passed.

func (*ValidationResult) String

func (v *ValidationResult) String() string

String returns a string representation of the validation result.

type ValidationWarning

type ValidationWarning struct {
	ResourceType sources.ResourceType
	ResourceID   string
	Field        string
	Message      string
}

ValidationWarning represents a validation warning.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL