Skip to content

Commit

Permalink
handle non-gce platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed May 20, 2022
1 parent e463be0 commit dfda8af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions detectors/gcp/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewDetector() *Detector {
type Platform int64

const (
Undefined Platform = iota
UnknownPlatform Platform = iota
GKE
GCE
CloudRun
Expand All @@ -51,9 +51,10 @@ func (d *Detector) CloudPlatform() Platform {
return CloudFunctions
case d.onAppEngine():
return AppEngine
default:
case d.onGCE():
return GCE
}
return UnknownPlatform
}

// ProjectID returns the ID of the project in which this program is running
Expand Down
5 changes: 5 additions & 0 deletions detectors/gcp/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import (
// https://cloud.google.com/compute/docs/metadata/default-metadata-values#vm_instance_metadata
const machineTypeMetadataAttr = "instance/machine-type"

func (d *Detector) onGCE() bool {
_, err := d.metadata.Get(machineTypeMetadataAttr)
return err == nil
}

// GCEHostType returns the machine type of the instance on which this program is running
func (d *Detector) GCEHostType() (string, error) {
return d.metadata.Get(machineTypeMetadataAttr)
Expand Down
4 changes: 3 additions & 1 deletion e2e-test-server/endtoendserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (d *testDetector) Detect(ctx context.Context) (*resource.Resource, error) {
semconv.FaaSVersionKey: detector.AppEngineServiceVersion,
semconv.FaaSIDKey: detector.AppEngineServiceInstance,
})
default:
case gcp.GCE:
attributes = append(attributes, semconv.CloudPlatformGCPComputeEngine)
zone, region, err := detector.GCEAvailabilityZoneAndRegion()
if err != nil {
Expand All @@ -226,6 +226,8 @@ func (d *testDetector) Detect(ctx context.Context) (*resource.Resource, error) {
semconv.HostIDKey: detector.GCEHostID,
semconv.HostNameKey: detector.GCEHostName,
})
default:
return resource.NewWithAttributes(semconv.SchemaURL, attributes...), nil
}
}

Expand Down

0 comments on commit dfda8af

Please sign in to comment.