config

package
v0.0.0-...-f16c7e7 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupViper

func SetupViper(v *viper.Viper, filename string)

Set the default config values for the viper object we are using.

Types

type Adapter

type Adapter struct {
	Endpoint    string `mapstructure:"endpoint"` // Required
	UserSyncURL string `mapstructure:"usersync_url"`
	PlatformID  string `mapstructure:"platform_id"` // needed for Facebook
	XAPI        struct {
		Username string `mapstructure:"username"`
		Password string `mapstructure:"password"`
		Tracker  string `mapstructure:"tracker"`
	} `mapstructure:"xapi"` // needed for Rubicon
}

type Analytics

type Analytics struct {
	File FileLogs `mapstructure:"file"`
}

type AuctionTimeouts

type AuctionTimeouts struct {
	// The default timeout is used if the user's request didn't define one. Use 0 if there's no default.
	Default uint64 `mapstructure:"default"`
	// The max timeout is used as an absolute cap, to prevent excessively long ones. Use 0 for no cap
	Max uint64 `mapstructure:"max"`
}

func (*AuctionTimeouts) LimitAuctionTimeout

func (cfg *AuctionTimeouts) LimitAuctionTimeout(requested time.Duration) time.Duration

LimitAuctionTimeout returns the min of requested or cfg.MaxAuctionTimeout. Both values treat "0" as "infinite".

type Cache

type Cache struct {
	Scheme string `mapstructure:"scheme"`
	Host   string `mapstructure:"host"`
	Query  string `mapstructure:"query"`

	// A static timeout here is not ideal. This is a hack because we have some aggressive timelines for OpenRTB support.
	// This value specifies how much time the prebid server host expects a call to prebid cache to take.
	//
	// OpenRTB allows the caller to specify the auction timeout. Prebid Server will subtract _this_ amount of time
	// from the timeout it gives demand sources to respond.
	//
	// In reality, the cache response time will probably fluctuate with the traffic over time. Someday,
	// this should be replaced by code which tracks the response time of recent cache calls and
	// adjusts the time dynamically.
	ExpectedTimeMillis int `mapstructure:"expected_millis"`
}

func (*Cache) GetBaseURL

func (cfg *Cache) GetBaseURL() string

Allows for protocol relative URL if scheme is empty

type Configuration

type Configuration struct {
	ExternalURL string `mapstructure:"external_url"`
	Host        string `mapstructure:"host"`
	Port        int    `mapstructure:"port"`
	AdminPort   int    `mapstructure:"admin_port"`
	// StatusResponse is the string which will be returned by the /status endpoint when things are OK.
	// If empty, it will return a 204 with no content.
	StatusResponse  string          `mapstructure:"status_response"`
	AuctionTimeouts AuctionTimeouts `mapstructure:"auction_timeouts_ms"`
	CacheURL        Cache           `mapstructure:"cache"`
	RecaptchaSecret string          `mapstructure:"recaptcha_secret"`
	HostCookie      HostCookie      `mapstructure:"host_cookie"`
	Metrics         Metrics         `mapstructure:"metrics"`
	DataCache       DataCache       `mapstructure:"datacache"`
	StoredRequests  StoredRequests  `mapstructure:"stored_requests"`

	// Adapters should have a key for every openrtb_ext.BidderName, converted to lower-case.
	// Se also: https://github.com/spf13/viper/issues/371#issuecomment-335388559
	Adapters             map[string]Adapter `mapstructure:"adapters"`
	MaxRequestSize       int64              `mapstructure:"max_request_size"`
	Analytics            Analytics          `mapstructure:"analytics"`
	AMPTimeoutAdjustment int64              `mapstructure:"amp_timeout_adjustment_ms"`
	GDPR                 GDPR               `mapstructure:"gdpr"`
}

Configuration

func New

func New(v *viper.Viper) (*Configuration, error)

New uses viper to get our server configurations.

func (*Configuration) GetCachedAssetURL

func (cfg *Configuration) GetCachedAssetURL(uuid string) string
type Cookie struct {
	Name  string `mapstructure:"name"`
	Value string `mapstructure:"value"`
}

type DataCache

type DataCache struct {
	Type       string `mapstructure:"type"`
	Filename   string `mapstructure:"filename"`
	CacheSize  int    `mapstructure:"cache_size"`
	TTLSeconds int    `mapstructure:"ttl_seconds"`
}

type FileLogs

type FileLogs struct {
	Filename string `mapstructure:"filename"`
}

Corresponding config for FileLogger as a PBS Analytics Module

type GDPR

type GDPR struct {
	HostVendorID        int          `mapstructure:"host_vendor_id"`
	UsersyncIfAmbiguous bool         `mapstructure:"usersync_if_ambiguous"`
	Timeouts            GDPRTimeouts `mapstructure:"timeouts_ms"`
}

