Skip to content

Commit

Permalink
[exporter/loki] Use NewDefaultClientConfig instead of manually creati…
Browse files Browse the repository at this point in the history
…ng struct

**Description:**
This PR makes usage of `NewDefaultClientConfig` instead of manually creating the confighttp.ClientConfig struct.

**Link to tracking Issue:** open-telemetry#35457
  • Loading branch information
mackjmr committed Oct 1, 2024
1 parent 795694c commit a6e8ec0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 9 additions & 3 deletions exporter/lokiexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package lokiexporter

import (
"fmt"
"net/http"
"path/filepath"
"testing"
"time"
Expand All @@ -24,6 +25,7 @@ import (
)

func TestLoadConfigNewExporter(t *testing.T) {
defaultTransport := http.DefaultTransport.(*http.Transport)
t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand All @@ -49,9 +51,13 @@ func TestLoadConfigNewExporter(t *testing.T) {
},
Insecure: true,
},
ReadBufferSize: 123,
WriteBufferSize: 345,
Timeout: time.Second * 10,
ReadBufferSize: 123,
WriteBufferSize: 345,
Timeout: time.Second * 10,
MaxIdleConns: &defaultTransport.MaxIdleConns,
MaxIdleConnsPerHost: &defaultTransport.MaxIdleConnsPerHost,
MaxConnsPerHost: &defaultTransport.MaxConnsPerHost,
IdleConnTimeout: &defaultTransport.IdleConnTimeout,
},
BackOffConfig: configretry.BackOffConfig{
Enabled: true,
Expand Down
13 changes: 5 additions & 8 deletions exporter/lokiexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand All @@ -29,14 +28,12 @@ func NewFactory() exporter.Factory {
}

func createDefaultConfig() component.Config {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Timeout = 30 * time.Second
// We almost read 0 bytes, so no need to tune ReadBufferSize.
clientConfig.WriteBufferSize = 512 * 1024
return &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: "",
Timeout: 30 * time.Second,
Headers: map[string]configopaque.String{},
// We almost read 0 bytes, so no need to tune ReadBufferSize.
WriteBufferSize: 512 * 1024,
},
ClientConfig: clientConfig,
BackOffConfig: configretry.NewDefaultBackOffConfig(),
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
DefaultLabelsEnabled: map[string]bool{
Expand Down

0 comments on commit a6e8ec0

Please sign in to comment.