pkgsite: golang.org/x/pkgsite/internal/config Index | Files | Directories

package config

import "golang.org/x/pkgsite/internal/config"

Package config resolves shared configuration for Go Discovery services, and provides functions to access this configuration.

The Init function should be called before using any of the configuration accessors.

Index

Package Files

config.go

Constants

const (
    // BypassQuotaAuthHeader is the header key used by the frontend server to know
    // that a request can bypass the quota server.
    BypassQuotaAuthHeader = "X-Go-Discovery-Auth-Bypass-Quota"

    // BypassCacheAuthHeader is the header key used by the frontend server to
    // know that a request can bypass cache.
    BypassCacheAuthHeader = "X-Go-Discovery-Auth-Bypass-Cache"
)
const AppVersionFormat = "20060102t150405"

AppVersionFormat is the expected format of the app version timestamp.

const SourceTimeout = 1 * time.Minute

SourceTimeout is the value of the timeout for source.Client, which is used to fetch source code from third party URLs.

const StatementTimeout = 10 * time.Minute

StatementTimeout is the value of the Postgres statement_timeout parameter. Statements that run longer than this are terminated. 10 minutes is the App Engine standard request timeout.

const TaskIDChangeIntervalFrontend = 30 * time.Minute

TaskIDChangeIntervalFrontend is the time period during which a given module version can be re-enqueued to frontend tasks.

const TaskIDChangeIntervalWorker = 3 * time.Hour

TaskIDChangeIntervalWorker is the time period during which a given module version can be re-enqueued to fetch tasks.

func GetEnv Uses

func GetEnv(key, fallback string) string

GetEnv looks up the given key from the environment, returning its value if it exists, and otherwise returning the given fallback value.

func GetEnvFloat64 Uses

func GetEnvFloat64(key string, fallback float64) float64

GetEnvFloat64 looks up the given key from the environment and expects a float64, returning the float64 value if it exists, and otherwise returning the given fallback value.

func GetEnvInt Uses

func GetEnvInt(key string, fallback int) int

GetEnvInt looks up the given key from the environment and expects an integer, returning the integer value if it exists, and otherwise returning the given fallback value. If the environment variable has a value but it can't be parsed as an integer, GetEnvInt terminates the program.

func ValidateAppVersion Uses

func ValidateAppVersion(appVersion string) error

ValidateAppVersion validates that appVersion follows the expected format defined by AppVersionFormat.

type Config Uses

type Config struct {
    // AuthValues is the set of values that could be set on the AuthHeader, in
    // order to bypass checks by the cache.
    AuthValues []string

    // Discovery environment variables
    ProxyURL, IndexURL string

    // Ports used for hosting. 'DebugPort' is used for serving HTTP debug pages.
    Port, DebugPort string

    // AppEngine identifiers
    ProjectID, ServiceID, VersionID, ZoneID, InstanceID, LocationID string

    // ServiceAccount is the email of the service account that this process
    // is running as when on GCP.
    ServiceAccount string

    // QueueService is the AppEngine service that the Cloud Tasks queue should
    // send requests to.
    QueueService string

    // QueueURL is the URL that the Cloud Tasks queue should send requests to.
    // It should be used when the worker is not on AppEngine.
    QueueURL string

    // QueueAudience is used to allow the Cloud Tasks queue to authorize itself
    // to the worker. It should be the OAuth 2.0 client ID associated with the
    // IAP that is gating access to the worker.
    QueueAudience string

    // GoogleTagManagerID is the ID used for GoogleTagManager. It has the
    // structure GTM-XXXX.
    GoogleTagManagerID string

    // MonitoredResource represents the resource that is running the current binary.
    // It might be a Google AppEngine app or a Kubernetes pod.
    // See https://cloud.google.com/monitoring/api/resources for more
    // details:
    // "An object representing a resource that can be used for monitoring, logging,
    // billing, or other purposes. Examples include virtual machine instances,
    // databases, and storage devices such as disks.""
    MonitoredResource *mrpb.MonitoredResource

    // FallbackVersionLabel is used as the VersionLabel when not hosting on
    // AppEngine.
    FallbackVersionLabel string

    DBSecret, DBUser, DBHost, DBPort, DBName string
    DBSecondaryHost                          string // DB host to use if first one is down
    DBPassword                               string `json:"-"`

    // Configuration for redis page cache.
    RedisCacheHost, RedisCachePort string

    // Configuration for redis autocompletion. This is different from the page
    // cache instance as it has different availability requirements.
    RedisHAHost, RedisHAPort string

    // UseProfiler specifies whether to enable Stackdriver Profiler.
    UseProfiler bool

    Quota QuotaSettings

    // Teeproxy sepcifies the configuration values for the teeproxy.
    Teeproxy TeeproxySettings

    // Minimum log level below which no logs will be printed.
    // Possible values are [debug, info, error, fatal].
    // In case of invalid/empty value, all logs will be printed.
    LogLevel string

    // DynamicConfigLocation is the location (either a file or gs://bucket/object) for
    // dynamic configuration.
    DynamicConfigLocation string

    // ServeStats determines whether the server has an endpoint that serves statistics for
    // benchmarking or other purposes.
    ServeStats bool

    // DisableErrorReporting disables sending errors to the GCP ErrorReporting system.
    DisableErrorReporting bool
}

