stats

package
v0.0.0-...-b295479 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPQueryCount

type IPQueryCount struct {
	Ip    netip.Addr
	Count int
}

Query count from an IP address in one bucket.

type ResolverInfo

type ResolverInfo struct {
	ResolverInfoParts
	// contains filtered or unexported fields
}

ResolverInfo contains information about resolvers that are not zone specific, such as latency and GeoIP information.

func (*ResolverInfo) GetIP

func (resolverInfo *ResolverInfo) GetIP() netip.Addr

func (*ResolverInfo) GetSnapshot

func (resolverInfo *ResolverInfo) GetSnapshot() ResolverInfoParts

Return a copy of the resolver's RTT and geolocation information

func (*ResolverInfo) QualifiesForPing

func (resolverInfo *ResolverInfo) QualifiesForPing() bool

Whether this resolver qualifies to be pinged, solely according to the resolver info

func (*ResolverInfo) SetIsBeingPinged

func (resolverInfo *ResolverInfo) SetIsBeingPinged(new bool)

func (*ResolverInfo) UpdatePingState

func (resolverInfo *ResolverInfo) UpdatePingState(respondsToPing bool, isBeingPinged bool, lastPingTime time.Time)

func (*ResolverInfo) UpdateRTT

func (resolverInfo *ResolverInfo) UpdateRTT(rtt time.Duration)

Update the RTT of this resolver after having pinged it and set a random RTT expiration.

type ResolverInfoMap

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

ResolverInfoMap is a helper struct for a map from resolver IP addresses to corresponding ResolverInfo objects.

func NewResolverInfoMap

func NewResolverInfoMap(geoipRetriever geoip.GeoIPRetriever) *ResolverInfoMap

Creates a new ResolverInfoMap with a GeoIP information provider (Maxmind instance).

func (*ResolverInfoMap) GetResolverInfo

func (infoMap *ResolverInfoMap) GetResolverInfo(ip netip.Addr, logAccess bool) (*ResolverInfo, bool)

GetResolverInfo concurrency-safely retrieves a ResolverInfo instance from the map. If logAccess is true, this get request is logged on the ResolverInfo object.

func (*ResolverInfoMap) GetSnapshotFrom

func (infoMap *ResolverInfoMap) GetSnapshotFrom(ip netip.Addr) (ResolverInfoParts, bool)

Get a snapshot of a subset of resolverInfo, to be used in reporting.

func (*ResolverInfoMap) NewResolverInfo

func (infoMap *ResolverInfoMap) NewResolverInfo(ip netip.Addr) *ResolverInfo

Adds a new ResolverInfo to the ResolverInfoMap or buffer and returns the instance.

func (*ResolverInfoMap) Start

func (infoMap *ResolverInfoMap) Start(ctx context.Context, group *errgroup.Group)

Start housekeeping processes for the ResolverInfoMap:

  1. Keep geolocations up to date (update whenever GeoIP database updates).
  2. Purge stale resolvers from the map (not queried any zone for an hour).
  3. Empty the buffer of ResolverInfo objects to which resolvers are added during longer locked operations.

type ResolverInfoParts

type ResolverInfoParts struct {
	RTT           time.Duration
	RTTExpiration time.Time
	CountryCode   string
	ContinentCode string
}

type ResolverStats

type ResolverStats struct {
	PingMinQph int
	// contains filtered or unexported fields
}

ResolverStats contains a resolver's zone-specific query count statistics. Query counts are kept in a ring buffer spanning an hour to be able to keep track of the number of queries sent in the past hour at any time.

func (*ResolverStats) QualifiesForPing

func (resolverStats *ResolverStats) QualifiesForPing() bool

Reports whether the resolver described by resolverStats qualifies to be pinged, solely according to its query count to this zone.

type ResolverStatsBuffer

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

Buffer for new ResolverStats that are to be added to the ResolverStatsMap while the map is busy for a while (read-locked for a full iteration).

type ResolverStatsConfig

type ResolverStatsConfig struct {
	PingMinQph                 int
	NrBuckets                  int
	PrometheusMetricsFrequency time.Duration
}

Configuration variables for the ResolverStatsMap

type ResolverStatsMap

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

ResolverStatsMap is a helper struct for a map from resolver IP addresses to corresponding ResolverStats objects.

func NewResolverStatsMap

func NewResolverStatsMap(config ResolverStatsConfig, nrResolversGauge prometheus.Gauge) *ResolverStatsMap

Creates a new ResolverStatsMap with a prometheus gauge to update with the current number of resolvers in the map.

func (*ResolverStatsMap) CollectAndAdvance

func (statsMap *ResolverStatsMap) CollectAndAdvance() []IPQueryCount

Collect the current bucket's query count from all resolvers and advance the bucket indices.

func (*ResolverStatsMap) NewResolverStats

func (statsMap *ResolverStatsMap) NewResolverStats(ip netip.Addr) *ResolverStats

Create a new ResolverStats object and add it to this ResolverStatsMap or buffer.

func (*ResolverStatsMap) Start

func (statsMap *ResolverStatsMap) Start(ctx context.Context, group *errgroup.Group)

Start housekeeping processes for the ResolverStatsMap:

  1. Purge stale resolvers from the map (not queried this zone for an hour).
  2. Empty the buffer of ResolverStats objects to which resolvers are added during longer locked operations.
  3. Monitor the number of resolvers that have queried this zone in the past hour.

type ZoneStats

type ZoneStats struct {
	QtypeCounter      counter[uint16]
	OpcodeCounter     counter[uint8]
	RcodeCounter      counter[uint16]
	ProtocolCounter   counter[int32]
	RdCounter         atomic.Int64
	DoCounter         atomic.Int64
	IPv4Counter       atomic.Int64
	*ResolverStatsMap // Resolver-specific query counts
	// contains filtered or unexported fields
}

Struct containing all zone-specific query statistics

func NewZoneStats

func NewZoneStats(config ZoneStatsConfig, resolverStatsMap *ResolverStatsMap) *ZoneStats

Creates a new ZoneStats object with the given resolverStatsMap.

func (*ZoneStats) RegisterQuery

func (stats *ZoneStats) RegisterQuery(query *dns.Msg, sender netip.Addr, socketProtocol int32) *ResolverStats

Registers a query to this zone. Returns the resolverStats object for which the query count is increased.

func (*ZoneStats) RegisterResponse

func (stats *ZoneStats) RegisterResponse(response *dns.Msg)

Registers a response to this zone.

type ZoneStatsConfig

type ZoneStatsConfig struct {
	Zone                       string
	NrBuckets                  int
	PrometheusMetricsFrequency time.Duration
}

Configuration variables for the ZoneStats struct

Jump to

Keyboard shortcuts

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