Skip to content

Commit

Permalink
Merge branch 'main' into sort-adjuster
Browse files Browse the repository at this point in the history
  • Loading branch information
mahadzaryab1 authored Dec 20, 2024
2 parents dc4c503 + 5ab3d26 commit 8013ca8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 11 deletions.
22 changes: 22 additions & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,25 @@ We are grateful to our former maintainers for their contributions to the Jaeger
* [@objectiser](https://github.com/objectiser)
* [@tiffon](https://github.com/tiffon)
* [@vprithvi](https://github.com/vprithvi)

### Maintainer Onboarding

Upon approval, the following steps should be taken to onboard the new maintainer:

* **1. Update Project Documentation**
* **`MAINTAINERS.md` File:** Merge the PR to add the new maintainer to the `MAINTAINERS.md` file(s) in the relevant Jaeger repositories.
* **2. Grant Permissions**
* **GitHub:** Add the new maintainer to the `@jaegertracing/jaeger-maintainers` GitHub team. This grants them write access to the Jaeger repositories.
* **CNCF Mailing List:** Add the new maintainer to the `[email protected]` mailing list (and any other relevant Jaeger mailing lists). Contact the existing `cncf-jaeger-maintainers` to find out the precise process for adding to the mailing list, it will likely involve getting in touch with the CNCF.
* **CNCF Maintainer Registry:**
* Create a PR against the `cncf/foundation` repository to add the new maintainer's information to the `project-maintainers.csv` file. The following fields are required:
* Reference the PR in the `cncf-jaeger-maintainers` mailing list.
* **Signing Keys:**
* Jaeger uses a GPG key for encrypted emails sent to the maintainers for security reports along with access to the `maintainers-only` GitHub repository. This key is stored in our 1password repository.
* **1Password:** Connect with an existing maintainer to be added to our jaegertracing 1Password team.
* **3. Announcement**
* Announce the new maintainer to the Jaeger community through the mailing list, blog, or other appropriate channels.

### Maintainer Offboarding

The process for removing a maintainer is similar to adding one. A maintainer can step down voluntarily or be removed by a vote of the other maintainers if they are no longer fulfilling their responsibilities or are violating the project's Code of Conduct. A supermajority vote is needed to remove a maintainer. Their access should be revoked from all relevant tools, and the project documentation updated accordingly.
3 changes: 3 additions & 0 deletions pkg/prometheus/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Configuration struct {
LatencyUnit string `mapstructure:"latency_unit"`
NormalizeCalls bool `mapstructure:"normalize_calls"`
NormalizeDuration bool `mapstructure:"normalize_duration"`
// ExtraQueryParams is used to provide extra parameters to be appended
// to the URL of queries going out to the metrics backend.
ExtraQueryParams map[string]string `mapstructure:"extra_query_parameters"`
}

func (c *Configuration) Validate() error {
Expand Down
44 changes: 38 additions & 6 deletions plugin/metricstore/prometheus/metricstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -60,16 +61,32 @@ type (
metricDesc string
buildPromQuery func(p promQueryParams) string
}

promClient struct {
api.Client
extraParams map[string]string
}
)

// NewMetricsReader returns a new MetricsReader.
func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace.TracerProvider) (*MetricsReader, error) {
logger.Info("Creating metrics reader", zap.Any("configuration", cfg))
// URL decorator enables adding additional query parameters to the request sent to prometheus backend
func (p promClient) URL(ep string, args map[string]string) *url.URL {
u := p.Client.URL(ep, args)

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

return u
}

roundTripper, err := getHTTPRoundTripper(&cfg, logger)
func createPromClient(cfg config.Configuration) (api.Client, error) {
roundTripper, err := getHTTPRoundTripper(&cfg)
if err != nil {
return nil, err
}

client, err := api.NewClient(api.Config{
Address: cfg.ServerURL,
RoundTripper: roundTripper,
Expand All @@ -78,10 +95,25 @@ func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace
return nil, fmt.Errorf("failed to initialize prometheus client: %w", err)
}

customClient := promClient{
Client: client,
extraParams: cfg.ExtraQueryParams,
}

return customClient, nil
}

// NewMetricsReader returns a new MetricsReader.
func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace.TracerProvider) (*MetricsReader, error) {
const operationLabel = "span_name"

promClient, err := createPromClient(cfg)
if err != nil {
return nil, err
}

mr := &MetricsReader{
client: promapi.NewAPI(client),
client: promapi.NewAPI(promClient),
logger: logger,
tracer: tracer.Tracer("prom-metrics-reader"),

Expand Down Expand Up @@ -314,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
39 changes: 34 additions & 5 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 @@ -863,6 +863,35 @@ func TestInvalidCertFile(t *testing.T) {
assert.Nil(t, reader)
}

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

cfg := config.Configuration{
ServerURL: "http://localhost:1234?param1=value0",
ExtraQueryParams: extraParams,
}

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

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

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

q := u.Query()

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

func startMockPrometheusServer(t *testing.T, wantPromQlQuery string, wantWarnings []string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if len(wantWarnings) > 0 {
Expand Down

0 comments on commit 8013ca8

Please sign in to comment.