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

Add Azure Resource Logs translator #34830

Merged
merged 60 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
134db01
Add attribute_name mappings skeleton
ThatRendle Apr 15, 2024
0478006
Add property name mappings for Azure Front Door resource logs via Eve…
ThatRendle Apr 17, 2024
298619a
Add FrontDoorHealthProbeLog and FrontdoorWebApplicationFirewallLog
ThatRendle Apr 18, 2024
610340b
Add complex conversion handling
ThatRendle Apr 23, 2024
87d1cdd
Incorporate suggestions from lmolkova
ThatRendle Apr 23, 2024
18afa9f
Add empty maps for AppService log types
ThatRendle Apr 23, 2024
cf37abb
Fill out as many name mappings as possible
ThatRendle Apr 24, 2024
f2b6754
Add tests for securityProtocol -> tls.protocol.name and tls.protocol.…
ThatRendle Apr 24, 2024
bc6b28b
Add value normalizing and full test for FrontDoorAccessLog
ThatRendle Apr 25, 2024
be58d53
Add test for AppServiceHTTPLog
ThatRendle Apr 26, 2024
09446db
Add test for AppServicePlatformLog
ThatRendle Apr 26, 2024
b25d353
Tests for CDN Access Log, Front Door WAF Log and FD Health Probe Log
ThatRendle Apr 29, 2024
fc758fc
Finish adding tests
ThatRendle Apr 30, 2024
77b4024
Add chloggen entry
ThatRendle Apr 30, 2024
a02352f
Add feature flag for applying semantic conventions
ThatRendle May 6, 2024
65e762f
Merge branch 'main' into azureeventhub_otelsc
ThatRendle May 6, 2024
623574b
Refactor translator into azure_logs with SemConv, azure without
ThatRendle May 6, 2024
ce3e549
Revert previous change
ThatRendle May 6, 2024
9d1de3f
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
MikeGoldsmith Aug 23, 2024
cb61e39
update to use event-based semconv
MikeGoldsmith Aug 23, 2024
41aa084
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
MikeGoldsmith Aug 28, 2024
d67d2d5
add azure_logs to cmd/otelcontribcol
MikeGoldsmith Aug 28, 2024
05d579f
fix lint errors
MikeGoldsmith Aug 28, 2024
bfcb2c4
rename azure_logs to azurelogs
MikeGoldsmith Aug 28, 2024
177589f
update otelcontribcol
MikeGoldsmith Aug 28, 2024
45760c7
run genotelcontribcol with go 1.22.6
MikeGoldsmith Aug 28, 2024
4cc6ded
Update cmd/oteltestbedcol/go.mod
MikeGoldsmith Aug 28, 2024
545571c
make generate-gh-issue-templates
MikeGoldsmith Aug 28, 2024
e8897a8
Merge branch 'main' into azureeventhub_otelsc
MikeGoldsmith Aug 29, 2024
9bb63cc
Apply suggestions from code review
MikeGoldsmith Aug 30, 2024
c7c7e4d
update codeowners for azurelogs
MikeGoldsmith Aug 30, 2024
f99d3a6
replace normalize map with switch
MikeGoldsmith Aug 30, 2024
849ab82
remove changes to azure events hub receiver
MikeGoldsmith Sep 10, 2024
ba1c4bf
Merge branch 'main' into azureeventhub_otelsc
MikeGoldsmith Sep 10, 2024
fe0792b
go mod tidy
MikeGoldsmith Sep 10, 2024
193a5f5
update a couple more mod file entries
MikeGoldsmith Sep 10, 2024
258fd79
mod tidy again
MikeGoldsmith Sep 10, 2024
326e890
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
MikeGoldsmith Sep 11, 2024
4ab14e3
update collector deps to 0.109.0
MikeGoldsmith Sep 11, 2024
88cf250
add mikegoldsmith to codeowners in metadata.yaml
MikeGoldsmith Sep 11, 2024
5dd53f1
handle properties when not a map
MikeGoldsmith Sep 11, 2024
fb01cfb
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
MikeGoldsmith Sep 11, 2024
2dc71d0
Merge branch 'main' into azureeventhub_otelsc
MikeGoldsmith Sep 11, 2024
4c62cdc
Merge branch 'main' into azureeventhub_otelsc
MikeGoldsmith Sep 11, 2024
4676e1c
Merge branch 'azureeventhub_otelsc' of github.com:MikeGoldsmith/opent…
MikeGoldsmith Sep 16, 2024
1ea3bd4
Apply suggestions from code review
MikeGoldsmith Sep 16, 2024
b9000ac
Merge branch 'main' into azureeventhub_otelsc
MikeGoldsmith Sep 16, 2024
e0e6658
Merge branch 'azureeventhub_otelsc' of github.com:MikeGoldsmith/opent…
MikeGoldsmith Sep 16, 2024
ddb0a11
go mod tidy
MikeGoldsmith Sep 16, 2024
f5b25b5
and again
MikeGoldsmith Sep 16, 2024
4429eea
remove redundant break
MikeGoldsmith Sep 16, 2024
5044864
make genotelcontribcol and genoteltestbedcol
MikeGoldsmith Sep 16, 2024
c5913a6
remove otelcontribcol replace
MikeGoldsmith Sep 16, 2024
d467769
Merge branch 'main' into azureeventhub_otelsc
TylerHelmuth Sep 16, 2024
6fac213
Merge branch 'main' into azureeventhub_otelsc
MikeGoldsmith Sep 17, 2024
f04487a
update toolchain version in otelcontribcol and oteltestsbedcol
MikeGoldsmith Sep 17, 2024
30f60b3
remove azurelogs from otelcontribcol builder config
MikeGoldsmith Sep 17, 2024
e8f92ca
Merge branch 'main' into azureeventhub_otelsc
TylerHelmuth Sep 17, 2024
5a31e3f
Merge branch 'main' into azureeventhub_otelsc
codeboten Sep 18, 2024
cd299b1
tidy
codeboten Sep 18, 2024
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/azureeventhub_otelsc.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: new_component

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Adds a new translater that converts Azure EventHub logs to OpenTelemetry logs used by the Azure Events Hub receiver.

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

