metrics

package
v0.0.0-...-1ff64f8 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package metrics contains definitions of most of the prometheus metrics that we use in AdGuard DNS.

NOTE: Prefer to not import any packages from the current module here, because a lot of packages import metrics, and so import cycles may happen.

TODO(a.garipov): Do not use promauto.

Index

Constants

This section is empty.

Variables

View Source
var (

	// BindToDeviceUnknownTCPRequestsTotal is the total counter of DNS requests
	// over TCP to unknown local addresses.
	BindToDeviceUnknownTCPRequestsTotal = bindToDeviceUnknownRequestsTotal.With(prometheus.Labels{
		"proto": "tcp",
	})

	// BindToDeviceUnknownUDPRequestsTotal is the total counter of DNS requests
	// over UDP to unknown local addresses.
	BindToDeviceUnknownUDPRequestsTotal = bindToDeviceUnknownRequestsTotal.With(prometheus.Labels{
		"proto": "udp",
	})
)
View Source
var (
	// BindToDeviceTCPConnsChanSize is a gauge with the current number of TCP
	// connections in the buffer of the channel by each subnet.
	BindToDeviceTCPConnsChanSize = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name:      "tcp_conns_chan_size",
		Namespace: namespace,
		Subsystem: subsystemBindToDevice,
		Help:      "The current number of TCP connections in the channel.",
	}, []string{"subnet"})

	// BindToDeviceUDPSessionsChanSize is a gauge with the current number of UDP
	// sessions in the buffer of the channel by each subnet.
	BindToDeviceUDPSessionsChanSize = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name:      "udp_sessions_chan_size",
		Namespace: namespace,
		Subsystem: subsystemBindToDevice,
		Help:      "The current number of UDP sessions in the channel.",
	}, []string{"subnet"})

	// BindToDeviceUDPWriteRequestsChanSize is a gauge with the current number
	// of UDP write requests in the buffer of the channel for each interface
	// listener.
	BindToDeviceUDPWriteRequestsChanSize = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name:      "udp_write_requests_chan_size",
		Namespace: namespace,
		Subsystem: subsystemBindToDevice,
		Help:      "The current number of UDP write requests in the channel.",
	}, []string{"name"})

	// BindToDeviceUDPWriteDurationSeconds is a histogram of durations of UDP
	// write operations.  This histogram includes only the write itself and does
	// not include deadline setting and resetting.
	BindToDeviceUDPWriteDurationSeconds = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Name:      "udp_write_duration_seconds",
		Namespace: namespace,
		Subsystem: subsystemBindToDevice,
		Help:      "The duration of a write to a UDP socket.",
		Buckets:   []float64{0.001, 0.01, 0.1, 1},
	}, []string{"name"})
)
View Source
var (

	// DNSSvcDDRRequestsTotal is a counter with total number of requests for
	// Discovery of Designated Resolvers.
	DNSSvcDDRRequestsTotal = specialRequestsTotal.With(prometheus.Labels{
		"kind": "ddr",
	})

	// DNSSvcBadResolverARPA is a counter with total number of requests for
	// malformed resolver.arpa queries.
	DNSSvcBadResolverARPA = specialRequestsTotal.With(prometheus.Labels{
		"kind": "bad_resolver_arpa",
	})

	// DNSSvcChromePrefetchRequestsTotal is a counter with total number of
	// requests for the domain name that Chrome uses to check if it should use
	// its prefetch proxy.
	DNSSvcChromePrefetchRequestsTotal = specialRequestsTotal.With(prometheus.Labels{
		"kind": "chrome_prefetch",
	})

	// DNSSvcFirefoxRequestsTotal is a counter with total number of requests for
	// the domain name that Firefox uses to check if it should use its own
	// DNS-over-HTTPS settings.
	DNSSvcFirefoxRequestsTotal = specialRequestsTotal.With(prometheus.Labels{
		"kind": "firefox",
	})

	// DNSSvcApplePrivateRelayRequestsTotal is a counter with total number of
	// requests for the domain name that Apple devices use to check if Apple
	// Private Relay can be enabled.
	DNSSvcApplePrivateRelayRequestsTotal = specialRequestsTotal.With(prometheus.Labels{
		"kind": "apple_private_relay",
	})

	// DNSSvcDoHAuthFailsTotal is the counter of DoH basic authentication
	// failures.
	DNSSvcDoHAuthFailsTotal = promauto.NewCounter(prometheus.CounterOpts{
		Name:      "doh_authentication_fails",
		Namespace: namespace,
		Subsystem: subsystemDNSSvc,
		Help:      "The number of authentication failures for DoH auth.",
	})
)
View Source
var (

	// WebSvcError404RequestsTotal is a counter with total number of
	// requests with error 404.
	WebSvcError404RequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "error404",
	})

	// WebSvcError500RequestsTotal is a counter with total number of
	// requests with error 500.
	WebSvcError500RequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "error500",
	})

	// WebSvcStaticContentRequestsTotal is a counter with total number of
	// requests for static content.
	WebSvcStaticContentRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "static_content",
	})

	// WebSvcDNSCheckTestRequestsTotal is a counter with total number of
	// requests for dnscheck_test.
	WebSvcDNSCheckTestRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "dnscheck_test",
	})

	// WebSvcRobotsTxtRequestsTotal is a counter with total number of
	// requests for robots_txt.
	WebSvcRobotsTxtRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "robots_txt",
	})

	// WebSvcRootRedirectRequestsTotal is a counter with total number of
	// root redirected requests.
	WebSvcRootRedirectRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "root_redirect",
	})

	// WebSvcLinkedIPProxyRequestsTotal is a counter with total number of
	// requests with linked ip.
	WebSvcLinkedIPProxyRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "linkip",
	})

	// WebSvcAdultBlockingPageRequestsTotal is a counter with total number
	// of requests for adult blocking page.
	WebSvcAdultBlockingPageRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "adult_blocking_page",
	})

	// WebSvcGeneralBlockingPageRequestsTotal is a counter with total number
	// of requests for general blocking page.
	WebSvcGeneralBlockingPageRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "general_blocking_page",
	})

	// WebSvcSafeBrowsingPageRequestsTotal is a counter with total number
	// of requests for safe browsing page.
	WebSvcSafeBrowsingPageRequestsTotal = webSvcRequestsTotal.With(prometheus.Labels{
		"kind": "safe_browsing_page",
	})
)
View Source
var AccessProfileInitDuration = promauto.NewHistogram(prometheus.HistogramOpts{
	Name:      "profile_init_engine_duration_seconds",
	Namespace: namespace,
	Subsystem: subsystemAccess,
	Help:      "Time elapsed on profile access engine initialization.",
})