type GDPRTimeouts

type GDPRTimeouts struct {
	InitVendorlistFetch   int `mapstructure:"init_vendorlist_fetches"`
	ActiveVendorlistFetch int `mapstructure:"active_vendorlist_fetch"`
}

func (*GDPRTimeouts) ActiveTimeout

func (t *GDPRTimeouts) ActiveTimeout() time.Duration

func (*GDPRTimeouts) InitTimeout

func (t *GDPRTimeouts) InitTimeout() time.Duration

type HTTPEventsConfig

type HTTPEventsConfig struct {
	AmpEndpoint string `mapstructure:"amp_endpoint"`
	Endpoint    string `mapstructure:"endpoint"`
	RefreshRate int64  `mapstructure:"refresh_rate_seconds"`
	Timeout     int    `mapstructure:"timeout_ms"`
}

HTTPEventsConfig configures stored_requests/events/http/http.go

func (HTTPEventsConfig) RefreshRateDuration

func (cfg HTTPEventsConfig) RefreshRateDuration() time.Duration

func (HTTPEventsConfig) TimeoutDuration

func (cfg HTTPEventsConfig) TimeoutDuration() time.Duration

type HTTPFetcherConfig

type HTTPFetcherConfig struct {
	Endpoint    string `mapstructure:"endpoint"`
	AmpEndpoint string `mapstructure:"amp_endpoint"`
}

HTTPFetcherConfig configures a stored_requests/backends/http_fetcher/fetcher.go

type HostCookie

type HostCookie struct {
	Domain       string `mapstructure:"domain"`
	Family       string `mapstructure:"family"`
	CookieName   string `mapstructure:"cookie_name"`
	OptOutURL    string `mapstructure:"opt_out_url"`
	OptInURL     string `mapstructure:"opt_in_url"`
	OptOutCookie Cookie `mapstructure:"optout_cookie"`
	// Cookie timeout in days
	TTL int64 `mapstructure:"ttl_days"`
}

func (*HostCookie) TTLDuration

func (cfg *HostCookie) TTLDuration() time.Duration

type InMemoryCache

type InMemoryCache struct {
	// Identify the type of memory cache. "none", "unbounded", "lru"
	Type string `mapstructure:"type"`
	// TTL is the maximum number of seconds that an unused value will stay in the cache.
	// TTL <= 0 can be used for "no ttl". Elements will still be evicted based on the Size.
	TTL int `mapstructure:"ttl_seconds"`
	// RequestCacheSize is the max number of bytes allowed in the cache for Stored Requests. Values <= 0 will have no limit
	RequestCacheSize int `mapstructure:"request_cache_size_bytes"`
	// ImpCacheSize is the max number of bytes allowed in the cache for Stored Imps. Values <= 0 will have no limit
	ImpCacheSize int `mapstructure:"imp_cache_size_bytes"`
}

type InfluxMetrics

type InfluxMetrics struct {
	Host     string `mapstructure:"host"`
	Database string `mapstructure:"database"`
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
}

type Metrics

type Metrics struct {
	Influxdb   InfluxMetrics     `mapstructure:"influxdb"`
	Prometheus PrometheusMetrics `mapstructure:"prometheus"`
}

type PostgresCacheInitializer

type PostgresCacheInitializer struct {
	Timeout int `mapstructure:"timeout_ms"`
	// Query should be something like:
	//
	// SELECT id, requestData, 'request' AS type FROM stored_requests
	// UNION ALL
	// SELECT id, impData, 'imp' AS type FROM stored_imps
	//
	// This query will be run once on startup to fetch _all_ known Stored Request data from the database.
	//
	// For more details on the expected format of requestData and impData, see stored_requests/events/postgres/polling.go
	Query string `mapstructure:"query"`
	// AmpQuery is just like Query, but for AMP Stored Requests
	AmpQuery string `mapstructure:"amp_query"`
}

type PostgresConfig

type PostgresConfig struct {
	ConnectionInfo      PostgresConnection       `mapstructure:"connection"`
	FetcherQueries      PostgresFetcherQueries   `mapstructure:"fetcher"`
	CacheInitialization PostgresCacheInitializer `mapstructure:"initialize_caches"`
	PollUpdates         PostgresUpdatePolling    `mapstructure:"poll_for_updates"`
}

PostgresConfig configures the Stored Request ecosystem to use Postgres. This must include a Fetcher, and may optionally include some EventProducers to populate and refresh the caches.

type PostgresConnection

type PostgresConnection struct {
	Database string `mapstructure:"dbname"`
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
	Username string `mapstructure:"user"`
	Password string `mapstructure:"password"`
}

