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

Azure Event Hub receiver Semantic Convention translator #32486

Closed
wants to merge 18 commits into from
Closed
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
27 changes: 27 additions & 0 deletions .chloggen/32486-apply-semantic-conventions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Map Azure Resource Log property names to the Semantic Conventions equivalent"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32764]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: '[user]'
1 change: 1 addition & 0 deletions pkg/translator/azure_logs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile.Common
102 changes: 102 additions & 0 deletions pkg/translator/azure_logs/complex_conversions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package azure_logs

import (
"fmt"
"strconv"
"strings"
)

type ComplexConversion func(string, any, map[string]any) bool
type TypeConversion func(string, any, map[string]any, string) bool

var conversions = map[string]ComplexConversion{
"AzureCdnAccessLog:SecurityProtocol": azureCdnAccessLogSecurityProtocol,
"FrontDoorAccessLog:securityProtocol": azureCdnAccessLogSecurityProtocol,
"AppServiceHTTPLogs:Protocol": appServiceHTTPLogsProtocol,
"AppServiceHTTPLogs:TimeTaken": appServiceHTTPLogTimeTakenMilliseconds,
"FrontDoorHealthProbeLog:DNSLatencyMicroseconds": frontDoorHealthProbeLogDNSLatencyMicroseconds,
"FrontDoorHealthProbeLog:totalLatencyMilliseconds": frontDoorHealthProbeLogTotalLatencyMilliseconds,
}

// Splits the "TLS 1.2" value into "TLS" and "1.2" and sets as "network.protocol.name" and "network.protocol.version"
func azureCdnAccessLogSecurityProtocol(key string, value any, attrs map[string]any) bool {
if str, ok := value.(string); ok {
if parts := strings.SplitN(str, " ", 2); len(parts) == 2 {
attrs["tls.protocol.name"] = strings.ToLower(parts[0])
attrs["tls.protocol.version"] = parts[1]
return true
}
}
return false
}

// Splits the "HTTP/1.1" value into "HTTP" and "1.1" and sets as "network.protocol.name" and "network.protocol.version"
func appServiceHTTPLogsProtocol(key string, value any, attrs map[string]any) bool {
if str, ok := value.(string); ok {
if parts := strings.SplitN(str, "/", 2); len(parts) == 2 {
attrs["network.protocol.name"] = strings.ToLower(parts[0])
attrs["network.protocol.version"] = parts[1]
return true
}
}
return false
}

// Converts Microseconds value to Seconds and sets as "dns.lookup.duration"
func frontDoorHealthProbeLogDNSLatencyMicroseconds(key string, value any, attrs map[string]any) bool {
microseconds, ok := tryParseFloat64(value)
if !ok {
return false
}
seconds := microseconds / 1_000_000
attrs["dns.lookup.duration"] = seconds
return true
}

// Converts Milliseconds value to Seconds and sets as "http.client.request.duration"
func frontDoorHealthProbeLogTotalLatencyMilliseconds(key string, value any, attrs map[string]any) bool {
milliseconds, ok := tryParseFloat64(value)
if !ok {
return false
}
seconds := milliseconds / 1_000
attrs["http.request.duration"] = seconds
return true
}

// Converts Milliseconds value to Seconds and sets as "http.server.request.duration"
func appServiceHTTPLogTimeTakenMilliseconds(key string, value any, attrs map[string]any) bool {
milliseconds, ok := tryParseFloat64(value)
if !ok {
return false
}
seconds := milliseconds / 1_000
attrs["http.server.request.duration"] = seconds
return true
}

func tryParseFloat64(value any) (float64, bool) {
switch value.(type) {
case float32:
return float64(value.(float32)), true
case float64:
return value.(float64), true
case int:
return float64(value.(int)), true
case int32:
return float64(value.(int32)), true
case int64:
return float64(value.(int64)), true
case string:
f, err := strconv.ParseFloat(value.(string), 64)
return f, err == nil
default:
return 0, false
}
}