AccessProfileInitDuration is a histogram with the duration of a profile access internal engine initialization.

Functions

func BoolString

func BoolString(cond bool) (s string)

BoolString returns "1" if cond is true and "0" otherwise.

func ExperimentGauge

func ExperimentGauge(constLabels prometheus.Labels) (g prometheus.Gauge)

ExperimentGauge returns the gauge used to inform about running experiments.

func IncrementCond

func IncrementCond(cond bool, trueCounter, falseCounter prometheus.Counter)

IncrementCond increments trueCounter if cond is true and falseCounter otherwise.

func Namespace

func Namespace() (ns string)

Namespace returns the namespace that we use in our prometheus metrics.

func SetAdditionalInfo

func SetAdditionalInfo(info map[string]string)

SetAdditionalInfo adds a gauge with extra info labels. If info is nil, SetAdditionalInfo does nothing.

func SetStatusGauge

func SetStatusGauge(gauge prometheus.Gauge, err error)

SetStatusGauge is a helper function that automatically checks if there's an error and sets the gauge to either 1 (success) or 0 (error).

func SetUpGauge

func SetUpGauge(version, commitTime, branch, revision, goversion string)

SetUpGauge signals that the server has been started. Use a function here to avoid circular dependencies.

Types

type Allowlist

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

