billstat

package
v0.0.0-...-f179113 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package billstat implements the AdGuard DNS billing statistics database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmptyMetrics

type EmptyMetrics struct{}

EmptyMetrics is the implementation of the Metrics interface that does nothing.

func (EmptyMetrics) BufferSizeSet

func (EmptyMetrics) BufferSizeSet(_ context.Context, _ float64)

BufferSizeSet implements the Metrics interface for EmptyMetrics.

func (EmptyMetrics) HandleUploadDuration

func (EmptyMetrics) HandleUploadDuration(_ context.Context, _ float64, _ bool)

HandleUploadDuration implements the Metrics interface for EmptyMetrics.

type EmptyRecorder

type EmptyRecorder struct{}

EmptyRecorder is a billing statistics recorder that does nothing.

func (EmptyRecorder) Record

Record implements the Recorder interface for EmptyRecorder.

type Metrics

type Metrics interface {
	// BufferSizeSet sets the number of stored records to n.
	BufferSizeSet(ctx context.Context, n float64)

	// HandleUploadDuration handles the upload duration of billing statistics.
	HandleUploadDuration(ctx context.Context, dur float64, isSuccess bool)
}

Metrics is an interface that is used for the collection of the billing statistics.

type Record

type Record struct {
	// Time is the time of the most recent query from the device.
	Time time.Time

	// Country is the detected country of the client's IP address, if any.
	Country geoip.Country

	// ASN is the detected ASN of the client's IP address, if any.
	ASN geoip.ASN

	// Queries is the total number of Queries the device has performed since the
	// most recent sync.  This value is an int32 to be in sync with the business
	// logic backend which uses this type.  Change it if it is changed there.
	// Queries must not be negative.
	Queries int32

	// Proto is the DNS protocol of the most recent query from the device.
	Proto agd.Protocol
}

Record is a single billing statistics Record.

type Recorder

type Recorder interface {
	Record(
		ctx context.Context,
		id agd.DeviceID,
		ctry geoip.Country,
		asn geoip.ASN,
		start time.Time,
		proto agd.Protocol,
	)
}

Recorder is the billing statistics recorder interface.

type Records

type Records = map[agd.DeviceID]*Record

Records is a helpful alias for a mapping of devices to their billing statistics records.

type RuntimeRecorder

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

RuntimeRecorder is the runtime billing statistics recorder. The records kept here are not persistent.

func NewRuntimeRecorder

func NewRuntimeRecorder(c *RuntimeRecorderConfig) (r *RuntimeRecorder)

NewRuntimeRecorder creates a new runtime billing statistics database. c must be non-nil.

func (*RuntimeRecorder) Record

func (r *RuntimeRecorder) Record(
	ctx context.Context,
	id agd.DeviceID,
	ctry geoip.Country,
	asn geoip.ASN,
	start time.Time,
	proto agd.Protocol,
)

Record implements the Recorder interface for *RuntimeRecorder.

func (*RuntimeRecorder) Refresh

func (r *RuntimeRecorder) Refresh(ctx context.Context) (err error)

Refresh implements the [agdserivce.Refresher] interface for *RuntimeRecorder. It uploads the currently available data and resets it.

type RuntimeRecorderConfig

type RuntimeRecorderConfig struct {
	// Logger is used for logging the operation of the recorder.
	Logger *slog.Logger

	// ErrColl is used to collect errors during refreshes.
	ErrColl errcoll.Interface

	// Uploader is used to upload the billing statistics records to.
	Uploader Uploader

	// Metrics is used for the collection of the billing statistics.
	Metrics Metrics
}

RuntimeRecorderConfig is the configuration structure for a runtime billing statistics recorder. All fields must be non-empty.

type Uploader

type Uploader interface {
	Upload(ctx context.Context, records Records) (err error)
}

Uploader is the interface for a backend that accepts the billing statistics records.

Jump to

Keyboard shortcuts

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