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
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
static Monitoring provideMonitoring(
HttpTransport transport,
@ -56,19 +60,24 @@ public final class StackdriverModule {
ModulesService modulesService,
@Config("stackdriverMaxQps") int maxQps,
@Config("stackdriverMaxPointsPerRequest") int maxPointsPerRequest) {
// The MonitoredResource for GAE apps lacks an instance_id field, so we encode it into the
// version_id field so that metrics from different instances don't interleave.
// The MonitoredResource for GAE apps is not writable (and missing fields anyway) so we just
// use the gce_instance resource type instead.
return new StackdriverWriter(
monitoringClient,
projectId,
new MonitoredResource()
.setType("gae_app")
.setType("gce_instance")
.setLabels(
ImmutableMap.of(
"module_id",
modulesService.getCurrentModule(),
"version_id",
modulesService.getCurrentVersion()
// 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())),
maxQps,