Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/datadog] Fix hostname reported on GKE #11894

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,28 @@ type Provider struct {
detector gcpDetector
}

func platformDescription(platform gcp.Platform) string {
switch platform {
case gcp.UnknownPlatform:
return "Unknown platform"
case gcp.GKE:
return "Google Kubernetes Engine"
case gcp.GCE:
return "Google Cloud Engine"
case gcp.CloudRun:
return "Google Cloud Run"
case gcp.CloudFunctions:
return "Google Cloud Functions"
case gcp.AppEngineStandard, gcp.AppEngineFlex:
return "Google AppEngine"
}
return "Unrecognized platform"
}

// Hostname returns the GCP cloud integration hostname.
func (p *Provider) Source(context.Context) (source.Source, error) {
if p.detector.CloudPlatform() != gcp.GCE {
return source.Source{}, fmt.Errorf("not on Google Cloud Engine")
if platform := p.detector.CloudPlatform(); platform != gcp.GCE && platform != gcp.GKE {
return source.Source{}, fmt.Errorf("not on GCE or GKE (platform: %s)", platformDescription(platform))
}

name, err := p.detector.GCEHostName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ var (
var _ gcpDetector = (*mockDetector)(nil)

type mockDetector struct {
platform gcp.Platform
projectID string
instanceName string
}

func (m *mockDetector) CloudPlatform() gcp.Platform {
return gcp.GCE
return m.platform
}

func (m *mockDetector) ProjectID() (string, error) {
Expand All @@ -65,17 +66,20 @@ func TestProvider(t *testing.T) {
tests := []struct {
name string
projectID string
platform gcp.Platform
instanceName string
hostname string
}{
{
name: "good hostname",
platform: gcp.GCE,
projectID: testCloudAccount,
instanceName: testHostname,
hostname: testGCPIntegrationHostname,
},
{
name: "bad hostname",
platform: gcp.GKE,
projectID: testCloudAccount,
instanceName: testBadHostname,
hostname: testGCPIntegrationBadHostname,
Expand All @@ -85,6 +89,7 @@ func TestProvider(t *testing.T) {
for _, testInstance := range tests {
t.Run(testInstance.name, func(t *testing.T) {
provider := &Provider{detector: &mockDetector{
platform: testInstance.platform,
projectID: testInstance.projectID,
instanceName: testInstance.instanceName,
}}
Expand Down
11 changes: 11 additions & 0 deletions unreleased/datadog-exporter-gke-hostname.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogexporter

# A brief description of the change
note: (Under `exporter.datadog.hostname.preview` feature gate) Make the hostname reported on GKE match the Datadog GCP integration hostname.

# One or more tracking issues related to the change
issues: [11893]