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

Updates for cloud semantic conventions #2809

Merged
merged 2 commits into from
Mar 25, 2021
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
4 changes: 2 additions & 2 deletions internal/goldendataset/resource_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func generateCloudK8sAttributes() map[string]interface{} {
attrMap[conventions.AttributeCloudProvider] = "aws"
attrMap[conventions.AttributeCloudAccount] = "12345678901"
attrMap[conventions.AttributeCloudRegion] = "us-east-1"
attrMap[conventions.AttributeCloudZone] = "us-east-1c"
attrMap[conventions.AttributeCloudAvailabilityZone] = "us-east-1c"
return attrMap
}

Expand All @@ -146,7 +146,7 @@ func generateFassAttributes() map[string]interface{} {
attrMap[conventions.AttributeCloudProvider] = "gcp"
attrMap[conventions.AttributeCloudAccount] = "opentelemetry"
attrMap[conventions.AttributeCloudRegion] = "us-central1"
attrMap[conventions.AttributeCloudZone] = "us-central1-a"
attrMap[conventions.AttributeCloudAvailabilityZone] = "us-central1-a"
return attrMap
}

Expand Down
2 changes: 1 addition & 1 deletion processor/resourceprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Examples:
processors:
resource:
attributes:
- key: cloud.zone
- key: cloud.availability_zone
value: "zone-1"
action: upsert
- key: k8s.cluster.name
Expand Down
2 changes: 1 addition & 1 deletion processor/resourceprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestLoadConfig(t *testing.T) {
NameVal: "resource",
},
AttributesActions: []processorhelper.ActionKeyValue{
{Key: "cloud.zone", Value: "zone-1", Action: processorhelper.UPSERT},
{Key: "cloud.availability_zone", Value: "zone-1", Action: processorhelper.UPSERT},
{Key: "k8s.cluster.name", FromAttribute: "k8s-cluster", Action: processorhelper.INSERT},
{Key: "redundant-attribute", Action: processorhelper.DELETE},
},
Expand Down
2 changes: 1 addition & 1 deletion processor/resourceprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestCreateProcessor(t *testing.T) {
NameVal: "resource",
},
AttributesActions: []processorhelper.ActionKeyValue{
{Key: "cloud.zone", Value: "zone-1", Action: processorhelper.UPSERT},
{Key: "cloud.availability_zone", Value: "zone-1", Action: processorhelper.UPSERT},
},
}