PostgresConnection has options which put types to the Postgres Connection string. See: https://godoc.org/github.com/lib/pq#hdr-Connection_String_Parameters

func (*PostgresConnection) ConnString

func (cfg *PostgresConnection) ConnString() string

type PostgresFetcherQueries

type PostgresFetcherQueries struct {
	// QueryTemplate is the Postgres Query which can be used to fetch configs from the database.
	// It is a Template, rather than a full Query, because a single HTTP request may reference multiple Stored Requests.
	//
	// In the simplest case, this could be something like:
	//   SELECT id, requestData, 'request' as type
	//     FROM stored_requests
	//     WHERE id in %REQUEST_ID_LIST%
	//     UNION ALL
	//   SELECT id, impData, 'imp' as type
	//     FROM stored_imps
	//     WHERE id in %IMP_ID_LIST%
	//
	// The MakeQuery function will transform this query into:
	//   SELECT id, requestData, 'request' as type
	//     FROM stored_requests
	//     WHERE id in ($1)
	//     UNION ALL
	//   SELECT id, impData, 'imp' as type
	//     FROM stored_imps
	//     WHERE id in ($2, $3, $4, ...)
	//
	// ... where the number of "$x" args depends on how many IDs are nested within the HTTP request.
	QueryTemplate string `mapstructure:"query"`

	// AmpQueryTemplate is the same as QueryTemplate, but used in the `/openrtb2/amp` endpoint.
	AmpQueryTemplate string `mapstructure:"amp_query"`
}

func (*PostgresFetcherQueries) MakeAmpQuery

func (cfg *PostgresFetcherQueries) MakeAmpQuery(numReqs int, numImps int) string

MakeAmpQuery is the equivalent of MakeQuery() for AMP.

func (*PostgresFetcherQueries) MakeQuery

func (cfg *PostgresFetcherQueries) MakeQuery(numReqs int, numImps int) (query string)

MakeQuery builds a query which can fetch numReqs Stored Requetss and numImps Stored Imps. See the docs on PostgresConfig.QueryTemplate for a description of how it works.

type PostgresUpdatePolling

type PostgresUpdatePolling struct {
	// RefreshRate determines how frequently the Query and AmpQuery are run.
	RefreshRate int `mapstructure:"refresh_rate_seconds"`

	// Timeout is the amount of time before a call to the database is aborted.
	Timeout int `mapstructure:"timeout_ms"`

	// An example UpdateQuery is:
	//
	// SELECT id, requestData, 'request' AS type
	//   FROM stored_requests
	//   WHERE last_updated > $1
	// UNION ALL
	// SELECT id, requestData, 'imp' AS type
	//   FROM stored_imps
	//   WHERE last_updated > $1
	//
	// The code will be run periodically to fetch updates from the database.
	Query string `mapstructure:"query"`

	// AmpQuery is the same as Query, but used for the `/openrtb2/amp` endpoint.
	AmpQuery string `mapstructure:"amp_query"`
}

type PrometheusMetrics

type PrometheusMetrics struct {
	Endpoint  string `mapstructure:"endpoint"`
	Port      int    `mapstructure:"port"`
	Namespace string `mapstructure:"namespace"`
	Subsystem string `mapstructure:"subsystem"`
}

type StoredRequests

type StoredRequests struct {
	// Files should be true if Stored Requests should be loaded from the filesystem.
	Files bool `mapstructure:"filesystem"`
	// Postgres configures Fetchers and EventProducers which read from a Postgres DB.
	// Fetchers are in stored_requests/backends/db_fetcher/postgres.go
	// EventProducers are in stored_requests/events/postgres
	Postgres PostgresConfig `mapstructure:"postgres"`
	// HTTP configures an instance of stored_requests/backends/http/http_fetcher.go.
	// If non-nil, Stored Requests will be fetched from the endpoint described there.
	HTTP HTTPFetcherConfig `mapstructure:"http"`
	// InMemoryCache configures an instance of stored_requests/caches/memory/cache.go.
	// If non-nil, Stored Requests will be saved in an in-memory cache.
	InMemoryCache InMemoryCache `mapstructure:"in_memory_cache"`
	// CacheEventsAPI configures an instance of stored_requests/events/api/api.go.
	// If non-nil, Stored Request Caches can be updated or invalidated through API endpoints.
	// This is intended to be a useful development tool and not recommended for a production environment.
	// It should not be exposed to public networks without authentication.
	CacheEventsAPI bool `mapstructure:"cache_events_api"`
	// HTTPEvents configures an instance of stored_requests/events/http/http.go.
	// If non-nil, the server will use those endpoints to populate and update the cache.
	HTTPEvents HTTPEventsConfig `mapstructure:"http_events"`
}

StoredRequests configures the backend used to store requests on the server.

Jump to

Keyboard shortcuts

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