Allowlist is the Prometheus-based implementation of the [consul.Metrics] interface.

func NewAllowlist

func NewAllowlist(
	namespace string,
	reg prometheus.Registerer,
	typ string,
) (m *Allowlist, err error)

NewAllowlist registers the Consul allowlist metrics in reg and returns a properly initialized Allowlist.

func (*Allowlist) SetSize

func (m *Allowlist) SetSize(_ context.Context, n int)

SetSize implements the [consul.Metrics] interface for *Allowlist.

func (*Allowlist) SetStatus

func (m *Allowlist) SetStatus(_ context.Context, err error)

SetStatus implements the [consul.Metrics] interface for *Allowlist.

type BackendGRPC

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

BackendGRPC is the Prometheus-based implementation of the [backendpb.GRPCMetrics] interface.

func NewBackendGRPC

func NewBackendGRPC(namespace string, reg prometheus.Registerer) (m *BackendGRPC, err error)

NewBackendGRPC registers the protobuf errors metrics in reg and returns a properly initialized BackendGRPC.

func (*BackendGRPC) IncrementErrorCount

func (m *BackendGRPC) IncrementErrorCount(_ context.Context, errType GRPCError)

IncrementErrorCount implements the [backendpb.GRPCMetrics] interface for BackendGRPC.

type BackendProfileDB

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

BackendProfileDB is the Prometheus-based implementation of the [backendpb.ProfileDBMetrics] interface.

func NewBackendProfileDB

func NewBackendProfileDB(
	namespace string,
	reg prometheus.Registerer,
) (m *BackendProfileDB, err error)

NewBackendProfileDB registers the protobuf errors metrics in reg and returns a properly initialized BackendProfileDB.

func (*BackendProfileDB) IncrementInvalidDevicesCount

func (m *BackendProfileDB) IncrementInvalidDevicesCount(_ context.Context)

IncrementInvalidDevicesCount implements the [backendpb.ProfileDBMetrics] interface for BackendProfileDB.

func (*BackendProfileDB) UpdateStats

func (m *BackendProfileDB) UpdateStats(_ context.Context, avgRecv, avgDec time.Duration)

UpdateStats implements the [backendpb.ProfileDBMetrics] interface for BackendProfileDB.

type BackendRemoteKV

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

BackendRemoteKV is the Prometheus-based implementation of the [backendpb.Metrics] interface.

func NewBackendRemoteKV

func NewBackendRemoteKV(
	namespace string,
	reg prometheus.Registerer,
) (m *BackendRemoteKV, err error)

NewBackendRemoteKV registers the backend remote key-value storage metrics in reg and returns a properly initialized BackendRemoteKV.

func (*BackendRemoteKV) IncrementLookups

func (m *BackendRemoteKV) IncrementLookups(_ context.Context, hit bool)

IncrementLookups implements the [backendpb.RemoteKVMetrics] interface for *BackendRemoteKV.

func (*BackendRemoteKV) ObserveOperation

func (m *BackendRemoteKV) ObserveOperation(_ context.Context, op string, dur time.Duration)

ObserveOperation implements the [backendpb.RemoteKVMetrics] interface for *BackendRemoteKV.

type Billstat

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

Billstat is the Prometheus-based implementation of the [billstat.Metrics] interface.

func NewBillstat

func NewBillstat(namespace string, reg prometheus.Registerer) (m *Billstat, err error)

NewBillstat registers the billing-statistics metrics in reg and returns a properly initialized Billstat.

func (*Billstat) HandleUploadDuration

func (m *Billstat) HandleUploadDuration(_ context.Context, dur float64, err error)

HandleUploadDuration implements the [billstat.Metrics] interface for *Billstat.

