|
@@ -12,6 +12,7 @@ import (
|
|
"cloud.google.com/go/logging"
|
|
"cloud.google.com/go/logging"
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/Sirupsen/logrus"
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/context"
|
|
|
|
+ mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -128,7 +129,35 @@ func New(info logger.Info) (logger.Logger, error) {
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
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 {
|
|
if err := c.Ping(context.Background()); err != nil {
|
|
return nil, fmt.Errorf("unable to connect or authenticate with Google Cloud Logging: %v", err)
|
|
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()
|
|
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
|
|
// The logger "overflows" at a rate of 10,000 logs per second and this
|