tracker

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DNSRecord

type DNSRecord struct {
	// LastUpdate is the last update time as a Unix timestamp.
	LastUpdate int64
	// Ports contains a list of service ports to monitor
	Ports []string
}

DNSRecord represents a DNS record with a last update time to verify if the hostname is still active or expired.

func (*DNSRecord) RedisScan

func (t *DNSRecord) RedisScan(x interface{}) error

RedisScan determines how DNSRecord objects will be interpreted when read from Redis.

type GarbageCollector

type GarbageCollector struct {
	MemorystoreClient[Status]
	// contains filtered or unexported fields
}

GarbageCollector is a tracker that implements automatic garbage collection of stale entities - i.e. entities whose registration has not been updated for longer than the configured TTL.

When the GarbageCollector is created, it spawns a goroutine that periodically reads all entities in Memorystore and checks if their registration has expired. If an entity has expired, it is deleted from both Cloud DNS and Memorystore.

func NewGarbageCollector

func NewGarbageCollector(dns dnsiface.Service, project string, msClient MemorystoreClient[Status],
	ttl, interval time.Duration) *GarbageCollector

NewGarbageCollector returns a new garbage-collected tracker for DNS entries and spawns a goroutine to periodically check and delete expired entities.

func (*GarbageCollector) Delete

func (gc *GarbageCollector) Delete(hostname string) error

func (*GarbageCollector) List

func (gc *GarbageCollector) List() ([]string, [][]string, error)

func (*GarbageCollector) Stop

func (gc *GarbageCollector) Stop()

func (*GarbageCollector) Update

func (gc *GarbageCollector) Update(hostname string, ports []string) error

Update creates a new entry in memorystore for the given hostname or updates the existing one with a new LastUpdate time.

type MemorystoreClient

type MemorystoreClient[V any] interface {
	Put(key string, field string, value redis.Scanner, opts *memorystore.PutOptions) error
	GetAll() (map[string]V, error)
	Del(key string) error
}

MemorystoreClient is a client for reading and writing data in Memorystore. The interface takes in a type argument which specifies the types of values that are stored and can be retrieved.

type Status

type Status struct {
	// DNS represents a DNS record
	DNS *DNSRecord
}

Status is the entity written to memorystore to track DNS hostnames. The key for the entity is the hostname.

Jump to

Keyboard shortcuts

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