service

package
v0.0.0-...-a6bb31e Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultFileIngesterOrigin is the default $ORIGIN used for parsing zone files.
	DefaultFileIngesterOrigin = ""

	// DefaultFileIngesterTTL is the default $TTL used for parsing zone files.
	DefaultFileIngesterTTL = 5 * time.Minute
)
View Source
const (
	// DefaultCheckInterval is the default time that a FileIngester rechecks external sources
	// for DNS RRs that affect how hashy operates.
	DefaultCheckInterval = 10 * time.Minute
)
View Source
const (
	DefaultDiscoveryDomain = "_hashy.discover"
)

Variables

This section is empty.

Functions

func Provide

func Provide() fx.Option

Provide creates the relevant components in this package.

Types

type Endpoint

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

Endpoint is a single endpoint of a service.

func (*Endpoint) OriginalName

func (s *Endpoint) OriginalName() string

OriginalName is the name as it appeared in the source DNS records. This will likely be served from a different domain.

type FileIngester

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

FileIngester handles reading in DNS zone files from the filesystem.

func NewFileIngester

func NewFileIngester(opts ...FileIngesterOption) (*FileIngester, error)

NewFileIngester creates a FileIngester from a set of options.

func (*FileIngester) Ingest

func (fi *FileIngester) Ingest(ctx context.Context)

Ingest reads in all the files this FileIngester was configured with. This method tracks the checksum across all files. An IngestEvent will only be dispatch if either (a) this is the first Ingest, or (b) if any change in the files occurred.

type FileIngesterOption

type FileIngesterOption interface {
	// contains filtered or unexported methods
}

func WithDiscoveryDomain

func WithDiscoveryDomain(domain string) FileIngesterOption

func WithGlobs

func WithGlobs(more ...string) FileIngesterOption

func WithGroupsConfig

func WithGroupsConfig(gcfg config.Groups) FileIngesterOption

func WithIngestListeners

func WithIngestListeners(more ...IngestListener) FileIngesterOption

func WithIngestLogger

func WithIngestLogger(base *zap.Logger) FileIngesterOption

func WithOrigin

func WithOrigin(origin string) FileIngesterOption

func WithTTL

func WithTTL(ttl time.Duration) FileIngesterOption

type Group

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

Group is a single group of servers.

func (*Group) Endpoints

func (g *Group) Endpoints() iter.Seq[*Endpoint]

func (*Group) Len

func (g *Group) Len() int

func (*Group) LenRRs

func (g *Group) LenRRs(rrType uint16) (n int)

LenRRs returns the number of RRs this group will produce of the given type.

func (*Group) Name

func (g *Group) Name() string

func (*Group) RRs

func (g *Group) RRs(rrType uint16) iter.Seq2[*Group, dns.RR]

RRs produces a sequence of RR records for this group. If rrType is anything but TypeTXT, this method returns an empty sequence.

Each returned RR has a header with only the Class set to ClassINET.

func (*Group) Services

func (g *Group) Services() iter.Seq[string]

type GroupDefinition

type GroupDefinition struct {
	Name     string
	Services []string
}

GroupDefinition holds the discovered information about a group. Typically, group definitions will come from TXT records.

func MergeGroupDefinitions

func MergeGroupDefinitions(defs ...GroupDefinition) (merged GroupDefinition)

MergeGroupDefinitions merges each of a sequence of definitions into a single definition. The returned definition has the name of the first definition passed to this function. The services are merged into a single slice, but are not deduped or sorted.

If no definitions are passed to this function, it returns an empty definition.

func ParseGroupDefinition

func ParseGroupDefinition(txt string) (gdef GroupDefinition, err error)

ParseGroupDefinition parses the textual representation of a group's discovered information. The text must be a valid US-ASCII string with 2 or more fields delimited by whitespace. The first field is the group's name, and all subsequent fields are the services (SRV records) that hold the members of the group.

type Groups

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

Groups is an immutable collection of Group instances.

func (*Groups) All

func (gps *Groups) All() iter.Seq[*Group]

func (*Groups) At

func (gps *Groups) At(i int) *Group

func (*Groups) Get

func (gps *Groups) Get(groupName string) *Group

func (*Groups) Len

func (gps *Groups) Len() int

func (*Groups) LenRRs