# (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 .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pkg/sampling/ @open-teleme
pkg/stanza/ @open-telemetry/collector-contrib-approvers @djaglowski
pkg/stanza/fileconsumer/ @open-telemetry/collector-contrib-approvers @djaglowski
pkg/translator/azure/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers @atoulme @cparkins
pkg/translator/azurelogs/ @open-telemetry/collector-contrib-approvers @atoulme @cparkins @MikeGoldsmith
pkg/translator/jaeger/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers @frzifus
pkg/translator/loki/ @open-telemetry/collector-contrib-approvers @gouthamve @jpkrohling @mar4uk
pkg/translator/opencensus/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ body:
- pkg/stanza
- pkg/stanza/fileconsumer
- pkg/translator/azure
- pkg/translator/azurelogs
- pkg/translator/jaeger
- pkg/translator/loki
- pkg/translator/opencensus
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ body:
- pkg/stanza
- pkg/stanza/fileconsumer
- pkg/translator/azure
- pkg/translator/azurelogs
- pkg/translator/jaeger
- pkg/translator/loki
- pkg/translator/opencensus
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ body:
- pkg/stanza
- pkg/stanza/fileconsumer
- pkg/translator/azure
- pkg/translator/azurelogs
- pkg/translator/jaeger
- pkg/translator/loki
- pkg/translator/opencensus
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ body:
- pkg/stanza
- pkg/stanza/fileconsumer
- pkg/translator/azure
- pkg/translator/azurelogs
- pkg/translator/jaeger
- pkg/translator/loki
- pkg/translator/opencensus
Expand Down
1 change: 1 addition & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ replaces:
- github.com/openshift/api v3.9.0+incompatible => github.com/openshift/api v0.0.0-20180801171038-322a19404e37
- github.com/outcaste-io/ristretto v0.2.0 => github.com/outcaste-io/ristretto v0.2.1
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure => ../../pkg/translator/azure
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs => ../../pkg/translator/azurelogs
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/skywalking => ../../pkg/translator/skywalking
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/collectd => ../../internal/collectd
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding => ../../extension/encoding
Expand Down
3 changes: 3 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/loki v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.109.0 // indirect
Expand Down Expand Up @@ -1320,6 +1321,8 @@ replace github.com/outcaste-io/ristretto v0.2.0 => github.com/outcaste-io/ristre

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

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

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

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/collectd => ../../internal/collectd
Expand Down
1 change: 1 addition & 0 deletions pkg/translator/azurelogs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile.Common
105 changes: 105 additions & 0 deletions pkg/translator/azurelogs/complex_conversions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package azurelogs // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs"

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(_ 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(_ 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(_ 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(_ 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(_ 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 v := value.(type) {
case float32:
return float64(v), true
case float64:
return v, true
case int:
return float64(v), true
case int32:
return float64(v), true
case int64:
return float64(v), true
case string:
f, err := strconv.ParseFloat(v, 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
}
76 changes: 76 additions & 0 deletions pkg/translator/azurelogs/complex_conversions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package azurelogs // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs"

import (
"testing"

"github.com/stretchr/testify/assert"
)

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)
}
44 changes: 44 additions & 0 deletions pkg/translator/azurelogs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs

go 1.22.0

require (
github.com/json-iterator/go v1.1.12
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.99.0
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
github.com/relvacode/iso8601 v1.4.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.109.0
go.opentelemetry.io/collector/pdata v1.15.0
go.opentelemetry.io/collector/semconv v0.109.0
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/gogo/protobuf v1.3.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.109.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.109.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/grpc v1.66.0 // indirect
google.golang.org/protobuf v1.34.2 // 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

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