Config holds shared configuration values used in instantiating our server components.

func Init Uses

func Init(ctx context.Context) (_ *Config, err error)

Init resolves all configuration values provided by the config package. It must be called before any configuration values are used.

func (*Config) AppVersionLabel Uses

func (c *Config) AppVersionLabel() string

AppVersionLabel returns the version label for the current instance. This is the AppVersionID available, otherwise a string constructed using the timestamp of process start.

func (*Config) Application Uses

func (c *Config) Application() string

Application returns the name of the running application: "worker", "frontend", etc.

func (*Config) DBConnInfo Uses

func (c *Config) DBConnInfo() string

DBConnInfo returns a PostgreSQL connection string constructed from environment variables, using the primary database host.

func (*Config) DBSecondaryConnInfo Uses

func (c *Config) DBSecondaryConnInfo() string

DBSecondaryConnInfo returns a PostgreSQL connection string constructed from environment variables, using the backup database host. It returns the empty string if no backup is configured.

func (*Config) DebugAddr Uses

func (c *Config) DebugAddr(dflt string) string

DebugAddr returns the network address on which to serve debugging information.

func (*Config) DeploymentEnvironment Uses

func (c *Config) DeploymentEnvironment() string

DeploymentEnvironment returns the deployment environment this process is in: usually one of "local", "exp", "dev", "staging" or "prod".

func (*Config) Dump Uses

func (c *Config) Dump(w io.Writer) error

Dump outputs the current config information to the given Writer.

func (*Config) HostAddr Uses

func (c *Config) HostAddr(dflt string) string

HostAddr returns the network on which to serve the primary HTTP service.

func (*Config) OnAppEngine Uses

func (c *Config) OnAppEngine() bool

OnAppEngine reports if the current process is running in an AppEngine environment.

func (*Config) OnGCP Uses

func (c *Config) OnGCP() bool

OnGCP reports whether the current process is running on Google Cloud Platform.

func (*Config) OnGKE Uses

func (c *Config) OnGKE() bool

OnGKE reports whether the current process is running on GKE.

type QuotaSettings Uses

type QuotaSettings struct {
    QPS        int // allowed queries per second, per IP block
    Burst      int // maximum requests per second, per block; the size of the token bucket
    MaxEntries int // maximum number of entries to keep track of
    // Record data about blocking, but do not actually block.
    // This is a *bool, so we can distinguish "not present" from "false" in an override
    RecordOnly *bool
    // AuthValues is the set of values that could be set on the AuthHeader, in
    // order to bypass checks by the quota server.
    AuthValues []string
}

QuotaSettings is config for internal/middleware/quota.go

type TeeproxySettings Uses

type TeeproxySettings struct {
    AuthKey          string
    AuthValue        string
    Hosts            []string
    Rate             float64
    Burst            int
    FailsToRed       int
    FailureThreshold float64
    GreenInterval    time.Duration
    MinTimeout       time.Duration
    MaxTimeout       time.Duration
    SuccsToGreen     int
}

TeeproxySettings contains the configuration values for the teeproxy. See internal/teeproxy.Config to see what these values mean.

Directories

PathSynopsis
dynconfigPackage dynconfig supports dynamic configuration for pkgsite services.

Package config imports 20 packages (graph) and is imported by 18 packages. Updated 2020-10-28. Refresh now. Tools for package owners.