config

package
v0.0.0-...-ae9624b Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParameterNotFound = errors.New("could not find parameter with this path")
)
View Source
var Nil = Value{}

Functions

func Describe

func Describe(val flagext.RegistererWithLogger) ([]byte, error)

Describe returns a JSON-serialized result of InspectConfig

Types

type BestEffortDirectMapper

type BestEffortDirectMapper struct{}

BestEffortDirectMapper implement Mapper and naively maps the values of all parameters form the source to the same name parameter in the target. It ignores all errors while setting the values.

func (BestEffortDirectMapper) DoMap

func (BestEffortDirectMapper) DoMap(source, target Parameters) error

type ChangedDefault

type ChangedDefault struct {
	Path                   string
	OldDefault, NewDefault string
}

type ConversionNotices

type ConversionNotices struct {
	RemovedCLIFlags        []string
	RemovedParameters      []string
	ChangedDefaults        []ChangedDefault
	SkippedChangedDefaults []ChangedDefault
	PrunedDefaults         []PrunedDefault
}

func Convert

func Convert(
	contents []byte,
	flags []string,
	m Mapper,
	sourceFactory, targetFactory InspectedEntryFactory,
	useNewDefaults, showDefaults bool,
) (convertedContents []byte, convertedFlags []string, _ ConversionNotices, conversionErr error)

Convert converts the passed YAML contents and CLI flags in the source schema to a YAML config and CLI flags in the target schema. sourceFactory and targetFactory are assumed to return InspectedEntries where the FieldValue is the default value of the configuration parameter. Convert uses sourceFactory and targetFactory to also prune the default values from the resulting config. Convert returns the marshalled YAML config in the target schema.

type EntryKind

type EntryKind string
const (
	KindBlock EntryKind = "block"
	KindField EntryKind = "field"
)

type InspectedEntry

type InspectedEntry struct {
	Kind     EntryKind `json:"kind"`
	Name     string    `json:"name"`
	Required bool      `json:"required"`
	Desc     string    `json:"desc"`

	// In case the Kind is "block"
	BlockEntries       []*InspectedEntry `json:"blockEntries,omitempty"`
	BlockFlagsPrefix   string            `json:"blockFlagsPrefix,omitempty"`
	BlockFlagsPrefixes []string          `json:"blockFlagsPrefixes,omitempty"`

	// In case the Kind is "field"
	FieldValue        Value           `json:"fieldValue,omitempty"`
	FieldDefaultValue Value           `json:"fieldDefaultValue,omitempty"`
	FieldFlag         string          `json:"fieldFlag,omitempty"`
	FieldType         string          `json:"fieldType,omitempty"`
	FieldCategory     string          `json:"fieldCategory,omitempty"`
	FieldElement      *InspectedEntry `json:"fieldElement,omitempty"` // when FieldType is "slice" or "map"
}

func DefaultCortexConfig

func DefaultCortexConfig() *InspectedEntry

func DefaultGEM170Config

func DefaultGEM170Config() *InspectedEntry

func DefaultGEMConfig

func DefaultGEMConfig() *InspectedEntry

func DefaultMimirConfig

func DefaultMimirConfig() *InspectedEntry

func InspectConfig

func InspectConfig(cfg flagext.RegistererWithLogger) (*InspectedEntry, error)

InspectConfig returns an InspectedEntry that represents the root block of the configuration.

func InspectConfigWithFlags

func InspectConfigWithFlags(cfg interface{}, flags map[uintptr]*flag.Flag) (*InspectedEntry, error)

InspectConfigWithFlags does the same as InspectConfig while allowing to provide custom CLI flags. This is useful when the configuration struct does not implement flagext.RegistererWithLogger.

func (*InspectedEntry) Clone

func (i *InspectedEntry) Clone() *InspectedEntry

func (*InspectedEntry) Delete

func (i *InspectedEntry) Delete(path string) error

Delete deletes a leaf parameter or entire subtree from the InspectedEntry. Delete also recursively deletes any parent blocks that, because of this delete, now contain no entries. If an error is returned, it's errors.Cause will be ErrParameterNotFound.

func (InspectedEntry) GetDefaultValue

func (i InspectedEntry) GetDefaultValue(path string) (Value, error)

func (InspectedEntry) GetFlag

func (i InspectedEntry) GetFlag(path string) (string, error)

GetFlag returns the CLI flag name of the parameter.

func (*InspectedEntry) GetValue

func (i *InspectedEntry) GetValue(path string) (Value, error)

func (*InspectedEntry) IsBoolFlag

func (i *InspectedEntry) IsBoolFlag() bool

IsBoolFlag is used by flag package to support to setting bool flags without using value.

func (*InspectedEntry) MarshalYAML

func (i *InspectedEntry) MarshalYAML() (interface{}, error)