func (*Billstat) SetRecordCount

func (m *Billstat) SetRecordCount(_ context.Context, count int)

SetRecordCount implements the [billstat.Metrics] interface for *Billstat.

type ClonerStat

type ClonerStat struct{}

ClonerStat is the Prometheus-based implementation of the [dnsmsg.ClonerStat] interface.

func (ClonerStat) OnClone

func (ClonerStat) OnClone(isFull bool)

OnClone implements the [dnsmsg.ClonerStat] interface for ClonerStat.

type ConnLimiter

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

ConnLimiter is a Prometheus-based implementation of the [connlimiter.Metrics] interface.

func NewConnLimiter

func NewConnLimiter(namespace string, reg prometheus.Registerer) (m *ConnLimiter, err error)

NewConnLimiter registers the stream-connections metrics in reg and returns a properly initialized *ConnLimiter.

func (*ConnLimiter) DecrementActive

func (c *ConnLimiter) DecrementActive(_ context.Context, m *ConnLimiterConnMetricsData)

DecrementActive implements the [Metrics] interface for *ConnLimiter.

func (*ConnLimiter) IncrementActive

func (c *ConnLimiter) IncrementActive(_ context.Context, m *ConnLimiterConnMetricsData)

IncrementActive implements the [Metrics] interface for *ConnLimiter.

func (*ConnLimiter) ObserveLifeDuration

func (c *ConnLimiter) ObserveLifeDuration(
	_ context.Context,
	m *ConnLimiterConnMetricsData,
	dur time.Duration,
)

ObserveLifeDuration implements the [Metrics] interface for *ConnLimiter.

func (*ConnLimiter) ObserveWaitingDuration

func (c *ConnLimiter) ObserveWaitingDuration(
	_ context.Context,
	m *ConnLimiterConnMetricsData,
	dur time.Duration,
)

ObserveWaitingDuration implements the [Metrics] interface for *ConnLimiter.

func (*ConnLimiter) SetResumeLimit

func (c *ConnLimiter) SetResumeLimit(_ context.Context, n uint64)

SetResumeLimit implements the [Metrics] interface for *ConnLimiter.

func (*ConnLimiter) SetStopLimit

func (c *ConnLimiter) SetStopLimit(_ context.Context, n uint64)

SetStopLimit implements the [Metrics] interface for *ConnLimiter.

type ConnLimiterConnMetricsData

type ConnLimiterConnMetricsData = struct {
	// Addr is the address that the server is configured to listen on.
	Addr string

	// Name is the name of the server.
	Name string

	// Proto is the protocol of the server.
	Proto string
}

ConnLimiterConnMetricsData is an alias for a structure that contains information about a stream-connection. All fields must not be empty.

See [connlimiter.ConnMetricsData].

type DNSCheck

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

DNSCheck is the Prometheus-based implementation of the [dnscheck.Metrics] interface.

func NewDNSCheck

func NewDNSCheck(namespace string, reg prometheus.Registerer) (m *DNSCheck, err error)

NewDNSCheck registers the DNS checker metrics in reg and returns a properly initialized *DNSCheck.

func (*DNSCheck) HandleError

func (m *DNSCheck) HandleError(_ context.Context, reqType, errType string)

HandleError implements the [dnscheck.Metrics] interface for *DNSCheck. reqType must be "dns" or "http". errType must be either "timeout", "ratelimit", "other" or an empty string.

func (*DNSCheck) HandleRequest

func (m *DNSCheck) HandleRequest(_ context.Context, reqType string, isValid bool)

HandleRequest implements the [dnscheck.Metrics] interface for *DNSCheck. reqType must be "dns" or "http".

type DNSDB

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

DNSDB is the Prometheus-based implementation of the [dnsdb.Metrics] interface.

func NewDNSDB

func NewDNSDB(namespace string, reg prometheus.Registerer) (m *DNSDB, err error)

NewDNSDB registers the filtering rule metrics in reg and returns a properly initialized *DNSDB.