func tryGetComplexConversion(category string, propertyName string) (ComplexConversion, bool) {
key := fmt.Sprintf("%s:%s", category, propertyName)
conversion, ok := conversions[key]
return conversion, ok
}
72 changes: 72 additions & 0 deletions pkg/translator/azure_logs/complex_conversions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package azure_logs

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestFrontDoorAccessLogSecurityProtocol(t *testing.T) {
f, ok := tryGetComplexConversion("FrontDoorAccessLog", "securityProtocol")
assert.True(t, ok)
attrs := map[string]any{}
ok = f("securityProtocol", "TLS 1.2", attrs)
assert.True(t, ok)
protocolName, ok := attrs["tls.protocol.name"]
assert.True(t, ok)
// Protocol name is normalized to lower case
assert.Equal(t, "tls", protocolName)
protocolVersion, ok := attrs["tls.protocol.version"]
assert.True(t, ok)
assert.Equal(t, "1.2", protocolVersion)
}

func TestAzureCDNAccessLogSecurityProtocol(t *testing.T) {
f, ok := tryGetComplexConversion("AzureCDNAccessLog", "SecurityProtocol")
assert.True(t, ok)
attrs := map[string]any{}
ok = f("SecurityProtocol", "TLS 1.2", attrs)
assert.True(t, ok)
protocolName, ok := attrs["tls.protocol.name"]
assert.True(t, ok)
// Protocol name is normalized to lower case
assert.Equal(t, "tls", protocolName)
protocolVersion, ok := attrs["tls.protocol.version"]
assert.True(t, ok)
assert.Equal(t, "1.2", protocolVersion)
}

func TestAppServiceHTTPLogsProtocol(t *testing.T) {
f, ok := tryGetComplexConversion("AppServiceHTTPLogs", "Protocol")
assert.True(t, ok)
attrs := map[string]any{}
ok = f("Protocol", "HTTP/1.1", attrs)
assert.True(t, ok)
protocolName, ok := attrs["network.protocol.name"]
assert.True(t, ok)
assert.Equal(t, "http", protocolName)
protocolVersion, ok := attrs["network.protocol.version"]
assert.True(t, ok)
assert.Equal(t, "1.1", protocolVersion)
}

func TestFrontDoorHealthProbeLogDNSLatencyMicroseconds(t *testing.T) {
f, ok := tryGetComplexConversion("FrontDoorHealthProbeLog", "DNSLatencyMicroseconds")
assert.True(t, ok)
attrs := map[string]any{}
ok = f("DNSLatencyMicroseconds", 123456, attrs)
assert.True(t, ok)
duration, ok := attrs["dns.lookup.duration"].(float64)
assert.True(t, ok)
assert.Equal(t, 0.123456, duration)
}

func TestFrontDoorHealthProbeLogTotalLatencyMilliseconds(t *testing.T) {
f, ok := tryGetComplexConversion("FrontDoorHealthProbeLog", "totalLatencyMilliseconds")
assert.True(t, ok)
attrs := map[string]any{}
ok = f("totalLatencyMilliseconds", 123, attrs)
assert.True(t, ok)
duration, ok := attrs["http.request.duration"].(float64)
assert.True(t, ok)
assert.Equal(t, 0.123, duration)
}
53 changes: 53 additions & 0 deletions pkg/translator/azure_logs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure_logs

go 1.21.0

require (
github.com/json-iterator/go v1.1.12
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.99.0
github.com/relvacode/iso8601 v1.4.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.99.1-0.20240503221155-67d37183e6ac
go.opentelemetry.io/collector/pdata v1.6.1-0.20240503221155-67d37183e6ac
go.opentelemetry.io/collector/semconv v0.99.1-0.20240503221155-67d37183e6ac
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
)

require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.99.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.99.1-0.20240503221155-67d37183e6ac // indirect
go.opentelemetry.io/collector/confmap v0.99.1-0.20240503221155-67d37183e6ac // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../pdatautil

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pdatatest

module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure_logs

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden => ../../golden
85 changes: 85 additions & 0 deletions pkg/translator/azure_logs/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/translator/azure_logs/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
status:
codeowners:
active: [open-telemetry/collector-approvers, atoulme, cparkins]
Loading
Loading