func (InspectedEntry) MustGetDefaultValue

func (i InspectedEntry) MustGetDefaultValue(path string) Value

func (*InspectedEntry) MustGetValue

func (i *InspectedEntry) MustGetValue(path string) Value

MustGetValue does the same as GetVValue, but panics if there's an error.

func (*InspectedEntry) RegisterFlags

func (i *InspectedEntry) RegisterFlags(fs *flag.FlagSet, logger log.Logger)

func (*InspectedEntry) Set

func (i *InspectedEntry) Set(s string) (err error)

Set implements flag.Value

func (InspectedEntry) SetDefaultValue

func (i InspectedEntry) SetDefaultValue(path string, val Value) error

func (*InspectedEntry) SetValue

func (i *InspectedEntry) SetValue(path string, v Value) error

SetValue sets individual parameters. val can be any value. If an error is returned, its errors.Cause will be ErrParameterNotFound.

func (*InspectedEntry) String

func (i *InspectedEntry) String() string

String implements flag.Value

func (*InspectedEntry) UnmarshalJSON

func (i *InspectedEntry) UnmarshalJSON(b []byte) error

func (*InspectedEntry) UnmarshalYAML

func (i *InspectedEntry) UnmarshalYAML(value *yaml.Node) error

func (InspectedEntry) Walk

func (i InspectedEntry) Walk(f func(path string, value Value) error) error

Walk visits all leaf parameters of the InspectedEntry in a depth-first manner and calls f. If f returns an error, the traversal is not stopped. The error Walk returns are the combined errors that all f invocations returned. If no f invocations returned an error, then Walk returns nil.

type InspectedEntryFactory

type InspectedEntryFactory func() *InspectedEntry

type Mapper

type Mapper interface {
	DoMap(source, target Parameters) error
}

func CortexToMimirMapper

func CortexToMimirMapper() Mapper

CortexToMimirMapper maps from cortex-1.11.0 to latest mimir configurations

func GEM170ToGEMMapper

func GEM170ToGEMMapper() Mapper

GEM170ToGEMMapper maps from gem-1.7.0 to current gem configuration

type MapperFunc

type MapperFunc func(source, target Parameters) error

func (MapperFunc) DoMap

func (m MapperFunc) DoMap(source, target Parameters) error

type Mapping

type Mapping func(oldPath string, oldVal Value) (newPath string, newVal Value)

func RenameMapping

func RenameMapping(to string) Mapping

type MultiMapper

type MultiMapper []Mapper

func (MultiMapper) DoMap

func (m MultiMapper) DoMap(source, target Parameters) error

type Parameters

type Parameters interface {
	Delete(path string) error
	GetFlag(path string) (string, error)

	GetValue(path string) (Value, error)
	MustGetValue(path string) Value
	SetValue(path string, v Value) error

	GetDefaultValue(path string) (Value, error)
	MustGetDefaultValue(path string) Value
	SetDefaultValue(path string, v Value) error

	Walk(f func(path string, value Value) error) error
}

type PathMapper

type PathMapper struct {
	PathMappings map[string]Mapping
}

PathMapper applies the mappings to specific parameters of the source.

func (PathMapper) DoMap

func (m PathMapper) DoMap(source, target Parameters) error

DoMap applies the Mappings from source to target. The error DoMap returns are the combined errors that all Mappings returned. If no Mappings returned an error, then DoMap returns nil.

type PrunedDefault

type PrunedDefault struct {
	Path  string
	Value string
}

type Value

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

func DurationValue

func DurationValue(d time.Duration) Value

func IntValue

func IntValue(i int) Value

func InterfaceValue

func InterfaceValue(v interface{}) Value

func SliceValue

func SliceValue(slice []*InspectedEntry) Value

func StringValue

func StringValue(s string) Value

func (Value) AsBool

func (v Value) AsBool() bool

func (Value) AsDuration

func (v Value) AsDuration() time.Duration

func (Value) AsFloat

func (v Value) AsFloat() float64

func (Value) AsInt

func (v Value) AsInt() int

func (Value) AsInterface

func (v Value) AsInterface() interface{}

func (Value) AsSlice

func (v Value) AsSlice() []*InspectedEntry

func (Value) AsString

func (v Value) AsString() string

func (Value) AsURL

func (v Value) AsURL() flagext.URLValue

func (Value) Equals

func (v Value) Equals(other Value) bool

func (Value) IsSlice

func (v Value) IsSlice() bool

func (Value) IsUnset

func (v Value) IsUnset() bool

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

func (Value) String

func (v Value) String() string

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON([]byte) error

UnmarshalJSON is empty because unmarshalling without type information is not possible. InspectedEntry.UnmarshalJSON does the unmarshalling _with_ type information.

Jump to

Keyboard shortcuts

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