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

Configuring httpSD http client from TAs clienthttp, added changelog a… #34034

Prev Previous commit
Moved tests to relevant file
  • Loading branch information
ItielOlenick committed Jul 11, 2024
commit 05a37a054ecad4e8d7dabef8cacc91aae770d801
54 changes: 0 additions & 54 deletions receiver/prometheusreceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ package prometheusreceiver

import (
"context"
"encoding/base64"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"

gokitlog "github.com/go-kit/log"
commonconfig "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
promConfig "github.com/prometheus/prometheus/config"
promHTTP "github.com/prometheus/prometheus/discovery/http"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver/receivertest"
Expand Down Expand Up @@ -1646,51 +1640,3 @@ scrape_configs:
require.Contains(t, gotUA, set.BuildInfo.Command)
require.Contains(t, gotUA, set.BuildInfo.Version)
}

func TestConfigureSDHTTPClientConfigFromTA(t *testing.T) {
ta := &TargetAllocator{}
ta.TLSSetting = configtls.ClientConfig{
InsecureSkipVerify: true,
ServerName: "test.server",
Config: configtls.Config{
CAFile: "/path/to/ca",
CertFile: "/path/to/cert",
KeyFile: "/path/to/key",
CAPem: configopaque.String(base64.StdEncoding.EncodeToString([]byte("test-ca"))),
CertPem: configopaque.String(base64.StdEncoding.EncodeToString([]byte("test-cert"))),
KeyPem: configopaque.String(base64.StdEncoding.EncodeToString([]byte("test-key"))),
MinVersion: "1.2",
MaxVersion: "1.3",
},
}
ta.ProxyURL = "http:https://proxy.test"

httpSD := &promHTTP.SDConfig{RefreshInterval: model.Duration(30 * time.Second)}

err := configureSDHTTPClientConfigFromTA(httpSD, ta)

assert.NoError(t, err)

assert.Equal(t, false, httpSD.HTTPClientConfig.FollowRedirects)
assert.Equal(t, true, httpSD.HTTPClientConfig.TLSConfig.InsecureSkipVerify)
assert.Equal(t, "test.server", httpSD.HTTPClientConfig.TLSConfig.ServerName)
assert.Equal(t, "/path/to/ca", httpSD.HTTPClientConfig.TLSConfig.CAFile)
assert.Equal(t, "/path/to/cert", httpSD.HTTPClientConfig.TLSConfig.CertFile)
assert.Equal(t, "/path/to/key", httpSD.HTTPClientConfig.TLSConfig.KeyFile)
assert.Equal(t, "test-ca", httpSD.HTTPClientConfig.TLSConfig.CA)
assert.Equal(t, "test-cert", httpSD.HTTPClientConfig.TLSConfig.Cert)
assert.Equal(t, commonconfig.Secret("test-key"), httpSD.HTTPClientConfig.TLSConfig.Key)
assert.Equal(t, commonconfig.TLSVersions["TLS12"], httpSD.HTTPClientConfig.TLSConfig.MinVersion)
assert.Equal(t, commonconfig.TLSVersions["TLS13"], httpSD.HTTPClientConfig.TLSConfig.MaxVersion)

parsedProxyURL, _ := url.Parse("http:https://proxy.test")
assert.Equal(t, commonconfig.URL{URL: parsedProxyURL}, httpSD.HTTPClientConfig.ProxyURL)

// Test case with empty TargetAllocator
emptyTA := &TargetAllocator{}
emptyHTTPSD := &promHTTP.SDConfig{RefreshInterval: model.Duration(30 * time.Second)}

err = configureSDHTTPClientConfigFromTA(emptyHTTPSD, emptyTA)

assert.NoError(t, err)
}