From 408fff4fc10aa956902fc4918cb94a3f7c44f8ab Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Wed, 18 Jan 2023 16:24:59 -0500 Subject: [PATCH] Use a fake instance id in metric (#1912) Currently we synthesize a instance id which requires the use of App Engine Module API. Given that we only have one version of code running at one time, and HTTP is stateless, there is no point tracking exactly which GAE "instance" is. We do lose information on which service (default, backend, etc) is writing the metric, but that does not seem very important. Using a constant fake instance ID allows us to get rid of another GAE dependency. --- .../monitoring/whitebox/StackdriverModule.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/google/registry/monitoring/whitebox/StackdriverModule.java b/core/src/main/java/google/registry/monitoring/whitebox/StackdriverModule.java index 5298dc984..d5423395f 100644 --- a/core/src/main/java/google/registry/monitoring/whitebox/StackdriverModule.java +++ b/core/src/main/java/google/registry/monitoring/whitebox/StackdriverModule.java @@ -16,7 +16,6 @@ package google.registry.monitoring.whitebox; import com.google.api.services.monitoring.v3.Monitoring; import com.google.api.services.monitoring.v3.model.MonitoredResource; -import com.google.appengine.api.modules.ModulesService; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.monitoring.metrics.MetricReporter; @@ -34,8 +33,9 @@ import org.joda.time.Duration; public final class StackdriverModule { // We need a fake GCE zone to appease Stackdriver's resource model. - // TODO(b/31021585): Revisit this if/when gae_instance exists. + // TODO(b/265973059): Switch to resource type "gke_container". private static final String SPOOFED_GCE_ZONE = "us-central1-f"; + private static final String SPOOFED_GCE_INSTANCE = "fake-instance"; @Provides static Monitoring provideMonitoring( @@ -53,7 +53,6 @@ public final class StackdriverModule { static MetricWriter provideMetricWriter( Monitoring monitoringClient, @Config("projectId") String projectId, - ModulesService modulesService, @Config("stackdriverMaxQps") int maxQps, @Config("stackdriverMaxPointsPerRequest") int maxPointsPerRequest) { // The MonitoredResource for GAE apps is not writable (and missing fields anyway) so we just @@ -66,16 +65,7 @@ public final class StackdriverModule { .setLabels( ImmutableMap.of( // The "zone" field MUST be a valid GCE zone, so we fake one. - "zone", - SPOOFED_GCE_ZONE, - // Overload the GCE "instance_id" field with the GAE module name, version and - // instance_id. - "instance_id", - modulesService.getCurrentModule() - + ":" - + modulesService.getCurrentVersion() - + ":" - + modulesService.getCurrentInstanceId())), + "zone", SPOOFED_GCE_ZONE, "instance_id", SPOOFED_GCE_INSTANCE)), maxQps, maxPointsPerRequest); }