func (gps *Groups) LenRRs(rrType uint16) (n int)

func (*Groups) RRs

func (gps *Groups) RRs(rrType uint16) iter.Seq2[*Group, dns.RR]

type IngestChecker

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

IngestChecker manages a single goroutine that invokes Ingest on a particular Ingester on an interval.

Only (1) background goroutine will run for any given IngestChecker.

func NewIngestChecker

func NewIngestChecker(opts ...IngestCheckerOption) (*IngestChecker, error)

NewIngestChecker creates an unstarted IngestChecker using the supplied options. If no Ingester was supplied in the options, this method returns an error.

func (*IngestChecker) Start

func (ic *IngestChecker) Start()

Start atomically starts invoking Ingest on the configured interval. This method is idempotent.

func (*IngestChecker) Stop

func (ic *IngestChecker) Stop()

Stop atomically halts invoking Ingest. This method is idempotent.

type IngestCheckerOption

type IngestCheckerOption interface {
	// contains filtered or unexported methods
}

func WithCheckInterval

func WithCheckInterval(v time.Duration) IngestCheckerOption

func WithIngester

func WithIngester(i Ingester) IngestCheckerOption

type IngestEvent

type IngestEvent struct {
	// Err contains any error that occurred. If this is non-nil, Groups
	// should be ignored.
	Err error

	// Lists holds the ingested groups.
	Groups *Groups
}

IngestEvent holds information about an update to the set of groups.

type IngestListener

type IngestListener interface {
	// OnIngest notifies this listener that an ingest operation has completed.
	// Only errors and actual changes will be dispatched through this method.
	OnIngest(IngestEvent)
}

IngestListener is a sink for IngestEvents.

type Ingester

type Ingester interface {
	// Ingest reads group information, usually DNS RRs, from the configured source.
	// This method dispatches an IngestEvent that will contain the new groups as well
	// as any error that occurred.
	Ingest(context.Context)
}

Ingester represents the behavior of something that can read in group information. Primarily, this will be from some source of DNS RRs.

type LocatedEndpoints

type LocatedEndpoints []*Endpoint

LocatedEndpoints is a collection of endpoints that were discovered by a Locator.

func (LocatedEndpoints) LenRRs

func (le LocatedEndpoints) LenRRs(rrType uint16) (n int)

LenRRs returns the total count of all RRs of a given type in this set. This will be the number of tuples returned by the RRs() sequence.

func (LocatedEndpoints) RRs

func (le LocatedEndpoints) RRs(rrType uint16) iter.Seq2[*Endpoint, dns.RR]

RRs returns a sequence of (*Endpoint, dns.RR) tuples. Each RR is of the given type. Each RR's Class will be set to ClassINET, but will otherwise be uninitialized.

type Locator

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

Locator is a service locator backed by one or more medley consistent hash Rings.

func NewLocator

func NewLocator(opts ...LocatorOption) (*Locator, error)

func (*Locator) Find

func (l *Locator) Find(object []byte, groups ...string) (results LocatedEndpoints)

func (*Locator) FindString

func (l *Locator) FindString(object string, groups ...string) (results LocatedEndpoints)

func (*Locator) Groups

func (l *Locator) Groups() (gps *Groups)

func (*Locator) OnIngest

func (l *Locator) OnIngest(event IngestEvent)

func (*Locator) Update

func (l *Locator) Update(gps *Groups)

type LocatorOption

type LocatorOption interface {
	// contains filtered or unexported methods
}

func WithLocatorLogger

func WithLocatorLogger(base *zap.Logger) LocatorOption

func WithVNodes

func WithVNodes(vnodes int) LocatorOption

type RRCollector

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

RRCollector collects DNS resource records in order to build a Groups. This type is basically the recipient of a stream of incoming RRs from an arbitrary source.

func (*RRCollector) AddRR

func (rrc *RRCollector) AddRR(rr dns.RR) error

AddRR adds an RR to this collector. Any RR that is not recognized is simply ignored.

func (*RRCollector) Build

func (rrc *RRCollector) Build() *Groups

Build constructs a Groups from the collected DNS RRs. After this method returns, this builder will be Reset.

func (*RRCollector) Reset

func (rrc *RRCollector) Reset()

Reset clears all collected records, but retains the underlying storage buffers for next time.

Jump to

Keyboard shortcuts

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