From d97642b9b94a3d2323cf71075b72990aff3465b9 Mon Sep 17 00:00:00 2001 From: Khushi Jain Date: Thu, 9 Oct 2025 19:08:56 +0530 Subject: [PATCH 1/2] Support proxy_url on otel translation logic --- internal/pkg/otel/translate/otelconfig.go | 15 +++++++++++++++ internal/pkg/otel/translate/otelconfig_test.go | 2 ++ .../pkg/otel/translate/output_elasticsearch.go | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/internal/pkg/otel/translate/otelconfig.go b/internal/pkg/otel/translate/otelconfig.go index 4081e373fbc..248d95d25a9 100644 --- a/internal/pkg/otel/translate/otelconfig.go +++ b/internal/pkg/otel/translate/otelconfig.go @@ -551,6 +551,21 @@ func getBeatsAuthExtensionConfig(outputCfg *config.C) (map[string]any, error) { return nil, err } + // proxy_url on newConfig is of type url.URL. Beatsauth extension expects it to be of string type instead + // this logic here converts url.URL to string type similar to what a user would set on filebeat config + if defaultTransportSettings.Proxy.URL != nil { + proxyURL, err := config.NewConfigFrom(map[string]any{ + "proxy_url": defaultTransportSettings.Proxy.URL.String(), + }) + if err != nil { + return nil, fmt.Errorf("error translating proxy_url: %w", err) + } + err = newConfig.Merge(proxyURL) + if err != nil { + return nil, fmt.Errorf("error merging proxy_url: %w", err) + } + } + var newMap map[string]any err = newConfig.Unpack(&newMap) if err != nil { diff --git a/internal/pkg/otel/translate/otelconfig_test.go b/internal/pkg/otel/translate/otelconfig_test.go index 5ad1b411cd0..258ba3eda65 100644 --- a/internal/pkg/otel/translate/otelconfig_test.go +++ b/internal/pkg/otel/translate/otelconfig_test.go @@ -225,6 +225,7 @@ func TestGetOtelConfig(t *testing.T) { "preset": "balanced", "queue.mem.events": 3200, "ssl.enabled": true, + "proxy_url": "https://example.com", } for _, v := range extra { @@ -238,6 +239,7 @@ func TestGetOtelConfig(t *testing.T) { "continue_on_error": true, "idle_connection_timeout": "3s", "proxy_disable": false, + "proxy_url": "https://example.com", "ssl": map[string]interface{}{ "ca_sha256": []interface{}{}, "ca_trusted_fingerprint": "", diff --git a/internal/pkg/otel/translate/output_elasticsearch.go b/internal/pkg/otel/translate/output_elasticsearch.go index f3b6960431d..4b3c1df0020 100644 --- a/internal/pkg/otel/translate/output_elasticsearch.go +++ b/internal/pkg/otel/translate/output_elasticsearch.go @@ -8,6 +8,7 @@ import ( "encoding/base64" "errors" "fmt" + "net/url" "reflect" "strings" "time" @@ -20,6 +21,7 @@ import ( "github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue" "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/logp" + "github.com/elastic/elastic-agent-libs/transport/httpcommon" "github.com/elastic/elastic-agent-libs/transport/tlscommon" ) @@ -256,6 +258,12 @@ func cfgDecodeHookFunc() mapstructure.DecodeHookFunc { return nil, fmt.Errorf("failed parsing TLS verification mode: %w", err) } return verificationMode, nil + case t == reflect.TypeOf(httpcommon.ProxyURI(url.URL{})): + proxyURL := httpcommon.ProxyURI(url.URL{}) + if err := proxyURL.Unpack(data.(string)); err != nil { + return nil, fmt.Errorf("failed parsing proxy_url: %w", err) + } + return proxyURL, nil default: return data, nil } From 696dd54366be2a7bc22a39191f1ec1a5c9d85c9b Mon Sep 17 00:00:00 2001 From: Khushi Jain Date: Fri, 10 Oct 2025 09:05:56 +0530 Subject: [PATCH 2/2] address comments --- internal/pkg/otel/translate/otelconfig.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/internal/pkg/otel/translate/otelconfig.go b/internal/pkg/otel/translate/otelconfig.go index 248d95d25a9..3c67b0fa269 100644 --- a/internal/pkg/otel/translate/otelconfig.go +++ b/internal/pkg/otel/translate/otelconfig.go @@ -554,15 +554,9 @@ func getBeatsAuthExtensionConfig(outputCfg *config.C) (map[string]any, error) { // proxy_url on newConfig is of type url.URL. Beatsauth extension expects it to be of string type instead // this logic here converts url.URL to string type similar to what a user would set on filebeat config if defaultTransportSettings.Proxy.URL != nil { - proxyURL, err := config.NewConfigFrom(map[string]any{ - "proxy_url": defaultTransportSettings.Proxy.URL.String(), - }) + err = newConfig.SetString("proxy_url", -1, defaultTransportSettings.Proxy.URL.String()) if err != nil { - return nil, fmt.Errorf("error translating proxy_url: %w", err) - } - err = newConfig.Merge(proxyURL) - if err != nil { - return nil, fmt.Errorf("error merging proxy_url: %w", err) + return nil, fmt.Errorf("error settingg proxy url:%w ", err) } }