diff --git a/daemon/logger/gcplogs/gcplogging.go b/daemon/logger/gcplogs/gcplogging.go index 7d6475bf4f..3a48067f9d 100644 --- a/daemon/logger/gcplogs/gcplogging.go +++ b/daemon/logger/gcplogs/gcplogging.go @@ -12,6 +12,7 @@ import ( "cloud.google.com/go/logging" "github.com/Sirupsen/logrus" "golang.org/x/net/context" + mrpb "google.golang.org/genproto/googleapis/api/monitoredres" ) const ( @@ -128,7 +129,35 @@ func New(info logger.Info) (logger.Logger, error) { if err != nil { return nil, err } - lg := c.Logger("gcplogs-docker-driver") + var instanceResource *instanceInfo + if onGCE { + instanceResource = &instanceInfo{ + Zone: zone, + Name: instanceName, + ID: instanceID, + } + } else if info.Config[logZoneKey] != "" || info.Config[logNameKey] != "" || info.Config[logIDKey] != "" { + instanceResource = &instanceInfo{ + Zone: info.Config[logZoneKey], + Name: info.Config[logNameKey], + ID: info.Config[logIDKey], + } + } + + options := []logging.LoggerOption{} + if instanceResource != nil { + vmMrpb := logging.CommonResource( + &mrpb.MonitoredResource{ + Type: "gce_instance", + Labels: map[string]string{ + "instance_id": instanceResource.ID, + "zone": instanceResource.Zone, + }, + }, + ) + options = []logging.LoggerOption{vmMrpb} + } + lg := c.Logger("gcplogs-docker-driver", options...) if err := c.Ping(context.Background()); err != nil { return nil, fmt.Errorf("unable to connect or authenticate with Google Cloud Logging: %v", err) @@ -155,18 +184,8 @@ func New(info logger.Info) (logger.Logger, error) { l.container.Command = info.Command() } - if onGCE { - l.instance = &instanceInfo{ - Zone: zone, - Name: instanceName, - ID: instanceID, - } - } else if info.Config[logZoneKey] != "" || info.Config[logNameKey] != "" || info.Config[logIDKey] != "" { - l.instance = &instanceInfo{ - Zone: info.Config[logZoneKey], - Name: info.Config[logNameKey], - ID: info.Config[logIDKey], - } + if instanceResource != nil { + l.instance = instanceResource } // The logger "overflows" at a rate of 10,000 logs per second and this