pbsmetrics

package
v0.0.0-...-ea31b78 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const PublisherUnknown = "unknown"

PublisherUnknown: Default value for Labels.PubID

Variables

This section is empty.

Functions

This section is empty.

Types

type AdapterBid

type AdapterBid string

AdapterBid : Whether or not the adapter returned bids

const (
	AdapterBidPresent AdapterBid = "bid"
	AdapterBidNone    AdapterBid = "nobid"
)

Adapter bid response status.

func AdapterBids

func AdapterBids() []AdapterBid

type AdapterError

type AdapterError string

AdapterError : Errors which may have occurred during the adapter's execution

const (
	AdapterErrorBadInput            AdapterError = "badinput"
	AdapterErrorBadServerResponse   AdapterError = "badserverresponse"
	AdapterErrorTimeout             AdapterError = "timeout"
	AdapterErrorFailedToRequestBids AdapterError = "failedtorequestbid"
	AdapterErrorUnknown             AdapterError = "unknown_error"
)

Adapter execution status

func AdapterErrors

func AdapterErrors() []AdapterError

type AdapterLabels

type AdapterLabels struct {
	Source        DemandSource
	RType         RequestType
	Adapter       openrtb_ext.BidderName
	PubID         string // exchange specific ID, so we cannot compile in values
	Browser       Browser
	CookieFlag    CookieFlag
	AdapterBids   AdapterBid
	AdapterErrors map[AdapterError]struct{}
}

AdapterLabels defines the labels that can be attached to the adapter metrics.

type AdapterMetrics

type AdapterMetrics struct {
	NoCookieMeter     metrics.Meter
	ErrorMeters       map[AdapterError]metrics.Meter
	NoBidMeter        metrics.Meter
	GotBidsMeter      metrics.Meter
	RequestTimer      metrics.Timer
	PriceHistogram    metrics.Histogram
	BidsReceivedMeter metrics.Meter
	PanicMeter        metrics.Meter
	MarkupMetrics     map[openrtb_ext.BidType]*MarkupDeliveryMetrics
}

AdapterMetrics houses the metrics for a particular adapter

type Browser

type Browser string

Browser type enumeration

const (
	BrowserSafari Browser = "safari"
	BrowserOther  Browser = "other"
)

Browser flag; at this point we only care about identifying Safari

func BrowserTypes

func BrowserTypes() []Browser

type CacheResult

type CacheResult string

CacheResult : Cache hit/miss

const (
	// CacheHit represents a cache hit i.e the key was found in cache
	CacheHit CacheResult = "hit"
	// CacheMiss represents a cache miss i.e that key wasn't found in cache
	// and had to be fetched from the backend
	CacheMiss CacheResult = "miss"
)

func CacheResults

func CacheResults() []CacheResult

CacheResults returns possible cache results i.e. cache hit or miss

type CookieFlag

type CookieFlag string

CookieFlag : User ID cookie exists flag

const (
	CookieFlagYes     CookieFlag = "exists"
	CookieFlagNo      CookieFlag = "no"
	CookieFlagUnknown CookieFlag = "unknown"
)

Cookie flag

func CookieTypes

func CookieTypes() []CookieFlag

type DemandSource

type DemandSource string

DemandSource : Demand source enumeration

const (
	DemandWeb     DemandSource = "web"
	DemandApp     DemandSource = "app"
	DemandUnknown DemandSource = "unknown"
)

The demand sources

func DemandTypes

func DemandTypes() []DemandSource

type ImpLabels

type ImpLabels struct {
	BannerImps bool
	VideoImps  bool
	AudioImps  bool
	NativeImps bool
}

ImpLabels

type ImpMediaType

type ImpMediaType string

ImpMediaType : Media type described in the "imp" JSON object TODO is this still needed?

const (
	ImpTypeBanner ImpMediaType = "banner"
	ImpTypeVideo  ImpMediaType = "video"
	ImpTypeAudio  ImpMediaType = "audio"
	ImpTypeNative ImpMediaType = "native"
)

The media types described in the "imp" json objects

func ImpTypes

func ImpTypes() []ImpMediaType

type Labels

