1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Support a proxy in splunk log driver

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2018-02-06 12:33:18 -05:00
parent 7d296522f6
commit 3c4537d5b3
2 changed files with 33 additions and 0 deletions

View file

@ -218,6 +218,7 @@ func New(info logger.Info) (logger.Logger, error) {
transport := &http.Transport{ transport := &http.Transport{
TLSClientConfig: tlsConfig, TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
} }
client := &http.Client{ client := &http.Client{
Transport: transport, Transport: transport,

View file

@ -4,12 +4,14 @@ import (
"compress/gzip" "compress/gzip"
"context" "context"
"fmt" "fmt"
"net/http"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"time" "time"
"github.com/docker/docker/daemon/logger" "github.com/docker/docker/daemon/logger"
"github.com/gotestyourself/gotestyourself/env"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -82,6 +84,36 @@ func TestNewMissedToken(t *testing.T) {
} }
} }
func TestNewWithProxy(t *testing.T) {
proxy := "http://proxy.testing:8888"
reset := env.Patch(t, "HTTP_PROXY", proxy)
defer reset()
// must not be localhost
splunkURL := "http://example.com:12345"
logger, err := New(logger.Info{
Config: map[string]string{
splunkURLKey: splunkURL,
splunkTokenKey: "token",
splunkVerifyConnectionKey: "false",
},
ContainerID: "containeriid",
})
require.NoError(t, err)
splunkLogger := logger.(*splunkLoggerInline)
proxyFunc := splunkLogger.transport.Proxy
require.NotNil(t, proxyFunc)
req, err := http.NewRequest("GET", splunkURL, nil)
require.NoError(t, err)
proxyURL, err := proxyFunc(req)
require.NoError(t, err)
require.NotNil(t, proxyURL)
require.Equal(t, proxy, proxyURL.String())
}
// Test default settings // Test default settings
func TestDefault(t *testing.T) { func TestDefault(t *testing.T) {
hec := NewHTTPEventCollectorMock(t) hec := NewHTTPEventCollectorMock(t)