forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[datadogexporter] Use resource attributes for metadata and generated …
…metrics (#2023) * Set hostname to running metrics from resource attributes if available Running metrics can be duplicate in this setup but this is fine since they are gauges. * Use resource metadata to complet host metadata If enabled (it is by default) the resource attributes from the first payload from either metrics or traces will be used to populate host metadata. If there are fields missing these will be filled in by the exporter (this preserves behavior when not using k8s_tagger/resourcedetection). * Add tests for new metadata behavior * Fix go lint * Remove unnecessary log messages * Improve GCP info from attributes Most logic is taken from here: https://github.com/DataDog/datadog-agent/blob/491c309e374ed5c7f1b385b347d5f9b5ac72c2b6/pkg/util/gce/gce_tags.go#L71-L101 * Use "system" host tags for EC2 tags This is what the Datadog Agent does https://github.com/DataDog/datadog-agent/blob/491c309e374ed5c7f1b385b347d5f9b5ac72c2b6/pkg/metadata/host/host_tags.go#L97-L139 * Add additional test for GCP hostname from attributes * Add test for metadata.Pusher function * Improve test coverage * Set EC2 tags in OTel field instead of System field This avoids clashes with the Datadog Agent
- Loading branch information
1 parent
66d59db
commit 004e72c
Showing
20 changed files
with
674 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package gcp | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/consumer/pdata" | ||
"go.opentelemetry.io/collector/translator/conventions" | ||
) | ||
|
||
type HostInfo struct { | ||
HostAliases []string | ||
GCPTags []string | ||
} | ||
|
||
// HostnameFromAttributes gets a valid hostname from labels | ||
// if available | ||
func HostnameFromAttributes(attrs pdata.AttributeMap) (string, bool) { | ||
if hostName, ok := attrs.Get(conventions.AttributeHostName); ok { | ||
return hostName.StringVal(), true | ||
} | ||
|
||
return "", false | ||
} | ||
|
||
// HostInfoFromAttributes gets GCP host info from attributes following | ||
// OpenTelemetry semantic conventions | ||
func HostInfoFromAttributes(attrs pdata.AttributeMap) (hostInfo *HostInfo) { | ||
hostInfo = &HostInfo{} | ||
|
||
if hostID, ok := attrs.Get(conventions.AttributeHostID); ok { | ||
// Add host id as a host alias to preserve backwards compatibility | ||
// The Datadog Agent does not do this | ||
hostInfo.HostAliases = append(hostInfo.HostAliases, hostID.StringVal()) | ||
hostInfo.GCPTags = append(hostInfo.GCPTags, fmt.Sprintf("instance-id:%s", hostID.StringVal())) | ||
} | ||
|
||
if cloudZone, ok := attrs.Get(conventions.AttributeCloudZone); ok { | ||
hostInfo.GCPTags = append(hostInfo.GCPTags, fmt.Sprintf("zone:%s", cloudZone.StringVal())) | ||
} | ||
|
||
if hostType, ok := attrs.Get(conventions.AttributeHostType); ok { | ||
hostInfo.GCPTags = append(hostInfo.GCPTags, fmt.Sprintf("instance-type:%s", hostType.StringVal())) | ||
} | ||
|
||
if cloudAccount, ok := attrs.Get(conventions.AttributeCloudAccount); ok { | ||
hostInfo.GCPTags = append(hostInfo.GCPTags, fmt.Sprintf("project:%s", cloudAccount.StringVal())) | ||
} | ||
|
||
return | ||
} |
Oops, something went wrong.