func (*DNSDB) ObserveRotation

func (m *DNSDB) ObserveRotation(_ context.Context, dur time.Duration)

ObserveRotation implements the [dnsdb.Metrics] interface for *DNSDB.

func (*DNSDB) SetRecordCount

func (m *DNSDB) SetRecordCount(_ context.Context, count int)

SetRecordCount implements the [dnsdb.Metrics] interface for *DNSDB.

type DefaultMainMiddleware

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

DefaultMainMiddleware is the Prometheus-based implementation of the MainMiddleware interface.

func NewDefaultMainMiddleware

func NewDefaultMainMiddleware(
	logger *slog.Logger,
	namespace string,
	reg prometheus.Registerer,
) (m *DefaultMainMiddleware, err error)

NewDefaultMainMiddleware registers the filtering-middleware metrics in reg and returns a properly initialized *DefaultMainMiddleware. All arguments must be set.

func (*DefaultMainMiddleware) OnRequest

OnRequest implements the [Metrics] interface for *DefaultMainMiddleware.

type DefaultRatelimitMiddleware

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

DefaultRatelimitMiddleware is the Prometheus-based implementation of the RatelimitMiddleware interface.

func NewDefaultRatelimitMiddleware

func NewDefaultRatelimitMiddleware(
	namespace string,
	reg prometheus.Registerer,
) (m *DefaultRatelimitMiddleware, err error)

NewDefaultRatelimitMiddleware registers the middleware metrics of the access and ratelimiting middleware in reg and returns a properly initialized *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementAccessBlockedByHost

func (m *DefaultRatelimitMiddleware) IncrementAccessBlockedByHost(_ context.Context)

IncrementAccessBlockedByHost implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementAccessBlockedByProfile

func (m *DefaultRatelimitMiddleware) IncrementAccessBlockedByProfile(_ context.Context)

IncrementAccessBlockedByProfile implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementAccessBlockedBySubnet

func (m *DefaultRatelimitMiddleware) IncrementAccessBlockedBySubnet(_ context.Context)

IncrementAccessBlockedBySubnet implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementRatelimitedByProfile

func (m *DefaultRatelimitMiddleware) IncrementRatelimitedByProfile(_ context.Context)

IncrementRatelimitedByProfile implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) IncrementUnknownDedicated

func (m *DefaultRatelimitMiddleware) IncrementUnknownDedicated(_ context.Context)

IncrementUnknownDedicated implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) OnAllowlisted

func (m *DefaultRatelimitMiddleware) OnAllowlisted(
	ctx context.Context,
	req *dns.Msg,
	rw dnsserver.ResponseWriter,
)

OnAllowlisted implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

func (*DefaultRatelimitMiddleware) OnRateLimited

func (m *DefaultRatelimitMiddleware) OnRateLimited(
	ctx context.Context,
	req *dns.Msg,
	rw dnsserver.ResponseWriter,
)

OnRateLimited implements the RatelimitMiddleware interface for *DefaultRatelimitMiddleware.

type ECSCache

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

ECSCache is a Prometheus-based implementation of the [ecscache.Metrics] interface.

func NewECSCache

func NewECSCache(namespace string, reg prometheus.Registerer) (m *ECSCache, err error)

NewECSCache registers the ECS cache metrics in reg and returns a properly initialized *ECSCache.

func (*ECSCache) IncrementLookups

func (m *ECSCache) IncrementLookups(_ context.Context, supportsECS, hit bool)

IncrementLookups implements the [ecscache.Metrics] interface for *ECSCache.

func (*ECSCache) SetElementsCount

func (m *ECSCache) SetElementsCount(_ context.Context, supportsECS bool, count int)

SetElementsCount implements the [ecscache.Metrics] interface for *ECSCache.

type Filter

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

Filter is the Prometheus-based implementation of the Filter interface.

func NewFilter