type Labels struct {
	Source        DemandSource
	RType         RequestType
	PubID         string // exchange specific ID, so we cannot compile in values
	Browser       Browser
	CookieFlag    CookieFlag
	RequestStatus RequestStatus
}

Labels defines the labels that can be attached to the metrics.

type MarkupDeliveryMetrics

type MarkupDeliveryMetrics struct {
	AdmMeter  metrics.Meter
	NurlMeter metrics.Meter
}

type Metrics

type Metrics struct {
	MetricsRegistry            metrics.Registry
	ConnectionCounter          metrics.Counter
	ConnectionAcceptErrorMeter metrics.Meter
	ConnectionCloseErrorMeter  metrics.Meter
	ImpMeter                   metrics.Meter
	LegacyImpMeter             metrics.Meter
	AppRequestMeter            metrics.Meter
	NoCookieMeter              metrics.Meter
	SafariRequestMeter         metrics.Meter
	SafariNoCookieMeter        metrics.Meter
	RequestTimer               metrics.Timer
	StoredReqCacheMeter        map[CacheResult]metrics.Meter
	StoredImpCacheMeter        map[CacheResult]metrics.Meter

	// Metrics for OpenRTB requests specifically. So we can track what % of RequestsMeter are OpenRTB
	// and know when legacy requests have been abandoned.
	RequestStatuses       map[RequestType]map[RequestStatus]metrics.Meter
	AmpNoCookieMeter      metrics.Meter
	CookieSyncMeter       metrics.Meter
	CookieSyncGen         map[openrtb_ext.BidderName]metrics.Meter
	CookieSyncGDPRPrevent map[openrtb_ext.BidderName]metrics.Meter

	// Media types found in the "imp" JSON object
	ImpsTypeBanner metrics.Meter
	ImpsTypeVideo  metrics.Meter
	ImpsTypeAudio  metrics.Meter
	ImpsTypeNative metrics.Meter

	AdapterMetrics map[openrtb_ext.BidderName]*AdapterMetrics
	// contains filtered or unexported fields
}

Metrics is the legacy Metrics object (go-metrics) expanded to also satisfy the MetricsEngine interface

func NewBlankMetrics

func NewBlankMetrics(registry metrics.Registry, exchanges []openrtb_ext.BidderName) *Metrics

NewBlankMetrics creates a new Metrics object with all blank metrics object. This may also be useful for testing routines to ensure that no metrics are written anywhere.

This will be useful when removing endpoints, we can just run will the blank metrics function rather than loading legacy metrics that never get filled. This will also eventually let us configure metrics, such as setting a limited set of metrics for a production instance, and then expanding again when we need more debugging.

func NewMetrics

func NewMetrics(registry metrics.Registry, exchanges []openrtb_ext.BidderName) *Metrics

NewMetrics creates a new Metrics object with needed metrics defined. In time we may develop to the point where Metrics contains all the metrics we might want to record, and then we build the actual metrics object to contain only the metrics we are interested in. This would allow for debug mode metrics. The code would allways try to record the metrics, but effectively noop if we are using a blank meter/timer.

func (*Metrics) RecordAdapterBidReceived

func (me *Metrics) RecordAdapterBidReceived(labels AdapterLabels, bidType openrtb_ext.BidType, hasAdm bool)

