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.
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.
SourceTimeout is the value of the timeout for source.Client, which is used to fetch source code from third party URLs.
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.
TaskIDChangeIntervalFrontend is the time period during which a given module version can be re-enqueued to frontend tasks.
GetEnv looks up the given key from the environment, returning its value if it exists, and otherwise returning the given fallback value.
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.
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.
ValidateAppVersion validates that appVersion follows the expected format defined by AppVersionFormat.
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 // 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:"-"` DBDriver string // 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.
Init resolves all configuration values provided by the config package. It must be called before any configuration values are used.
AppVersionLabel returns the version label for the current instance. This is the AppVersionID available, otherwise a string constructed using the timestamp of process start.
Application returns the name of the running application: "worker", "frontend", etc.
DBConnInfo returns a PostgreSQL connection string constructed from environment variables, using the primary database host.
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.
DebugAddr returns the network address on which to serve debugging information.
DeploymentEnvironment returns the deployment environment this process is in: usually one of "local", "exp", "dev", "staging" or "prod".
Dump outputs the current config information to the given Writer.
HostAddr returns the network on which to serve the primary HTTP service.
OnAppEngine reports if the current process is running in an AppEngine environment.
OnGCP reports whether the current process is running on Google Cloud Platform.
OnGKE reports whether the current process is running on GKE.
type QuotaSettings struct { Enable bool 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 HMACKey []byte `json:"-"` // key for obfuscating IPs }
QuotaSettings is config for internal/middleware/quota.go
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.
Path | Synopsis |
---|---|
dynconfig | Package dynconfig supports dynamic configuration for pkgsite services. |
Package config imports 21 packages (graph) and is imported by 19 packages. Updated 2021-01-17. Refresh now. Tools for package owners.