func NewFilter(namespace string, reg prometheus.Registerer) (m *Filter, err error)

NewFilter registers the filtering metrics in reg and returns a properly initialized *Filter.

func (*Filter) SetFilterStatus

func (m *Filter) SetFilterStatus(
	_ context.Context,
	id string,
	updTime time.Time,
	ruleCount int,
	err error,
)

SetFilterStatus implements the [filter.Metrics] interface for *Filter.

type GRPCError

type GRPCError = string

GRPCError is a type alias for string that contains gGRPC error type.

See [backendpb.GRPCMetrics.IncrementErrorCount].

const (
	GRPCErrAuthentication GRPCError = "auth"
	GRPCErrBadRequest     GRPCError = "bad_req"
	GRPCErrDeviceQuota    GRPCError = "dev_quota"
	GRPCErrOther          GRPCError = "other"
	GRPCErrRateLimit      GRPCError = "rate_limit"
	GRPCErrTimeout        GRPCError = "timeout"
)

gRPC errors of GRPCError type.

NOTE: Keep in sync with [backendpb.GRPCError].

type GeoIP

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

GeoIP is the Prometheus-based implementation of the [geoip.Metrics] interface.

func NewGeoIP

func NewGeoIP(
	namespace string,
	reg prometheus.Registerer,
	asnPath string,
	ctryPath string,
) (m *GeoIP, err error)

NewGeoIP registers the GeoIP metrics in reg and returns a properly initialized GeoIP.

func (*GeoIP) HandleASNUpdateStatus

func (m *GeoIP) HandleASNUpdateStatus(_ context.Context, err error)

HandleASNUpdateStatus implements the [geoip.Metrics] interface for *GeoIP.

func (*GeoIP) HandleCountryUpdateStatus

func (m *GeoIP) HandleCountryUpdateStatus(_ context.Context, err error)

HandleCountryUpdateStatus implements the [geoip.Metrics] interface for *GeoIP.

func (*GeoIP) IncrementHostCacheLookups

func (m *GeoIP) IncrementHostCacheLookups(_ context.Context, hit bool)

IncrementHostCacheLookups implements the [geoip.Metrics] interface for *GeoIP.

func (*GeoIP) IncrementIPCacheLookups

func (m *GeoIP) IncrementIPCacheLookups(_ context.Context, hit bool)

IncrementIPCacheLookups implements the [geoip.Metrics] interface for *GeoIP.

type HashPrefixFilter

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

HashPrefixFilter is the Prometheus-based implementation of the [hashprefix.Metrics] interface.

func NewHashPrefixFilter

func NewHashPrefixFilter(
	namespace string,
	filterName string,
	reg prometheus.Registerer,
) (m *HashPrefixFilter, err error)

NewHashPrefixFilter registers the filtering metrics in reg and returns a properly initialized *HashPrefixFilter. filterName must be a valid label name.

func (*HashPrefixFilter) IncrementLookups

func (m *HashPrefixFilter) IncrementLookups(_ context.Context, hit bool)

IncrementLookups implements the [hashprefix.Metrics] interface for *HashPrefixFilter.

func (*HashPrefixFilter) UpdateCacheSize

func (m *HashPrefixFilter) UpdateCacheSize(_ context.Context, size int)

UpdateCacheSize implements the [hashprefix.Metrics] interface for *HashPrefixFilter.

type MainMiddleware

type MainMiddleware interface {
	OnRequest(ctx context.Context, m *MainMiddlewareRequestMetrics)
}

MainMiddleware is an interface for collection of the statistics of the main filtering middleware.

NOTE: Keep in sync with [dnssvc.MainMiddleware].

type MainMiddlewareRequestMetrics

type MainMiddlewareRequestMetrics = struct {
	RemoteIP          netip.Addr
	Continent         string
	Country           string
	FilterListID      string
	FilteringDuration time.Duration
	ASN               uint32
	IsAnonymous       bool
	IsBlocked         bool
}