RecordAdapterBidReceived implements a part of the MetricsEngine interface. This tracks how many bids from each Bidder use `adm` vs. `nurl.

func (*Metrics) RecordAdapterCookieSync

func (me *Metrics) RecordAdapterCookieSync(adapter openrtb_ext.BidderName, gdprBlocked bool)

RecordAdapterCookieSync implements a part of the MetricsEngine interface. Records a cookie sync adpter sync request and gdpr status

func (*Metrics) RecordAdapterPanic

func (me *Metrics) RecordAdapterPanic(labels AdapterLabels)

RecordAdapterPanic implements a part of the MetricsEngine interface

func (*Metrics) RecordAdapterPrice

func (me *Metrics) RecordAdapterPrice(labels AdapterLabels, cpm float64)

RecordAdapterPrice implements a part of the MetricsEngine interface. Generates a histogram of winning bid prices

func (*Metrics) RecordAdapterRequest

func (me *Metrics) RecordAdapterRequest(labels AdapterLabels)

RecordAdapterRequest implements a part of the MetricsEngine interface

func (*Metrics) RecordAdapterTime

func (me *Metrics) RecordAdapterTime(labels AdapterLabels, length time.Duration)

RecordAdapterTime implements a part of the MetricsEngine interface. Records the adapter response time

func (*Metrics) RecordConnectionAccept

func (me *Metrics) RecordConnectionAccept(success bool)

func (*Metrics) RecordConnectionClose

func (me *Metrics) RecordConnectionClose(success bool)

func (*Metrics) RecordCookieSync

func (me *Metrics) RecordCookieSync(labels Labels)

RecordCookieSync implements a part of the MetricsEngine interface. Records a cookie sync request

func (*Metrics) RecordImps

func (me *Metrics) RecordImps(labels ImpLabels)

func (*Metrics) RecordLegacyImps

func (me *Metrics) RecordLegacyImps(labels Labels, numImps int)

func (*Metrics) RecordRequest

func (me *Metrics) RecordRequest(labels Labels)

RecordRequest implements a part of the MetricsEngine interface

func (*Metrics) RecordRequestTime

func (me *Metrics) RecordRequestTime(labels Labels, length time.Duration)

RecordRequestTime implements a part of the MetricsEngine interface. The calling code is responsible for determining the call duration.

func (*Metrics) RecordStoredImpCacheResult

func (me *Metrics) RecordStoredImpCacheResult(cacheResult CacheResult, inc int)

func (*Metrics) RecordStoredReqCacheResult

func (me *Metrics) RecordStoredReqCacheResult(cacheResult CacheResult, inc int)

RecordStoredReqCacheResult implements a part of the MetricsEngine interface. Records the cache hits and misses when looking up stored requests

func (*Metrics) RecordUserIDSet

func (me *Metrics) RecordUserIDSet(userLabels UserLabels)

RecordUserIDSet implements a part of the MetricsEngine interface. Records a cookie setuid request

type MetricsEngine

type MetricsEngine interface {
	RecordConnectionAccept(success bool)
	RecordConnectionClose(success bool)
	RecordRequest(labels Labels)                           // ignores adapter. only statusOk and statusErr fom status
	RecordImps(labels ImpLabels)                           // RecordImps across openRTB2 engines that support the 'Native' Imp Type
	RecordLegacyImps(labels Labels, numImps int)           // RecordImps for the legacy engine
	RecordRequestTime(labels Labels, length time.Duration) // ignores adapter. only statusOk and statusErr fom status
	RecordAdapterRequest(labels AdapterLabels)
	RecordAdapterPanic(labels AdapterLabels)
	// This records whether or not a bid of a particular type uses `adm` or `nurl`.
	// Since the legacy endpoints don't have a bid type, it can only count bids from OpenRTB and AMP.
	RecordAdapterBidReceived(labels AdapterLabels, bidType openrtb_ext.BidType, hasAdm bool)
	RecordAdapterPrice(labels AdapterLabels, cpm float64)
	RecordAdapterTime(labels AdapterLabels, length time.Duration)
	RecordCookieSync(labels Labels) // May ignore all labels
	RecordAdapterCookieSync(adapter openrtb_ext.BidderName, gdprBlocked bool)
	RecordUserIDSet(userLabels UserLabels) // Function should verify bidder values
	RecordStoredReqCacheResult(cacheResult CacheResult, inc int)
	RecordStoredImpCacheResult(cacheResult CacheResult, inc int)
}

MetricsEngine is a generic interface to record PBS metrics into the desired backend The first three metrics function fire off once per incoming request, so total metrics will equal the total numer of incoming requests. The remaining 5 fire off per outgoing request to a bidder adapter, so will record a number of hits per incoming request. The two groups should be consistent within themselves, but comparing numbers between groups is generally not useful.

type MetricsEngineMock

type MetricsEngineMock struct {
	mock.Mock
}

MetricsEngineMock is mock for the MetricsEngine interface

func (*MetricsEngineMock) RecordAdapterBidReceived

func (me *MetricsEngineMock) RecordAdapterBidReceived(labels AdapterLabels, bidType openrtb_ext.BidType, hasAdm bool)

RecordAdapterBidReceived mock

func (*MetricsEngineMock) RecordAdapterCookieSync

func (me *MetricsEngineMock) RecordAdapterCookieSync(adapter openrtb_ext.BidderName, gdprBlocked bool)

RecordAdapterCookieSync mock

func (*MetricsEngineMock) RecordAdapterPanic

func (me *MetricsEngineMock) RecordAdapterPanic(labels AdapterLabels)

RecordAdapterPanic mock

func (*MetricsEngineMock) RecordAdapterPrice

func (me *MetricsEngineMock) RecordAdapterPrice(labels AdapterLabels, cpm float64)

RecordAdapterPrice mock

func (*MetricsEngineMock) RecordAdapterRequest

func (me *MetricsEngineMock) RecordAdapterRequest(labels AdapterLabels)

RecordAdapterRequest mock

func (*MetricsEngineMock) RecordAdapterTime

func (me *MetricsEngineMock) RecordAdapterTime(labels AdapterLabels, length time.Duration)

RecordAdapterTime mock

func (*MetricsEngineMock) RecordConnectionAccept

func (me *MetricsEngineMock) RecordConnectionAccept(success bool)

RecordConnectionAccept mock

func (*MetricsEngineMock) RecordConnectionClose

func (me *MetricsEngineMock) RecordConnectionClose(success bool)

RecordConnectionClose mock

func (*MetricsEngineMock) RecordCookieSync

func (me *MetricsEngineMock) RecordCookieSync(labels Labels)

RecordCookieSync mock

func (*MetricsEngineMock) RecordImps

func (me *MetricsEngineMock) RecordImps(labels ImpLabels)

RecordImps mock

func (*MetricsEngineMock) RecordLegacyImps

func (me *MetricsEngineMock) RecordLegacyImps(labels Labels, numImps int)

RecordLegacyImps mock

func (*MetricsEngineMock) RecordRequest

func (me *MetricsEngineMock) RecordRequest(labels Labels)

RecordRequest mock

func (*MetricsEngineMock) RecordRequestTime

func (me *MetricsEngineMock) RecordRequestTime(labels Labels, length time.Duration)

RecordRequestTime mock

func (*MetricsEngineMock) RecordStoredImpCacheResult

func (me *MetricsEngineMock) RecordStoredImpCacheResult(cacheResult CacheResult, inc int)

RecordStoredImpCacheResult mock

func (*MetricsEngineMock) RecordStoredReqCacheResult

func (me *MetricsEngineMock) RecordStoredReqCacheResult(cacheResult CacheResult, inc int)

RecordStoredReqCacheResult mock

func (*MetricsEngineMock) RecordUserIDSet

func (me *MetricsEngineMock) RecordUserIDSet(userLabels UserLabels)

RecordUserIDSet mock

type RequestAction

type RequestAction string

RequestAction : The setuid request result

const (
	RequestActionSet    RequestAction = "set"
	RequestActionOptOut RequestAction = "opt_out"
	RequestActionGDPR   RequestAction = "gdpr"
	RequestActionErr    RequestAction = "err"
)

/setuid action labels

type RequestStatus

type RequestStatus string

RequestStatus : The request return status

const (
	RequestStatusOK         RequestStatus = "ok"
	RequestStatusBadInput   RequestStatus = "badinput"
	RequestStatusErr        RequestStatus = "err"
	RequestStatusNetworkErr RequestStatus = "networkerr"
)

Request/return status

func RequestStatuses

func RequestStatuses() []RequestStatus

type RequestType

type RequestType string

RequestType : Request type enumeration

const (
	ReqTypeLegacy   RequestType = "legacy"
	ReqTypeORTB2Web RequestType = "openrtb2-web"
	ReqTypeORTB2App RequestType = "openrtb2-app"
	ReqTypeAMP      RequestType = "amp"
	ReqTypeVideo    RequestType = "video"
)

The request types (endpoints)

func RequestTypes

func RequestTypes() []RequestType

type UserLabels

type UserLabels struct {
	Action RequestAction
	Bidder openrtb_ext.BidderName
}

UserLabels : Labels for /setuid endpoint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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