Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
Signed-off-by: Alok Kumar Singh <[email protected]>
  • Loading branch information
akstron committed Dec 16, 2024
1 parent d4fb513 commit 046b1b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
10 changes: 5 additions & 5 deletions plugin/metricstore/prometheus/metricstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ func (p promClient) URL(ep string, args map[string]string) *url.URL {

query := u.Query()
for k, v := range p.extraParams {
query.Set(k, v)
query.Add(k, v)
}
u.RawQuery = query.Encode()

return u
}

func createPromClient(logger *zap.Logger, cfg config.Configuration) (api.Client, error) {
roundTripper, err := getHTTPRoundTripper(&cfg, logger)
func createPromClient(cfg config.Configuration) (api.Client, error) {
roundTripper, err := getHTTPRoundTripper(&cfg)
if err != nil {
return nil, err
}
Expand All @@ -107,7 +107,7 @@ func createPromClient(logger *zap.Logger, cfg config.Configuration) (api.Client,
func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace.TracerProvider) (*MetricsReader, error) {
const operationLabel = "span_name"

promClient, err := createPromClient(logger, cfg)
promClient, err := createPromClient(cfg)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func logErrorToSpan(span trace.Span, err error) {
span.SetStatus(codes.Error, err.Error())
}

func getHTTPRoundTripper(c *config.Configuration, _ *zap.Logger) (rt http.RoundTripper, err error) {
func getHTTPRoundTripper(c *config.Configuration) (rt http.RoundTripper, err error) {
ctlsConfig, err := c.TLS.LoadTLSConfig(context.Background())
if err != nil {
return nil, err
Expand Down
27 changes: 16 additions & 11 deletions plugin/metricstore/prometheus/metricstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http/httptest"
"net/url"
"os"
"sort"
"strings"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -737,13 +738,12 @@ func TestGetRoundTripperTLSConfig(t *testing.T) {
{"tls disabled", false},
} {
t.Run(tc.name, func(t *testing.T) {
logger := zap.NewNop()
config := &config.Configuration{
ConnectTimeout: 9 * time.Millisecond,
TLS: configtls.ClientConfig{},
TokenOverrideFromContext: true,
}
rt, err := getHTTPRoundTripper(config, logger)
rt, err := getHTTPRoundTripper(config)
require.NoError(t, err)

server := newFakePromServer(t)
Expand Down Expand Up @@ -781,7 +781,7 @@ func TestGetRoundTripperTokenFile(t *testing.T) {
ConnectTimeout: time.Second,
TokenFilePath: file.Name(),
TokenOverrideFromContext: false,
}, nil)
})
require.NoError(t, err)

server := newFakePromServer(t)
Expand Down Expand Up @@ -815,7 +815,7 @@ func TestGetRoundTripperTokenFromContext(t *testing.T) {
ConnectTimeout: time.Second,
TokenFilePath: file.Name(),
TokenOverrideFromContext: true,
}, nil)
})
require.NoError(t, err)

server := newFakePromServer(t)
Expand All @@ -842,7 +842,7 @@ func TestGetRoundTripperTokenError(t *testing.T) {

_, err := getHTTPRoundTripper(&config.Configuration{
TokenFilePath: tokenFilePath,
}, nil)
})
assert.ErrorContains(t, err, "failed to get token from file")
}

Expand All @@ -864,26 +864,31 @@ func TestInvalidCertFile(t *testing.T) {
}

func TestCreatePromClientWithExtraQueryParameters(t *testing.T) {
expParams := map[string]string{
extraParams := map[string]string{
"param1": "value1",
"param2": "value2",
}

logger := zap.NewNop()
cfg := config.Configuration{
ServerURL: "http://localhost:1234",
ExtraQueryParams: expParams,
ServerURL: "http://localhost:1234?param1=value0",
ExtraQueryParams: extraParams,
}

expParams := map[string][]string{
"param1": {"value0", "value1"},
"param2": {"value2"},
}

customClient, err := createPromClient(logger, cfg)
customClient, err := createPromClient(cfg)
require.NoError(t, err)

u := customClient.URL("", nil)

q := u.Query()

for k, v := range expParams {
recV := q.Get(k)
sort.Strings(q[k])
recV := q[k]
require.Equal(t, v, recV)
}
}
Expand Down

0 comments on commit 046b1b1

Please sign in to comment.