MainMiddlewareRequestMetrics is an alias for a structure that contains the information about a request that has reached the filtering middleware.

See [mainmw.RequestMetrics].

type ProfileDB

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

ProfileDB is the Prometheus-based implementation of the [profiledb.Metrics] interface.

func NewProfileDB

func NewProfileDB(namespace string, reg prometheus.Registerer) (m *ProfileDB, err error)

NewProfileDB registers the user profiles metrics in reg and returns a properly initialized ProfileDB.

func (*ProfileDB) HandleProfilesUpdate

func (m *ProfileDB) HandleProfilesUpdate(_ context.Context, u *UpdateMetrics)

HandleProfilesUpdate implements the [profilesdb.Metrics] interface for *ProfileDB.

func (*ProfileDB) IncrementDeleted

func (m *ProfileDB) IncrementDeleted(_ context.Context)

IncrementDeleted implements the [profilesdb.Metrics] interface for *ProfileDB.

func (*ProfileDB) IncrementSyncTimeouts

func (m *ProfileDB) IncrementSyncTimeouts(_ context.Context, isFullSync bool)

IncrementSyncTimeouts implements the [profilesdb.Metrics] interface for *ProfileDB.

func (*ProfileDB) SetProfilesAndDevicesNum

func (m *ProfileDB) SetProfilesAndDevicesNum(_ context.Context, profNum, devNum uint)

SetProfilesAndDevicesNum implements the [profilesdb.Metrics] interface for *ProfileDB.

type QueryLog

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

QueryLog is the Prometheus-based implementation of the [querylog.Metrics] interface.

func NewQueryLog

func NewQueryLog(namespace string, reg prometheus.Registerer) (m *QueryLog, err error)

NewQueryLog creates a new Prometheus-based query log metrics collector.

func (*QueryLog) IncrementItemsCount

func (m *QueryLog) IncrementItemsCount(_ context.Context)

IncrementItemsCount implements the [querylog.Metrics] interface for *QueryLog.

func (*QueryLog) ObserveItemSize

func (m *QueryLog) ObserveItemSize(_ context.Context, size datasize.ByteSize)

ObserveItemSize implements the [querylog.Metrics] interface for *QueryLog.

func (*QueryLog) ObserveWriteDuration

func (m *QueryLog) ObserveWriteDuration(_ context.Context, dur time.Duration)

ObserveWriteDuration implements the [querylog.Metrics] interface for *QueryLog.

type RatelimitMiddleware

type RatelimitMiddleware interface {
	ratelimit.Metrics

	IncrementAccessBlockedByHost(ctx context.Context)
	IncrementAccessBlockedByProfile(ctx context.Context)
	IncrementAccessBlockedBySubnet(ctx context.Context)
	IncrementRatelimitedByProfile(ctx context.Context)
	IncrementUnknownDedicated(ctx context.Context)
}

RatelimitMiddleware is an interface for collection of the statistics of the access and ratelimit middleware.

NOTE: Keep in sync with [dnssvc.RatelimitMiddleware].

type RedisKV

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

RedisKV is the Prometheus-based implementation of the [rediskv.Metrics] interface.

func NewRedisKV

func NewRedisKV(namespace string, reg prometheus.Registerer) (m *RedisKV, err error)

NewRedisKV registers the Redis KV metrics in reg and returns a properly initialized RedisKV.

func (*RedisKV) UpdateMetrics

func (m *RedisKV) UpdateMetrics(_ context.Context, val uint, err error)

UpdateMetrics implements the [rediskv.Metrics] interface for *RedisKV.

type RemoteKVOp

type RemoteKVOp = string

RemoteKVOp is the type alias for string that contains remote key-value storage operation name.

See [backendpb.RemoteKVMetrics.ObserveOperation].

const (
	RemoteKVOpGet RemoteKVOp = "get"
	RemoteKVOpSet RemoteKVOp = "set"
)