Expand Down
18 changes: 9 additions & 9 deletions processor/resourceprocessor/resource_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
cfg = &Config{
ProcessorSettings: processorSettings,
AttributesActions: []processorhelper.ActionKeyValue{
{Key: "cloud.zone", Value: "zone-1", Action: processorhelper.UPSERT},
{Key: "cloud.availability_zone", Value: "zone-1", Action: processorhelper.UPSERT},
{Key: "k8s.cluster.name", FromAttribute: "k8s-cluster", Action: processorhelper.INSERT},
{Key: "redundant-attribute", Action: processorhelper.DELETE},
},
Expand All @@ -56,29 +56,29 @@ func TestResourceProcessorAttributesUpsert(t *testing.T) {
config: cfg,
sourceAttributes: nil,
wantAttributes: map[string]string{
"cloud.zone": "zone-1",
"cloud.availability_zone": "zone-1",
},
},
{
name: "config_with_attributes_applied_on_empty_resource",
config: cfg,
sourceAttributes: map[string]string{},
wantAttributes: map[string]string{
"cloud.zone": "zone-1",
"cloud.availability_zone": "zone-1",
},
},
{
name: "config_attributes_applied_on_existing_resource_attributes",
config: cfg,
sourceAttributes: map[string]string{
"cloud.zone": "to-be-replaced",
"k8s-cluster": "test-cluster",
"redundant-attribute": "to-be-removed",
"cloud.availability_zone": "to-be-replaced",
"k8s-cluster": "test-cluster",
"redundant-attribute": "to-be-removed",
},
wantAttributes: map[string]string{
"cloud.zone": "zone-1",
"k8s-cluster": "test-cluster",
"k8s.cluster.name": "test-cluster",
"cloud.availability_zone": "zone-1",
"k8s-cluster": "test-cluster",
"k8s.cluster.name": "test-cluster",
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions processor/resourceprocessor/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ receivers:

processors:
# The following specifies a resource configuration doing the changes on resource attributes:
# 1. Set "cloud.zone" attributes with "zone-1" value ignoring existing values.
# 1. Set "cloud.availability_zone" attributes with "zone-1" value ignoring existing values.
# 2. Copy "k8s-cluster" attribute value to "k8s.cluster.name" attribute, nothing happens if "k8s-cluster" not found.
# 3. Remove "redundant-attribute" attribute.
# There are many more attribute modification actions supported,
# There are many more attribute modification actions supported,
# check processor/attributesprocessor/testdata/config.yaml for reference.
resource:
attributes:
- key: cloud.zone
- key: cloud.availability_zone
value: zone-1
action: upsert
- key: k8s.cluster.name
Expand Down
146 changes: 73 additions & 73 deletions translator/conventions/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,61 @@ package conventions
// OpenTelemetry Semantic Convention values for Resource attribute names.
// See: https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions/README.md
const (
AttributeCloudAccount = "cloud.account.id"
AttributeCloudProvider = "cloud.provider"
AttributeCloudRegion = "cloud.region"
AttributeCloudZone = "cloud.zone"
AttributeCloudInfrastructureService = "cloud.infrastructure_service"
AttributeContainerID = "container.id"
AttributeContainerImage = "container.image.name"
AttributeContainerName = "container.name"
AttributeContainerTag = "container.image.tag"
AttributeDeploymentEnvironment = "deployment.environment"
AttributeFaasID = "faas.id"
AttributeFaasInstance = "faas.instance"
AttributeFaasName = "faas.name"
AttributeFaasVersion = "faas.version"
AttributeHostID = "host.id"
AttributeHostImageID = "host.image.id"
AttributeHostImageName = "host.image.name"
AttributeHostImageVersion = "host.image.version"
AttributeHostName = "host.name"
AttributeHostType = "host.type"
AttributeK8sCluster = "k8s.cluster.name"
AttributeK8sContainer = "k8s.container.name"
AttributeK8sCronJob = "k8s.cronjob.name"
AttributeK8sCronJobUID = "k8s.cronjob.uid"
AttributeK8sDaemonSet = "k8s.daemonset.name"
AttributeK8sDaemonSetUID = "k8s.daemonset.uid"
AttributeK8sDeployment = "k8s.deployment.name"
AttributeK8sDeploymentUID = "k8s.deployment.uid"
AttributeK8sJob = "k8s.job.name"
AttributeK8sJobUID = "k8s.job.uid"
AttributeK8sNamespace = "k8s.namespace.name"
AttributeK8sNodeName = "k8s.node.name"
AttributeK8sNodeUID = "k8s.node.uid"
AttributeK8sPod = "k8s.pod.name"
AttributeK8sPodUID = "k8s.pod.uid"
AttributeK8sReplicaSet = "k8s.replicaset.name"
AttributeK8sReplicaSetUID = "k8s.replicaset.uid"
AttributeK8sStatefulSet = "k8s.statefulset.name"
AttributeK8sStatefulSetUID = "k8s.statefulset.uid"
AttributeOSType = "os.type"
AttributeOSDescription = "os.description"
AttributeProcessCommand = "process.command"
AttributeProcessCommandLine = "process.command_line"
AttributeProcessExecutableName = "process.executable.name"
AttributeProcessExecutablePath = "process.executable.path"
AttributeProcessID = "process.pid"
AttributeProcessOwner = "process.owner"
AttributeServiceInstance = "service.instance.id"
AttributeServiceName = "service.name"
AttributeServiceNamespace = "service.namespace"
AttributeServiceVersion = "service.version"
AttributeTelemetryAutoVersion = "telemetry.auto.version"
AttributeTelemetrySDKLanguage = "telemetry.sdk.language"
AttributeTelemetrySDKName = "telemetry.sdk.name"
AttributeTelemetrySDKVersion = "telemetry.sdk.version"
AttributeCloudAccount = "cloud.account.id"
AttributeCloudAvailabilityZone = "cloud.availability_zone"
AttributeCloudPlatform = "cloud.platform"
AttributeCloudProvider = "cloud.provider"
AttributeCloudRegion = "cloud.region"
AttributeContainerID = "container.id"
AttributeContainerImage = "container.image.name"
AttributeContainerName = "container.name"
AttributeContainerTag = "container.image.tag"
AttributeDeploymentEnvironment = "deployment.environment"
AttributeFaasID = "faas.id"
AttributeFaasInstance = "faas.instance"
AttributeFaasName = "faas.name"
AttributeFaasVersion = "faas.version"
AttributeHostID = "host.id"
AttributeHostImageID = "host.image.id"
AttributeHostImageName = "host.image.name"
AttributeHostImageVersion = "host.image.version"
AttributeHostName = "host.name"
AttributeHostType = "host.type"
AttributeK8sCluster = "k8s.cluster.name"
AttributeK8sContainer = "k8s.container.name"
AttributeK8sCronJob = "k8s.cronjob.name"
AttributeK8sCronJobUID = "k8s.cronjob.uid"
AttributeK8sDaemonSet = "k8s.daemonset.name"
AttributeK8sDaemonSetUID = "k8s.daemonset.uid"
AttributeK8sDeployment = "k8s.deployment.name"
AttributeK8sDeploymentUID = "k8s.deployment.uid"
AttributeK8sJob = "k8s.job.name"
AttributeK8sJobUID = "k8s.job.uid"
AttributeK8sNamespace = "k8s.namespace.name"
AttributeK8sNodeName = "k8s.node.name"
AttributeK8sNodeUID = "k8s.node.uid"
AttributeK8sPod = "k8s.pod.name"
AttributeK8sPodUID = "k8s.pod.uid"
AttributeK8sReplicaSet = "k8s.replicaset.name"
AttributeK8sReplicaSetUID = "k8s.replicaset.uid"
AttributeK8sStatefulSet = "k8s.statefulset.name"
AttributeK8sStatefulSetUID = "k8s.statefulset.uid"
AttributeOSDescription = "os.description"
AttributeOSType = "os.type"
AttributeProcessCommand = "process.command"
AttributeProcessCommandLine = "process.command_line"
AttributeProcessExecutableName = "process.executable.name"
AttributeProcessExecutablePath = "process.executable.path"
AttributeProcessID = "process.pid"
AttributeProcessOwner = "process.owner"
AttributeServiceInstance = "service.instance.id"
AttributeServiceName = "service.name"
AttributeServiceNamespace = "service.namespace"
AttributeServiceVersion = "service.version"
AttributeTelemetryAutoVersion = "telemetry.auto.version"
AttributeTelemetrySDKLanguage = "telemetry.sdk.language"
AttributeTelemetrySDKName = "telemetry.sdk.name"
AttributeTelemetrySDKVersion = "telemetry.sdk.version"
)

// OpenTelemetry Semantic Convention values for Resource attribute "telemetry.sdk.language" values.
Expand All @@ -97,24 +97,24 @@ const (
AttributeCloudProviderGCP = "gcp"
)

// OpenTelemetry Semantic Convention values for Resource attribute "cloud.infrastructure_service" values.
// OpenTelemetry Semantic Convention values for Resource attribute "cloud.platform" values.
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/cloud.md
const (
AttributeCloudProviderAWSEC2 = "aws_ec2"
AttributeCloudProviderAWSECS = "aws_ecs"
AttributeCloudProviderAWSEKS = "aws_eks"
AttributeCloudProviderAWSLambda = "aws_lambda"
AttributeCloudProviderAWSElasticBeanstalk = "aws_elastic_beanstalk"
AttributeCloudProviderAzureVM = "azure_vm"
AttributeCloudProviderAzureContainerInstances = "azure_container_instances"
AttributeCloudProviderAzureAKS = "azure_aks"
AttributeCloudProviderAzureFunctions = "azure_functions"
AttributeCloudProviderAzureAppService = "azure_app_service"
AttributeCloudProviderGCPComputeEngine = "gcp_compute_engine"
AttributeCloudProviderGCPCloudRun = "gcp_cloud_run"
AttributeCloudProviderGCPGKE = "gcp_gke"
AttributeCloudProviderGCPCloudFunctions = "gcp_cloud_functions"
AttributeCloudProviderGCPAppEngine = "gcp_app_engine"
AttributeCloudPlatformAWSEC2 = "aws_ec2"
AttributeCloudPlatformAWSECS = "aws_ecs"
AttributeCloudPlatformAWSEKS = "aws_eks"
AttributeCloudPlatformAWSLambda = "aws_lambda"
AttributeCloudPlatformAWSElasticBeanstalk = "aws_elastic_beanstalk"
AttributeCloudPlatformAzureVM = "azure_vm"
AttributeCloudPlatformAzureContainerInstances = "azure_container_instances"
AttributeCloudPlatformAzureAKS = "azure_aks"
AttributeCloudPlatformAzureFunctions = "azure_functions"
AttributeCloudPlatformAzureAppService = "azure_app_service"
AttributeCloudPlatformGCPComputeEngine = "gcp_compute_engine"
AttributeCloudPlatformGCPCloudRun = "gcp_cloud_run"
AttributeCloudPlatformGCPGKE = "gcp_gke"
AttributeCloudPlatformGCPCloudFunctions = "gcp_cloud_functions"
AttributeCloudPlatformGCPAppEngine = "gcp_app_engine"
)

// GetResourceSemanticConventionAttributeNames a slice with all the Resource Semantic Conventions attribute names.
Expand All @@ -123,8 +123,8 @@ func GetResourceSemanticConventionAttributeNames() []string {
AttributeCloudAccount,
AttributeCloudProvider,
AttributeCloudRegion,
AttributeCloudZone,
AttributeCloudInfrastructureService,
AttributeCloudAvailabilityZone,
AttributeCloudPlatform,
AttributeContainerID,
AttributeContainerImage,
AttributeContainerName,
Expand Down
8 changes: 7 additions & 1 deletion translator/internaldata/oc_to_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

occommon "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
ocresource "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
"go.opencensus.io/resource/resourcekeys"

"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/translator/conventions"
Expand Down Expand Up @@ -122,7 +123,12 @@ func ocNodeResourceToInternal(ocNode *occommon.Node, ocResource *ocresource.Reso
if ocResource != nil {
// Copy resource Labels.
for k, v := range ocResource.Labels {
attrs.InsertString(k, v)
switch k {
case resourcekeys.CloudKeyZone:
attrs.InsertString(conventions.AttributeCloudAvailabilityZone, v)
default:
attrs.InsertString(k, v)
}
}
// Add special fields.
if ocResource.Type != "" {
Expand Down
2 changes: 2 additions & 0 deletions translator/internaldata/resource_to_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func internalResourceToOC(resource pdata.Resource) (*occommon.Node, *ocresource.
val := tracetranslator.AttributeValueToString(v, false)

switch k {
case conventions.AttributeCloudAvailabilityZone:
labels[resourcekeys.CloudKeyZone] = val
case conventions.OCAttributeResourceType:
ocResource.Type = val
case conventions.AttributeServiceName:
Expand Down
44 changes: 22 additions & 22 deletions translator/internaldata/resource_to_oc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func TestResourceToOC(t *testing.T) {
func TestContainerResourceToOC(t *testing.T) {
resource := pdata.NewResource()
resource.Attributes().InitFromMap(map[string]pdata.AttributeValue{
conventions.AttributeK8sCluster: pdata.NewAttributeValueString("cluster1"),
conventions.AttributeK8sPod: pdata.NewAttributeValueString("pod1"),
conventions.AttributeK8sNamespace: pdata.NewAttributeValueString("namespace1"),
conventions.AttributeContainerName: pdata.NewAttributeValueString("container-name1"),
conventions.AttributeCloudAccount: pdata.NewAttributeValueString("proj1"),
conventions.AttributeCloudZone: pdata.NewAttributeValueString("zone1"),
conventions.AttributeK8sCluster: pdata.NewAttributeValueString("cluster1"),
conventions.AttributeK8sPod: pdata.NewAttributeValueString("pod1"),
conventions.AttributeK8sNamespace: pdata.NewAttributeValueString("namespace1"),
conventions.AttributeContainerName: pdata.NewAttributeValueString("container-name1"),
conventions.AttributeCloudAccount: pdata.NewAttributeValueString("proj1"),
conventions.AttributeCloudAvailabilityZone: pdata.NewAttributeValueString("zone1"),
})

want := &ocresource.Resource{
Expand Down Expand Up @@ -163,43 +163,43 @@ func TestInferResourceType(t *testing.T) {
{
name: "container",
labels: map[string]string{
conventions.AttributeK8sCluster: "cluster1",
conventions.AttributeK8sPod: "pod1",
conventions.AttributeK8sNamespace: "namespace1",
conventions.AttributeContainerName: "container-name1",
conventions.AttributeCloudAccount: "proj1",
conventions.AttributeCloudZone: "zone1",
conventions.AttributeK8sCluster: "cluster1",
conventions.AttributeK8sPod: "pod1",
conventions.AttributeK8sNamespace: "namespace1",
conventions.AttributeContainerName: "container-name1",
conventions.AttributeCloudAccount: "proj1",
conventions.AttributeCloudAvailabilityZone: "zone1",
},
wantResourceType: resourcekeys.ContainerType,
wantOk: true,
},
{
name: "pod",
labels: map[string]string{
conventions.AttributeK8sCluster: "cluster1",
conventions.AttributeK8sPod: "pod1",
conventions.AttributeK8sNamespace: "namespace1",
conventions.AttributeCloudZone: "zone1",
conventions.AttributeK8sCluster: "cluster1",
conventions.AttributeK8sPod: "pod1",
conventions.AttributeK8sNamespace: "namespace1",
conventions.AttributeCloudAvailabilityZone: "zone1",
},
wantResourceType: resourcekeys.K8SType,
wantOk: true,
},
{
name: "host",
labels: map[string]string{
conventions.AttributeK8sCluster: "cluster1",
conventions.AttributeCloudZone: "zone1",
conventions.AttributeHostName: "node1",
conventions.AttributeK8sCluster: "cluster1",
conventions.AttributeCloudAvailabilityZone: "zone1",
conventions.AttributeHostName: "node1",
},
wantResourceType: resourcekeys.HostType,
wantOk: true,
},
{
name: "gce",
labels: map[string]string{
conventions.AttributeCloudProvider: "gcp",
conventions.AttributeHostID: "inst1",
conventions.AttributeCloudZone: "zone1",
conventions.AttributeCloudProvider: "gcp",
conventions.AttributeHostID: "inst1",
conventions.AttributeCloudAvailabilityZone: "zone1",
},
wantResourceType: resourcekeys.CloudType,
wantOk: true,
Expand Down