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) HandleUploadDuration ¶
func (EmptyMetrics) HandleUploadDuration(_ context.Context, _ float64, _ error)
HandleUploadDuration implements the Metrics interface for EmptyMetrics.
func (EmptyMetrics) SetRecordCount ¶
func (EmptyMetrics) SetRecordCount(_ context.Context, _ int)
SetRecordCount implements the Metrics interface for EmptyMetrics.
type EmptyRecorder ¶
type EmptyRecorder struct{}
EmptyRecorder is a billing statistics recorder that does nothing.
type Metrics ¶
type Metrics interface { // SetRecordCount sets the total number of records stored. SetRecordCount(ctx context.Context, count int) // HandleUploadDuration handles the upload duration of billing statistics. HandleUploadDuration(ctx context.Context, dur float64, err error) }
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 ¶
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 service.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.