Change resource type for Stackdriver to fix metrics push

Currently, it's forbidden for custom metrics to write to the gae_app resource
type.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131076789
This commit is contained in:
shikhman 2016-08-23 11:18:28 -07:00 committed by Ben McIlwain
parent 5dc1f716bd
commit e6beba2d39

View file

@ -38,6 +38,10 @@ import org.joda.time.Duration;
@Module @Module
public final class StackdriverModule { 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.
private static String SPOOFED_GCE_ZONE = "us-central1-f";
@Provides @Provides
static Monitoring provideMonitoring( static Monitoring provideMonitoring(
HttpTransport transport, HttpTransport transport,
@ -56,19 +60,24 @@ public final class StackdriverModule {
ModulesService modulesService, ModulesService modulesService,
@Config("stackdriverMaxQps") int maxQps, @Config("stackdriverMaxQps") int maxQps,
@Config("stackdriverMaxPointsPerRequest") int maxPointsPerRequest) { @Config("stackdriverMaxPointsPerRequest") int maxPointsPerRequest) {
// The MonitoredResource for GAE apps lacks an instance_id field, so we encode it into the // The MonitoredResource for GAE apps is not writable (and missing fields anyway) so we just
// version_id field so that metrics from different instances don't interleave. // use the gce_instance resource type instead.
return new StackdriverWriter( return new StackdriverWriter(
monitoringClient, monitoringClient,
projectId, projectId,
new MonitoredResource() new MonitoredResource()
.setType("gae_app") .setType("gce_instance")
.setLabels( .setLabels(
ImmutableMap.of( ImmutableMap.of(
"module_id", // The "zone" field MUST be a valid GCE zone, so we fake one.
modulesService.getCurrentModule(), "zone",
"version_id", SPOOFED_GCE_ZONE,
modulesService.getCurrentVersion() // Overload the GCE "instance_id" field with the GAE module name, version and
// instance_id.
"instance_id",
modulesService.getCurrentModule()
+ ":"
+ modulesService.getCurrentVersion()
+ ":" + ":"
+ modulesService.getCurrentInstanceId())), + modulesService.getCurrentInstanceId())),
maxQps, maxQps,