Remote key-value storage operation names for RemoteKVOp.

NOTE: Keep in sync with [backendpb.RemoteKVOp].

type RuleStat

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

RuleStat is the Prometheus-based implementation of the [rulestat.Metrics] interface.

func NewRuleStat

func NewRuleStat(namespace string, reg prometheus.Registerer) (m *RuleStat, err error)

NewRuleStat registers the filtering rule metrics in reg and returns a properly initialized *RuleStat.

func (*RuleStat) HandleUploadStatus

func (m *RuleStat) HandleUploadStatus(_ context.Context, err error)

HandleUploadStatus implements the [rulestat.Metrics] interface for *RuleStat.

func (*RuleStat) SetHitCount

func (m *RuleStat) SetHitCount(_ context.Context, count int64)

SetHitCount implements the [rulestat.Metrics] interface for *RuleStat.

type TLSConfig

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

TLSConfig is the Prometheus-based implementation of the [tlsconfig.Metrics] interface.

func NewTLSConfig

func NewTLSConfig(namespace string, reg prometheus.Registerer) (m *TLSConfig, err error)

NewTLSConfig registers the TLS-related metrics in reg and returns a properly initialized TLSConfig.

func (*TLSConfig) AfterHandshake

func (m *TLSConfig) AfterHandshake(
	proto string,
	srvName string,
	devDomains []string,
	srvCerts []*tls.Certificate,
) (f func(tls.ConnectionState) error)

AfterHandshake implements the [tlsconfig.Metrics] interface for *TLSConfig.

func (*TLSConfig) BeforeHandshake

func (m *TLSConfig) BeforeHandshake(
	proto string,
) (f func(*tls.ClientHelloInfo) (*tls.Config, error))

BeforeHandshake implements the [tlsconfig.Metrics] interface for *TLSConfig.

func (*TLSConfig) SetCertificateInfo

func (m *TLSConfig) SetCertificateInfo(_ context.Context, algo, subj string, notAfter time.Time)

SetCertificateInfo implements the [tlsconfig.Metrics] interface for *TLSConfig.

func (*TLSConfig) SetSessionTicketRotationStatus

func (m *TLSConfig) SetSessionTicketRotationStatus(_ context.Context, err error)

SetSessionTicketRotationStatus implements the [tlsconfig.Metrics] interface for *TLSConfig.

type UpdateMetrics

type UpdateMetrics = struct {
	Duration    time.Duration
	ProfilesNum uint
	DevicesNum  uint
	IsSuccess   bool
	IsFullSync  bool
}

UpdateMetrics is an alias for a structure that contains the information about a user profiles update operation.

See [profiledb.UpdateMetrics].

type UserCounter

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

UserCounter is used to save estimated counts of active users per hour and per day by some data.

TODO(a.garipov): Improve and move to golibs.

func NewUserCounter

func NewUserCounter(logger *slog.Logger, lastHour, lastDay prometheus.Gauge) (c *UserCounter)

NewUserCounter initializes and returns a properly initialized *UserCounter that uses the given gauges to estimate the user count. All arguments must not be nil.

func (*UserCounter) Estimate

func (c *UserCounter) Estimate() (hourly, daily uint64)

Estimate uses HyperLogLog counters to return the number of users for the last hour and the last day. It doesn't include the data for current minute.

It must not be called concurrently with [UserCounter.updateCounters].

TODO(a.garipov): Unexport and use gauges instead?

func (*UserCounter) Record

func (c *UserCounter) Record(ctx context.Context, now time.Time, userData []byte, syncUpdate bool)

Record updates the current minute-of-the-day counter as well as sets the values of the hourly and daily metric counters, if necessary. now is the time for which to Record the IP address or other data, typically the current time.

If syncUpdate is true, Record performs the metric counter updates synchronously. It is currently only used in tests.

It currently assumes that it will be called at least once per day.

Jump to

Keyboard shortcuts

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