Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-sarama-v1.38.1
Browse files Browse the repository at this point in the history
Signed-off-by: axfor <[email protected]>
  • Loading branch information
axfor committed Mar 22, 2023
2 parents 2703cb9 + 6ab3f01 commit f8863b5
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 87 deletions.
38 changes: 19 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ require (
github.com/gocql/gocql v1.3.1
github.com/gogo/googleapis v1.4.1
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.2
github.com/golang/protobuf v1.5.3
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/go-hclog v1.4.0
github.com/hashicorp/go-plugin v1.4.8
github.com/kr/pretty v0.3.1
github.com/olivere/elastic v6.2.37+incompatible
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.73.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.74.0
github.com/opentracing-contrib/go-grpc v0.0.0-20230205024533-5ced129e5996
github.com/opentracing-contrib/go-stdlib v1.0.0
github.com/opentracing/opentracing-go v1.2.0
Expand All @@ -46,13 +46,13 @@ require (
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/uber/jaeger-lib v2.4.1+incompatible
github.com/xdg-go/scram v1.1.2
go.opentelemetry.io/collector v0.73.0
go.opentelemetry.io/collector/component v0.73.0
go.opentelemetry.io/collector/consumer v0.73.0
go.opentelemetry.io/collector/pdata v1.0.0-rc7
go.opentelemetry.io/collector/receiver v0.73.0
go.opentelemetry.io/collector/receiver/otlpreceiver v0.73.0
go.opentelemetry.io/collector/semconv v0.73.0
go.opentelemetry.io/collector v0.74.0
go.opentelemetry.io/collector/component v0.74.0
go.opentelemetry.io/collector/consumer v0.74.0
go.opentelemetry.io/collector/pdata v1.0.0-rc8
go.opentelemetry.io/collector/receiver v0.74.0
go.opentelemetry.io/collector/receiver/otlpreceiver v0.74.0
go.opentelemetry.io/collector/semconv v0.74.0
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/bridge/opentracing v1.14.0
go.opentelemetry.io/otel/exporters/jaeger v1.14.0
Expand All @@ -63,11 +63,11 @@ require (
go.opentelemetry.io/otel/sdk v1.14.0
go.opentelemetry.io/otel/trace v1.14.0
go.uber.org/atomic v1.10.0
go.uber.org/automaxprocs v1.5.1
go.uber.org/automaxprocs v1.5.2
go.uber.org/zap v1.24.0
golang.org/x/net v0.7.0
golang.org/x/net v0.8.0
golang.org/x/sys v0.6.0
google.golang.org/grpc v1.53.0
google.golang.org/grpc v1.54.0
google.golang.org/protobuf v1.29.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down Expand Up @@ -130,7 +130,7 @@ require (
github.com/mostynb/go-grpc-compression v1.1.17 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.73.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.74.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
Expand All @@ -149,14 +149,14 @@ require (
github.com/xdg-go/stringprep v1.0.4 // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector/confmap v0.73.0 // indirect
go.opentelemetry.io/collector/exporter v0.73.0 // indirect
go.opentelemetry.io/collector/featuregate v0.73.0 // indirect
go.opentelemetry.io/collector/confmap v0.74.0 // indirect
go.opentelemetry.io/collector/exporter v0.74.0 // indirect
go.opentelemetry.io/collector/featuregate v0.74.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.40.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
Expand Down
83 changes: 43 additions & 40 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/prometheus/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ type Configuration struct {
ServerURL string
ConnectTimeout time.Duration
TLS tlscfg.Options
TokenFilePath string
}
37 changes: 25 additions & 12 deletions plugin/metrics/prometheus/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,35 @@ func TestPrometheusFactory(t *testing.T) {

func TestWithDefaultConfiguration(t *testing.T) {
f := NewFactory()
assert.Equal(t, f.options.Primary.ServerURL, "http://localhost:9090")
assert.Equal(t, f.options.Primary.ConnectTimeout, 30*time.Second)
assert.Equal(t, "http://localhost:9090", f.options.Primary.ServerURL)
assert.Equal(t, 30*time.Second, f.options.Primary.ConnectTimeout)
}

func TestWithConfiguration(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
err := command.ParseFlags([]string{
"--prometheus.server-url=http://localhost:1234",
"--prometheus.connect-timeout=5s",
t.Run("With custom configuration and no space in token file path", func(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
err := command.ParseFlags([]string{
"--prometheus.server-url=http://localhost:1234",
"--prometheus.connect-timeout=5s",
"--prometheus.token-file=test/test_file.txt",
})
require.NoError(t, err)
f.InitFromViper(v, zap.NewNop())
assert.Equal(t, "http://localhost:1234", f.options.Primary.ServerURL)
assert.Equal(t, 5*time.Second, f.options.Primary.ConnectTimeout)
assert.Equal(t, "test/test_file.txt", f.options.Primary.TokenFilePath)
})
t.Run("With space in token file path", func(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
err := command.ParseFlags([]string{
"--prometheus.token-file=test/ test file.txt",
})
require.NoError(t, err)
f.InitFromViper(v, zap.NewNop())
assert.Equal(t, "test/ test file.txt", f.options.Primary.TokenFilePath)
})
require.NoError(t, err)

f.InitFromViper(v, zap.NewNop())
assert.Equal(t, f.options.Primary.ServerURL, "http://localhost:1234")
assert.Equal(t, f.options.Primary.ConnectTimeout, 5*time.Second)
}

func TestFailedTLSOptions(t *testing.T) {
Expand Down
21 changes: 20 additions & 1 deletion plugin/metrics/prometheus/metricsstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"net"
"net/http"
"os"
"path/filepath"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -252,7 +254,6 @@ func getHTTPRoundTripper(c *config.Configuration, logger *zap.Logger) (rt http.R
return nil, err
}
}

// KeepAlive and TLSHandshake timeouts are kept to existing Prometheus client's
// DefaultRoundTripper to simplify user configuration and may be made configurable when required.
httpTransport := &http.Transport{
Expand All @@ -264,8 +265,26 @@ func getHTTPRoundTripper(c *config.Configuration, logger *zap.Logger) (rt http.R
TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: ctlsConfig,
}

token := ""
if c.TokenFilePath != "" {
tokenFromFile, err := loadToken(c.TokenFilePath)
if err != nil {
return nil, err
}
token = tokenFromFile
}
return bearertoken.RoundTripper{
Transport: httpTransport,
OverrideFromCtx: true,
StaticToken: token,
}, nil
}

func loadToken(path string) (string, error) {
b, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return "", fmt.Errorf("failed to get token from file: %w", err)
}
return strings.TrimRight(string(b), "\r\n"), nil
}
50 changes: 48 additions & 2 deletions plugin/metrics/prometheus/metricsstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestWarningResponse(t *testing.T) {
assert.NotNil(t, m)
}

func TestGetRoundTripper(t *testing.T) {
func TestGetRoundTripperTLSConfig(t *testing.T) {
for _, tc := range []struct {
name string
tlsEnabled bool
Expand All @@ -325,7 +325,6 @@ func TestGetRoundTripper(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
logger := zap.NewNop()
rt, err := getHTTPRoundTripper(&config.Configuration{
ServerURL: "https://localhost:1234",
ConnectTimeout: 9 * time.Millisecond,
TLS: tlscfg.Options{
Enabled: tc.tlsEnabled,
Expand Down Expand Up @@ -357,6 +356,53 @@ func TestGetRoundTripper(t *testing.T) {
}
}

func TestGetRoundTripperToken(t *testing.T) {
const wantBearer = "token from file"

file, err := os.CreateTemp("", "token_")
require.NoError(t, err)
defer func() { assert.NoError(t, os.Remove(file.Name())) }()

_, err = file.Write([]byte(wantBearer))
require.NoError(t, err)
require.NoError(t, file.Close())

rt, err := getHTTPRoundTripper(&config.Configuration{
ConnectTimeout: time.Second,
TokenFilePath: file.Name(),
}, nil)
require.NoError(t, err)
server := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "Bearer "+wantBearer, r.Header.Get("Authorization"))
},
),
)
defer server.Close()
ctx := context.Background()
req, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
server.URL,
nil,
)
require.NoError(t, err)
resp, err := rt.RoundTrip(req)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestGetRoundTripperTokenError(t *testing.T) {
tokenFilePath := "this file does not exist"

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

func TestInvalidCertFile(t *testing.T) {
logger := zap.NewNop()
reader, err := NewMetricsReader(logger, config.Configuration{
Expand Down
10 changes: 6 additions & 4 deletions plugin/metrics/prometheus/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import (
)

const (
suffixServerURL = ".server-url"
suffixConnectTimeout = ".connect-timeout"

suffixServerURL = ".server-url"
suffixConnectTimeout = ".connect-timeout"
suffixTokenFilePath = ".token-file"
defaultServerURL = "http://localhost:9090"
defaultConnectTimeout = 30 * time.Second
defaultTokenFilePath = ""
)

type namespaceConfig struct {
Expand Down Expand Up @@ -64,7 +65,7 @@ func (opt *Options) AddFlags(flagSet *flag.FlagSet) {
nsConfig := &opt.Primary
flagSet.String(nsConfig.namespace+suffixServerURL, defaultServerURL, "The Prometheus server's URL, must include the protocol scheme e.g. http://localhost:9090")
flagSet.Duration(nsConfig.namespace+suffixConnectTimeout, defaultConnectTimeout, "The period to wait for a connection to Prometheus when executing queries.")

flagSet.String(nsConfig.namespace+suffixTokenFilePath, defaultTokenFilePath, "The path to a file containing the bearer token which will be included when executing queries against the Prometheus API.")
nsConfig.getTLSFlagsConfig().AddFlags(flagSet)
}

Expand All @@ -73,6 +74,7 @@ func (opt *Options) InitFromViper(v *viper.Viper) error {
cfg := &opt.Primary
cfg.ServerURL = stripWhiteSpace(v.GetString(cfg.namespace + suffixServerURL))
cfg.ConnectTimeout = v.GetDuration(cfg.namespace + suffixConnectTimeout)
cfg.TokenFilePath = v.GetString(cfg.namespace + suffixTokenFilePath)
var err error
cfg.TLS, err = cfg.getTLSFlagsConfig().InitFromViper(v)
if err != nil {
Expand Down
28 changes: 19 additions & 9 deletions scripts/rebuild-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ set -euxf -o pipefail

cd jaeger-ui

tag=$(git describe --exact-match --tags)
if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
temp_file=$(mktemp)
trap "rm -f ${temp_file}" EXIT
release_url="https://github.com/jaegertracing/jaeger-ui/releases/download/${tag}/assets.tar.gz"
if curl --silent --fail --location --output "$temp_file" "$release_url"; then
mkdir -p packages/jaeger-ui/build/
tar -zxvf "$temp_file" packages/jaeger-ui/build/
exit 0
LAST_TAG=$(git describe --abbrev=0 --tags 2>/dev/null)
BRANCH_HASH=$(git rev-parse HEAD)
LAST_TAG_HASH=$(git rev-parse $LAST_TAG)

if [[ "$BRANCH_HASH" == "$LAST_TAG_HASH" ]]; then

if [[ "$LAST_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
temp_file=$(mktemp)
trap "rm -f ${temp_file}" EXIT
release_url="https://github.com/jaegertracing/jaeger-ui/releases/download/${LAST_TAG}/assets.tar.gz"
if curl --silent --fail --location --output "$temp_file" "$release_url"; then

mkdir -p packages/jaeger-ui/build/
rm -r -f packages/jaeger-ui/build/
tar -zxvf "$temp_file" packages/jaeger-ui/build/
exit 0

fi
fi

fi

# do a regular full build
Expand Down

0 comments on commit f8863b5

Please sign in to comment.