internal/config: add OnGCP
Add a method that reports whether the binary is on GCP.  We use the
GAE_ENV env var to detect AppEngine, and an env var we'll set in the
k8s deployment manifest to detect GKE.
@@ -107,8 +107,6 @@ type Config struct {
// should send requests to.
QueueService string
- gaeEnv string // the AppEngine environment: "standard", "flex", or "" if not on AppEngine
-
// GoogleTagManagerID is the ID used for GoogleTagManager. It has the
// structure GTM-XXXX.
GoogleTagManagerID string
@@ -163,7 +161,13 @@ func (c *Config) AppVersionLabel() string {
// OnAppEngine reports if the current process is running in an AppEngine
// environment.
func (c *Config) OnAppEngine() bool {
- return c.gaeEnv == "standard"
+ return os.Getenv("GAE_ENV") == "standard"
+}
+
+// OnGCP reports whether the current process is running on Google Cloud
+// Platform.
+func (c *Config) OnGCP() bool {
+ return c.OnAppEngine() || os.Getenv("GO_DISCOVERY_ON_GKE") == "true"
}
// StatementTimeout is the value of the Postgres statement_timeout parameter.
@@ -283,7 +287,6 @@ func Init(ctx context.Context) (_ *Config, err error) {
ServiceID: GetEnv("GAE_SERVICE", os.Getenv("GO_DISCOVERY_SERVICE")),
VersionID: GetEnv("GAE_VERSION", os.Getenv("GO_DISCOVERY_VERSION")),
InstanceID: GetEnv("GAE_INSTANCE", os.Getenv("GO_DISCOVERY_INSTANCE")),
- gaeEnv: os.Getenv("GAE_ENV"),
GoogleTagManagerID: os.Getenv("GO_DISCOVERY_GOOGLE_TAG_MANAGER_ID"),
QueueService: GetEnv("GO_DISCOVERY_QUEUE_SERVICE", os.Getenv("GAE_SERVICE")),
// LocationID is essentially hard-coded until we figure out a good way to
@@ -336,7 +339,7 @@ func Init(ctx context.Context) (_ *Config, err error) {
},
}
- if cfg.gaeEnv != "" {
+ if cfg.OnAppEngine() {
// Zone is not available in the environment but can be queried via the metadata API.
zone, err := gceMetadata(ctx, "instance/zone")
if err != nil {
