positions

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertLegacyPositionsFile

func ConvertLegacyPositionsFile(legacyPath, newPath string, l log.Logger)

ConvertLegacyPositionsFile will convert the legacy positions file to the new format if: 1. There is no file at the newpath 2. There is a file at the legacy path and that it is valid yaml

func ConvertLegacyPositionsFileJournal added in v1.11.0

func ConvertLegacyPositionsFileJournal(legacyPath, legacyJob string, newPath string, componentID string, l log.Logger)

ConvertLegacyPositionsFileJournal will convert the legacy positions file to the new format for a journal job if: 1. There is no file at the newpath 2. There is a file at the legacy path and that it is valid yaml

legacyJob is the name of the journal job in e.g. promatil or agent static.

func CursorKey

func CursorKey(key string) string

CursorKey returns a key that can be saved as a cursor that is never deleted.

Types

type Config

type Config struct {
	SyncPeriod        time.Duration `mapstructure:"sync_period" yaml:"sync_period"`
	PositionsFile     string        `mapstructure:"filename" yaml:"filename"`
	IgnoreInvalidYaml bool          `mapstructure:"ignore_invalid_yaml" yaml:"ignore_invalid_yaml"`
	ReadOnly          bool          `mapstructure:"-" yaml:"-"`
}

Config describes where to get position information from.

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(flags *flag.FlagSet)

RegisterFlags register flags.

func (*Config) RegisterFlagsWithPrefix

func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

RegisterFlagsWithPrefix registers flags where every name is prefixed by prefix. If prefix is a non-empty string, prefix should end with a period.

type Entry

type Entry struct {
	Path   string `yaml:"path"`
	Labels string `yaml:"labels"`
}

Entry describes a positions file entry consisting of an absolute file path and the matching label set. An entry expects the string representation of a LabelSet or a Labels slice so that it can be utilized as a YAML key. The caller should make sure that the order and structure of the passed string representation is reproducible, and maintains the same format for both reading and writing from/to the positions file.

type File

type File struct {
	Positions map[Entry]string `yaml:"positions"`
}

File format for the positions data.

type LegacyFile

type LegacyFile struct {
	Positions map[string]string `yaml:"positions"`
}

LegacyFile is the copied struct for the static mode positions file.

type Positions

type Positions interface {
	// GetString returns how far we've through a file as a string.
	// JournalTarget writes a journal cursor to the positions file, while
	// FileTarget writes an integer offset. Use Get to read the integer
	// offset.
	GetString(path, labels string) string
	// Get returns how far we've read through a file. Returns an error
	// if the value stored for the file is not an integer.
	Get(path, labels string) (int64, error)
	// PutString records (asynchronously) how far we've read through a file.
	// Unlike Put, it records a string offset and is only useful for
	// JournalTargets which doesn't have integer offsets.
	PutString(path, labels string, pos string)
	// Put records (asynchronously) how far we've read through a file.
	Put(path, labels string, pos int64)
	// Remove removes the position tracking for a filepath
	Remove(path, labels string)
	// SyncPeriod returns how often the positions file gets resynced
	SyncPeriod() time.Duration
	// Stop the Position tracker.
	Stop()
}

func New

func New(logger log.Logger, cfg Config) (Positions, error)

New makes a new Positions.

Jump to

Keyboard shortcuts

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